s=input()
k=int(input())
if len(s)==1:
  print(k//2)
  exit()
c=1
ans=0
for i in range(1,len(s)):
  if s[i-1]==s[i]:
    c+=1
  else:
    ans+=c//2
    c=1
ans+=c//2
ans*=k
cl=0
i=0
while  i<len(s) and s[-1]==s[i]:
  cl+=1
  i+=1
if i<len(s) and cl%2==1 and c%2==1:
  ans+=k-1
elif cl%2==1 and c%2==1:
  ans+=k//2
print(ans) s=input() s input() input k=int(input()) k int(input()) int input() input if len(s)==1:
  print(k//2)
  exit() len(s)==1 len(s) len s 1 print(k//2) print k//2 k 2 exit() exit c=1 c 1 ans=0 ans 0 for i in range(1,len(s)):
  if s[i-1]==s[i]:
    c+=1
  else:
    ans+=c//2
    c=1 i range(1,len(s)) range 1 len(s) len s if s[i-1]==s[i]:
    c+=1
  else:
    ans+=c//2
    c=1 s[i-1]==s[i] s[i-1] s i-1 i 1 s[i] s i c+=1 c 1 ans+=c//2 ans c//2 c 2 c=1 c 1 ans+=c//2 ans c//2 c 2 ans*=k ans k cl=0 cl 0 i=0 i 0 while  i<len(s) and s[-1]==s[i]:
  cl+=1
  i+=1 i<len(s) and s[-1]==s[i] i<len(s) i len(s) len s s[-1]==s[i] s[-1] s -1 s[i] s i cl+=1 cl 1 i+=1 i 1 if i<len(s) and cl%2==1 and c%2==1:
  ans+=k-1
elif cl%2==1 and c%2==1:
  ans+=k//2 i<len(s) and cl%2==1 and c%2==1 i<len(s) and cl%2==1 i<len(s) i len(s) len s cl%2==1 cl%2 cl 2 1 c%2==1 c%2 c 2 1 ans+=k-1 ans k-1 k 1 elif cl%2==1 and c%2==1:
  ans+=k//2 cl%2==1 and c%2==1 cl%2==1 cl%2 cl 2 1 c%2==1 c%2 c 2 1 ans+=k//2 ans k//2 k 2 print(ans) print ans c+=1 1 c c=1 1 c cl=0 0 cl cl+=1 1 cl k=int(input()) int(input()) k ans*=k k ans ans+=k-1 k-1 ans ans=0 0 ans ans+=c//2 c//2 ans i=0 0 i s=input() input() s i+=1 1 i ans+=c//2 c//2 ans ans+=k//2 k//2 ans c=1 1 c
s=input()
k=int(input())
if len(s)==1:
  print(k//2)
  exit()
c=1
ans=0
for i in range(1,len(s)):
  if s[i-1]==s[i]:
    c+=1
  else:
    ans+=c//2
    c=1
ans+=c//2
ans*=k
cl=0
i=0
while  i<len(s) and s[-1]==s[i]:
  cl+=1
  i+=1
if i<len(s) and cl%2==1 and c%2==1:
  ans+=k-1
elif cl%2==1 and c%2==1:
  ans+=k//2
print(ans)