s=input()
k=int(input())
if len(s)==1:
  print(k//2)
  exit()
c=[]
c_=1
for i in range(1,len(s)):
  if s[i-1]==s[i]:
    c_+=1
  else:
    c.append(c_)
    c_=1
c.append(c_)
if len(c)==1:
  print((c[0]*k)//2)
elif s[0]==s[-1]:
  ans=sum([c_//2 for c_ in c[1:-1]])*k
  ans+=c[0]//2
  ans+=c[-1]//2
  ans+=((c[0]+c[-1])//2)*(k-1)
  print(ans)
else:
  print(sum([c_//2 for c_ in c])*k)
#print(c) 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=[] c [] c_=1 c_ 1 for i in range(1,len(s)):
  if s[i-1]==s[i]:
    c_+=1
  else:
    c.append(c_)
    c_=1 i range(1,len(s)) range 1 len(s) len s if s[i-1]==s[i]:
    c_+=1
  else:
    c.append(c_)
    c_=1 s[i-1]==s[i] s[i-1] s i-1 i 1 s[i] s i c_+=1 c_ 1 c.append(c_) c.append c append c_ c_=1 c_ 1 c.append(c_) c.append c append c_ if len(c)==1:
  print((c[0]*k)//2)
elif s[0]==s[-1]:
  ans=sum([c_//2 for c_ in c[1:-1]])*k
  ans+=c[0]//2
  ans+=c[-1]//2
  ans+=((c[0]+c[-1])//2)*(k-1)
  print(ans)
else:
  print(sum([c_//2 for c_ in c])*k)
#print(c) len(c)==1 len(c) len c 1 print((c[0]*k)//2) print (c[0]*k)//2 c[0]*k c[0] c 0 k 2 elif s[0]==s[-1]:
  ans=sum([c_//2 for c_ in c[1:-1]])*k
  ans+=c[0]//2
  ans+=c[-1]//2
  ans+=((c[0]+c[-1])//2)*(k-1)
  print(ans) s[0]==s[-1] s[0] s 0 s[-1] s -1 c_//2 for c_ in c[1:-1] for c_ in c[1:-1] c_ c[1:-1] c 1:-1 1 -1 for c_ in c[1:-1] c_//2 c_ 2 ans=sum([c_//2 for c_ in c[1:-1]])*k ans sum([c_//2 for c_ in c[1:-1]])*k sum([c_//2 for c_ in c[1:-1]]) sum [c_//2 for c_ in c[1:-1]] k ans+=c[0]//2 ans c[0]//2 c[0] c 0 2 ans+=c[-1]//2 ans c[-1]//2 c[-1] c -1 2 ans+=((c[0]+c[-1])//2)*(k-1) ans ((c[0]+c[-1])//2)*(k-1) (c[0]+c[-1])//2 c[0]+c[-1] c[0] c 0 c[-1] c -1 2 k-1 k 1 print(ans) print ans c_//2 for c_ in c for c_ in c c_ c for c_ in c c_//2 c_ 2 print(sum([c_//2 for c_ in c])*k) print sum([c_//2 for c_ in c])*k sum([c_//2 for c_ in c]) sum [c_//2 for c_ in c] k c_=1 1 c_ c_+=1 1 c_ ans+=c[0]//2 c[0]//2 ans ans+=c[-1]//2 c[-1]//2 ans k=int(input()) int(input()) k c_=1 1 c_ s=input() input() s c=[] [] c ans+=((c[0]+c[-1])//2)*(k-1) ((c[0]+c[-1])//2)*(k-1) ans ans=sum([c_//2 for c_ in c[1:-1]])*k sum([c_//2 for c_ in c[1:-1]])*k ans
s=input()
k=int(input())
if len(s)==1:
  print(k//2)
  exit()
c=[]
c_=1
for i in range(1,len(s)):
  if s[i-1]==s[i]:
    c_+=1
  else:
    c.append(c_)
    c_=1
c.append(c_)
if len(c)==1:
  print((c[0]*k)//2)
elif s[0]==s[-1]:
  ans=sum([c_//2 for c_ in c[1:-1]])*k
  ans+=c[0]//2
  ans+=c[-1]//2
  ans+=((c[0]+c[-1])//2)*(k-1)
  print(ans)
else:
  print(sum([c_//2 for c_ in c])*k)
#print(c)
