s=input()
n=len(s)
k=int(input())
if k==1:
  if n==1:
    print(0)
  else:
    i=1
    cnt=0
    while i<n:
      if s[i-1]==s[i]:
        cnt+=1
        i+=1
      i+=1
    print(cnt)
else:
  single=True
  for c in s:
    if c!=s[0]:
      single=False
      break
  if single:
    print(n*k//2)
  elif s[0]!=s[-1]:
    i=1
    cnt=0
    while i<n:
      if s[i-1]==s[i]:
        cnt+=1
        i+=1
      i+=1
    print(cnt*k)
  else:
    i=1
    while s[i]==s[0]:
      i+=1
    kk=i
    j=-1
    while s[j]==s[0]:
      j-=1
    num=i-j-1
    cnt=0
    i+=1
    while i<=n+j:
      if s[i-1]==s[i]:
        cnt+=1
        i+=1
      i+=1
    print(cnt*k+num//2*(k-1)+kk//2+(-j-1)//2) s=input() s input() input n=len(s) n len(s) len s k=int(input()) k int(input()) int input() input if k==1:
  if n==1:
    print(0)
  else:
    i=1
    cnt=0
    while i<n:
      if s[i-1]==s[i]:
        cnt+=1
        i+=1
      i+=1
    print(cnt)
else:
  single=True
  for c in s:
    if c!=s[0]:
      single=False
      break
  if single:
    print(n*k//2)
  elif s[0]!=s[-1]:
    i=1
    cnt=0
    while i<n:
      if s[i-1]==s[i]:
        cnt+=1
        i+=1
      i+=1
    print(cnt*k)
  else:
    i=1
    while s[i]==s[0]:
      i+=1
    kk=i
    j=-1
    while s[j]==s[0]:
      j-=1
    num=i-j-1
    cnt=0
    i+=1
    while i<=n+j:
      if s[i-1]==s[i]:
        cnt+=1
        i+=1
      i+=1
    print(cnt*k+num//2*(k-1)+kk//2+(-j-1)//2) k==1 k 1 if n==1:
    print(0)
  else:
    i=1
    cnt=0
    while i<n:
      if s[i-1]==s[i]:
        cnt+=1
        i+=1
      i+=1
    print(cnt) n==1 n 1 print(0) print 0 i=1 i 1 cnt=0 cnt 0 while i<n:
      if s[i-1]==s[i]:
        cnt+=1
        i+=1
      i+=1
     i<n i n if s[i-1]==s[i]:
        cnt+=1
        i+=1
       s[i-1]==s[i] s[i-1] s i-1 i 1 s[i] s i cnt+=1 cnt 1 i+=1 i 1 i+=1 i 1 print(cnt) print cnt single=True single True for c in s:
    if c!=s[0]:
      single=False
      break
   c s if c!=s[0]:
      single=False
      break
   c!=s[0] c s[0] s 0 single=False single False break if single:
    print(n*k//2)
  elif s[0]!=s[-1]:
    i=1
    cnt=0
    while i<n:
      if s[i-1]==s[i]:
        cnt+=1
        i+=1
      i+=1
    print(cnt*k)
  else:
    i=1
    while s[i]==s[0]:
      i+=1
    kk=i
    j=-1
    while s[j]==s[0]:
      j-=1
    num=i-j-1
    cnt=0
    i+=1
    while i<=n+j:
      if s[i-1]==s[i]:
        cnt+=1
        i+=1
      i+=1
    print(cnt*k+num//2*(k-1)+kk//2+(-j-1)//2) single print(n*k//2) print n*k//2 n*k n k 2 elif s[0]!=s[-1]:
    i=1
    cnt=0
    while i<n:
      if s[i-1]==s[i]:
        cnt+=1
        i+=1
      i+=1
    print(cnt*k)
   s[0]!=s[-1] s[0] s 0 s[-1] s -1 i=1 i 1 cnt=0 cnt 0 while i<n:
      if s[i-1]==s[i]:
        cnt+=1
        i+=1
      i+=1
     i<n i n if s[i-1]==s[i]:
        cnt+=1
        i+=1
       s[i-1]==s[i] s[i-1] s i-1 i 1 s[i] s i cnt+=1 cnt 1 i+=1 i 1 i+=1 i 1 print(cnt*k) print cnt*k cnt k i=1 i 1 while s[i]==s[0]:
      i+=1
     s[i]==s[0] s[i] s i s[0] s 0 i+=1 i 1 kk=i kk i j=-1 j -1 while s[j]==s[0]:
      j-=1
     s[j]==s[0] s[j] s j s[0] s 0 j-=1 j 1 num=i-j-1 num i-j-1 i-j i j 1 cnt=0 cnt 0 i+=1 i 1 while i<=n+j:
      if s[i-1]==s[i]:
        cnt+=1
        i+=1
      i+=1
     i<=n+j i n+j n j if s[i-1]==s[i]:
        cnt+=1
        i+=1
       s[i-1]==s[i] s[i-1] s i-1 i 1 s[i] s i cnt+=1 cnt 1 i+=1 i 1 i+=1 i 1 print(cnt*k+num//2*(k-1)+kk//2+(-j-1)//2) print cnt*k+num//2*(k-1)+kk//2+(-j-1)//2 cnt*k+num//2*(k-1)+kk//2 cnt*k+num//2*(k-1) cnt*k cnt k num//2*(k-1) num//2 num 2 k-1 k 1 kk//2 kk 2 (-j-1)//2 -j-1 -j j 1 2 cnt+=1 1 cnt cnt=0 0 cnt cnt+=1 1 cnt n=len(s) len(s) n kk=i i kk i=1 1 i i+=1 1 i i+=1 1 i single=True True single i=1 1 i i+=1 1 i i=1 1 i i+=1 1 i j=-1 -1 j i+=1 1 i i+=1 1 i s=input() input() s i+=1 1 i cnt=0 0 cnt cnt=0 0 cnt k=int(input()) int(input()) k single=False False single i+=1 1 i cnt+=1 1 cnt num=i-j-1 i-j-1 num j-=1 1 j
s=input()
n=len(s)
k=int(input())
if k==1:
  if n==1:
    print(0)
  else:
    i=1
    cnt=0
    while i<n:
      if s[i-1]==s[i]:
        cnt+=1
        i+=1
      i+=1
    print(cnt)
else:
  single=True
  for c in s:
    if c!=s[0]:
      single=False
      break
  if single:
    print(n*k//2)
  elif s[0]!=s[-1]:
    i=1
    cnt=0
    while i<n:
      if s[i-1]==s[i]:
        cnt+=1
        i+=1
      i+=1
    print(cnt*k)
  else:
    i=1
    while s[i]==s[0]:
      i+=1
    kk=i
    j=-1
    while s[j]==s[0]:
      j-=1
    num=i-j-1
    cnt=0
    i+=1
    while i<=n+j:
      if s[i-1]==s[i]:
        cnt+=1
        i+=1
      i+=1
    print(cnt*k+num//2*(k-1)+kk//2+(-j-1)//2)
