s=input()
n=int(input())
ans=0
tmp=1
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    tmp+=1
  else:
    ans+=tmp//2
    tmp=1
if tmp!=0:
  ans+=tmp//2
ans*=n
if len(s)!=1 and s[0]==s[-1]:
  top=0
  bottom=0
  for i in range(len(s)):
    if s[:i].count(s[0])==i:
      top=i
    if s[-i:].count(s[-1])==i:
      bottom=i
  if top!=len(s)-1:
    ans-=(top//2+bottom//2-(top+bottom)//2)*(n-1)
  elif len(s)%2==1:
    ans+=n//2
if len(s)==1:
  print(n//2)
else:
  print(ans) s=input() s input() input n=int(input()) n int(input()) int input() input ans=0 ans 0 tmp=1 tmp 1 for i in range(len(s)-1):
  if s[i]==s[i+1]:
    tmp+=1
  else:
    ans+=tmp//2
    tmp=1 i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i]==s[i+1]:
    tmp+=1
  else:
    ans+=tmp//2
    tmp=1 s[i]==s[i+1] s[i] s i s[i+1] s i+1 i 1 tmp+=1 tmp 1 ans+=tmp//2 ans tmp//2 tmp 2 tmp=1 tmp 1 if tmp!=0:
  ans+=tmp//2 tmp!=0 tmp 0 ans+=tmp//2 ans tmp//2 tmp 2 ans*=n ans n if len(s)!=1 and s[0]==s[-1]:
  top=0
  bottom=0
  for i in range(len(s)):
    if s[:i].count(s[0])==i:
      top=i
    if s[-i:].count(s[-1])==i:
      bottom=i
  if top!=len(s)-1:
    ans-=(top//2+bottom//2-(top+bottom)//2)*(n-1)
  elif len(s)%2==1:
    ans+=n//2 len(s)!=1 and s[0]==s[-1] len(s)!=1 len(s) len s 1 s[0]==s[-1] s[0] s 0 s[-1] s -1 top=0 top 0 bottom=0 bottom 0 for i in range(len(s)):
    if s[:i].count(s[0])==i:
      top=i
    if s[-i:].count(s[-1])==i:
      bottom=i
   i range(len(s)) range len(s) len s if s[:i].count(s[0])==i:
      top=i
     s[:i].count(s[0])==i s[:i].count(s[0]) [:i].count [:i] s :i i count s[0] s 0 i top=i top i if s[-i:].count(s[-1])==i:
      bottom=i
   s[-i:].count(s[-1])==i s[-i:].count(s[-1]) [-i:].count [-i:] s -i: -i i count s[-1] s -1 i bottom=i bottom i if top!=len(s)-1:
    ans-=(top//2+bottom//2-(top+bottom)//2)*(n-1)
  elif len(s)%2==1:
    ans+=n//2 top!=len(s)-1 top len(s)-1 len(s) len s 1 ans-=(top//2+bottom//2-(top+bottom)//2)*(n-1) ans (top//2+bottom//2-(top+bottom)//2)*(n-1) top//2+bottom//2-(top+bottom)//2 top//2+bottom//2 top//2 top 2 bottom//2 bottom 2 (top+bottom)//2 top+bottom top bottom 2 n-1 n 1 elif len(s)%2==1:
    ans+=n//2 len(s)%2==1 len(s)%2 len(s) len s 2 1 ans+=n//2 ans n//2 n 2 if len(s)==1:
  print(n//2)
else:
  print(ans) len(s)==1 len(s) len s 1 print(n//2) print n//2 n 2 print(ans) print ans tmp=1 1 tmp ans-=(top//2+bottom//2-(top+bottom)//2)*(n-1) (top//2+bottom//2-(top+bottom)//2)*(n-1) ans s=input() input() s tmp+=1 1 tmp n=int(input()) int(input()) n bottom=i i bottom ans+=n//2 n//2 ans ans=0 0 ans ans*=n n ans ans+=tmp//2 tmp//2 ans tmp=1 1 tmp top=0 0 top top=i i top bottom=0 0 bottom ans+=tmp//2 tmp//2 ans
s=input()
n=int(input())
ans=0
tmp=1
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    tmp+=1
  else:
    ans+=tmp//2
    tmp=1
if tmp!=0:
  ans+=tmp//2
ans*=n
if len(s)!=1 and s[0]==s[-1]:
  top=0
  bottom=0
  for i in range(len(s)):
    if s[:i].count(s[0])==i:
      top=i
    if s[-i:].count(s[-1])==i:
      bottom=i
  if top!=len(s)-1:
    ans-=(top//2+bottom//2-(top+bottom)//2)*(n-1)
  elif len(s)%2==1:
    ans+=n//2
if len(s)==1:
  print(n//2)
else:
  print(ans)