s=input()
k=int(input())
n=len(s)
ans=0
tmp=0
x=s[0]
ss=[]
for i in range(n):
  if x==s[i]:
    tmp+=1
  else:
    ss.append(tmp)
    tmp=1
    x=s[i]
if tmp>0:
  ss.append(tmp)
if len(ss)==1:
  print(n*k//2)
else:
  if s[0]==s[-1]:
    ans=(-(ss[0]//2)-(ss[-1]//2)+(ss[0]+ss[-1])//2)*(k-1)
  for i in ss:
    ans+=i//2*k
  print(ans) s=input() s input() input k=int(input()) k int(input()) int input() input n=len(s) n len(s) len s ans=0 ans 0 tmp=0 tmp 0 x=s[0] x s[0] s 0 ss=[] ss [] for i in range(n):
  if x==s[i]:
    tmp+=1
  else:
    ss.append(tmp)
    tmp=1
    x=s[i] i range(n) range n if x==s[i]:
    tmp+=1
  else:
    ss.append(tmp)
    tmp=1
    x=s[i] x==s[i] x s[i] s i tmp+=1 tmp 1 ss.append(tmp) ss.append ss append tmp tmp=1 tmp 1 x=s[i] x s[i] s i if tmp>0:
  ss.append(tmp) tmp>0 tmp 0 ss.append(tmp) ss.append ss append tmp if len(ss)==1:
  print(n*k//2)
else:
  if s[0]==s[-1]:
    ans=(-(ss[0]//2)-(ss[-1]//2)+(ss[0]+ss[-1])//2)*(k-1)
  for i in ss:
    ans+=i//2*k
  print(ans) len(ss)==1 len(ss) len ss 1 print(n*k//2) print n*k//2 n*k n k 2 if s[0]==s[-1]:
    ans=(-(ss[0]//2)-(ss[-1]//2)+(ss[0]+ss[-1])//2)*(k-1)
   s[0]==s[-1] s[0] s 0 s[-1] s -1 ans=(-(ss[0]//2)-(ss[-1]//2)+(ss[0]+ss[-1])//2)*(k-1) ans (-(ss[0]//2)-(ss[-1]//2)+(ss[0]+ss[-1])//2)*(k-1) -(ss[0]//2)-(ss[-1]//2)+(ss[0]+ss[-1])//2 -(ss[0]//2)-(ss[-1]//2) -(ss[0]//2) ss[0]//2 ss[0] ss 0 2 ss[-1]//2 ss[-1] ss -1 2 (ss[0]+ss[-1])//2 ss[0]+ss[-1] ss[0] ss 0 ss[-1] ss -1 2 k-1 k 1 for i in ss:
    ans+=i//2*k
   i ss ans+=i//2*k ans i//2*k i//2 i 2 k print(ans) print ans ans+=i//2*k i//2*k ans ss=[] [] ss k=int(input()) int(input()) k x=s[0] s[0] x tmp=1 1 tmp tmp+=1 1 tmp s=input() input() s ans=0 0 ans x=s[i] s[i] x n=len(s) len(s) n tmp=0 0 tmp ans=(-(ss[0]//2)-(ss[-1]//2)+(ss[0]+ss[-1])//2)*(k-1) (-(ss[0]//2)-(ss[-1]//2)+(ss[0]+ss[-1])//2)*(k-1) ans
s=input()
k=int(input())
n=len(s)
ans=0
tmp=0
x=s[0]
ss=[]
for i in range(n):
  if x==s[i]:
    tmp+=1
  else:
    ss.append(tmp)
    tmp=1
    x=s[i]
if tmp>0:
  ss.append(tmp)
if len(ss)==1:
  print(n*k//2)
else:
  if s[0]==s[-1]:
    ans=(-(ss[0]//2)-(ss[-1]//2)+(ss[0]+ss[-1])//2)*(k-1)
  for i in ss:
    ans+=i//2*k
  print(ans)