s=str(input())
k=int(input())
s=list(s)
s2=s+s
cnt=0
temp1=0
temp2=0
l=0
for i in range(1,len(s)):
  if s[i]==s[i-1]:
    cnt=cnt+1
    l=l+1
  if s[i]!=s[i-1]:
    temp1=temp1+(cnt+1)//2
    cnt=0
temp1=temp1+(cnt+1)//2
cnt=0
for i in range(1,len(s2)):
  if s2[i]==s2[i-1]:
    cnt=cnt+1
  if s2[i]!=s2[i-1]:
    temp2=temp2+(cnt+1)//2
    cnt=0
temp2=temp2+(cnt+1)//2
cnt=0
if l==len(s)-1:
  print(k*len(s)//2)
elif k==1:
  print(temp1)
else:
  print(temp1+(temp2-temp1)*(k-1)) s=str(input()) s str(input()) str input() input k=int(input()) k int(input()) int input() input s=list(s) s list(s) list s s2=s+s s2 s+s s s cnt=0 cnt 0 temp1=0 temp1 0 temp2=0 temp2 0 l=0 l 0 for i in range(1,len(s)):
  if s[i]==s[i-1]:
    cnt=cnt+1
    l=l+1
  if s[i]!=s[i-1]:
    temp1=temp1+(cnt+1)//2
    cnt=0 i range(1,len(s)) range 1 len(s) len s if s[i]==s[i-1]:
    cnt=cnt+1
    l=l+1
   s[i]==s[i-1] s[i] s i s[i-1] s i-1 i 1 cnt=cnt+1 cnt cnt+1 cnt 1 l=l+1 l l+1 l 1 if s[i]!=s[i-1]:
    temp1=temp1+(cnt+1)//2
    cnt=0 s[i]!=s[i-1] s[i] s i s[i-1] s i-1 i 1 temp1=temp1+(cnt+1)//2 temp1 temp1+(cnt+1)//2 temp1 (cnt+1)//2 cnt+1 cnt 1 2 cnt=0 cnt 0 temp1=temp1+(cnt+1)//2 temp1 temp1+(cnt+1)//2 temp1 (cnt+1)//2 cnt+1 cnt 1 2 cnt=0 cnt 0 for i in range(1,len(s2)):
  if s2[i]==s2[i-1]:
    cnt=cnt+1
  if s2[i]!=s2[i-1]:
    temp2=temp2+(cnt+1)//2
    cnt=0 i range(1,len(s2)) range 1 len(s2) len s2 if s2[i]==s2[i-1]:
    cnt=cnt+1
   s2[i]==s2[i-1] s2[i] s2 i s2[i-1] s2 i-1 i 1 cnt=cnt+1 cnt cnt+1 cnt 1 if s2[i]!=s2[i-1]:
    temp2=temp2+(cnt+1)//2
    cnt=0 s2[i]!=s2[i-1] s2[i] s2 i s2[i-1] s2 i-1 i 1 temp2=temp2+(cnt+1)//2 temp2 temp2+(cnt+1)//2 temp2 (cnt+1)//2 cnt+1 cnt 1 2 cnt=0 cnt 0 temp2=temp2+(cnt+1)//2 temp2 temp2+(cnt+1)//2 temp2 (cnt+1)//2 cnt+1 cnt 1 2 cnt=0 cnt 0 if l==len(s)-1:
  print(k*len(s)//2)
elif k==1:
  print(temp1)
else:
  print(temp1+(temp2-temp1)*(k-1)) l==len(s)-1 l len(s)-1 len(s) len s 1 print(k*len(s)//2) print k*len(s)//2 k*len(s) k len(s) len s 2 elif k==1:
  print(temp1) k==1 k 1 print(temp1) print temp1 print(temp1+(temp2-temp1)*(k-1)) print temp1+(temp2-temp1)*(k-1) temp1 (temp2-temp1)*(k-1) temp2-temp1 temp2 temp1 k-1 k 1 k=int(input()) int(input()) k temp2=temp2+(cnt+1)//2 temp2+(cnt+1)//2 temp2 temp2=0 0 temp2 l=0 0 l temp2=temp2+(cnt+1)//2 temp2+(cnt+1)//2 temp2 cnt=0 0 cnt cnt=0 0 cnt s2=s+s s+s s2 cnt=0 0 cnt cnt=0 0 cnt temp1=temp1+(cnt+1)//2 temp1+(cnt+1)//2 temp1 cnt=0 0 cnt l=l+1 l+1 l s=list(s) list(s) s cnt=cnt+1 cnt+1 cnt s=str(input()) str(input()) s temp1=temp1+(cnt+1)//2 temp1+(cnt+1)//2 temp1 temp1=0 0 temp1 cnt=cnt+1 cnt+1 cnt
s=str(input())
k=int(input())
s=list(s)
s2=s+s
cnt=0
temp1=0
temp2=0
l=0
for i in range(1,len(s)):
  if s[i]==s[i-1]:
    cnt=cnt+1
    l=l+1
  if s[i]!=s[i-1]:
    temp1=temp1+(cnt+1)//2
    cnt=0
temp1=temp1+(cnt+1)//2
cnt=0
for i in range(1,len(s2)):
  if s2[i]==s2[i-1]:
    cnt=cnt+1
  if s2[i]!=s2[i-1]:
    temp2=temp2+(cnt+1)//2
    cnt=0
temp2=temp2+(cnt+1)//2
cnt=0
if l==len(s)-1:
  print(k*len(s)//2)
elif k==1:
  print(temp1)
else:
  print(temp1+(temp2-temp1)*(k-1))