t=input()
s=list(t)
k=int(input())
if s==[s[0]]*len(s):
  print((len(s)*k)//2)
  exit()
b=[1]
for i in range(1,len(s)):
  if s[i-1]==s[i]:b[-1]+=1
  else:b.append(1)
ans=0
for i in b:ans+=i//2*k
if t[0]==t[-1] and (b[0]+b[-1])%2==0:ans+=k-1
print(ans) t=input() t input() input s=list(t) s list(t) list t k=int(input()) k int(input()) int input() input if s==[s[0]]*len(s):
  print((len(s)*k)//2)
  exit() s==[s[0]]*len(s) s [s[0]]*len(s) [s[0]] s[0] s 0 len(s) len s print((len(s)*k)//2) print (len(s)*k)//2 len(s)*k len(s) len s k 2 exit() exit b=[1] b [1] 1 for i in range(1,len(s)):
  if s[i-1]==s[i]:b[-1]+=1
  else:b.append(1) i range(1,len(s)) range 1 len(s) len s if s[i-1]==s[i]:b[-1]+=1
  else:b.append(1) s[i-1]==s[i] s[i-1] s i-1 i 1 s[i] s i ans=0 ans 0 for i in b:ans+=i//2*k i b if t[0]==t[-1] and (b[0]+b[-1])%2==0:ans+=k-1 t[0]==t[-1] and (b[0]+b[-1])%2==0 t[0]==t[-1] t[0] t 0 t[-1] t -1 (b[0]+b[-1])%2==0 (b[0]+b[-1])%2 b[0]+b[-1] b[0] b 0 b[-1] b -1 2 0 print(ans) print ans s=list(t) list(t) s t=input() input() t k=int(input()) int(input()) k b=[1] [1] b ans=0 0 ans
t=input()
s=list(t)
k=int(input())
if s==[s[0]]*len(s):
  print((len(s)*k)//2)
  exit()
b=[1]
for i in range(1,len(s)):
  if s[i-1]==s[i]:b[-1]+=1
  else:b.append(1)
ans=0
for i in b:ans+=i//2*k
if t[0]==t[-1] and (b[0]+b[-1])%2==0:ans+=k-1
print(ans)
