s=input()
n=int(input())
if len(s)==1:print(n//2);exit()
if len(set(s))==1:print(len(s)*n//2);exit()
c=1
l=[]
for x in range(1,len(s)):
    if s[x-1]==s[x]:
        c+=1
        if x==len(s)-1:l.append(c)
    else:l.append(c);c=1

t=0
if s[0]==s[-1] and l[0]%2==1 and l[-1]%2==1:t=n-1
print(sum([i//2 for i in l])*n+t) s=input() s input() input n=int(input()) n int(input()) int input() input if len(s)==1:print(n//2);exit() len(s)==1 len(s) len s 1 if len(set(s))==1:print(len(s)*n//2);exit() len(set(s))==1 len(set(s)) len set(s) set s 1 c=1 c 1 l=[] l [] for x in range(1,len(s)):
    if s[x-1]==s[x]:
        c+=1
        if x==len(s)-1:l.append(c)
    else:l.append(c);c=1 x range(1,len(s)) range 1 len(s) len s if s[x-1]==s[x]:
        c+=1
        if x==len(s)-1:l.append(c)
    else:l.append(c);c=1 s[x-1]==s[x] s[x-1] s x-1 x 1 s[x] s x c+=1 c 1 if x==len(s)-1:l.append(c)
     x==len(s)-1 x len(s)-1 len(s) len s 1 t=0 t 0 if s[0]==s[-1] and l[0]%2==1 and l[-1]%2==1:t=n-1 s[0]==s[-1] and l[0]%2==1 and l[-1]%2==1 s[0]==s[-1] and l[0]%2==1 s[0]==s[-1] s[0] s 0 s[-1] s -1 l[0]%2==1 l[0]%2 l[0] l 0 2 1 l[-1]%2==1 l[-1]%2 l[-1] l -1 2 1 i//2 for i in l for i in l i l for i in l i//2 i 2 print(sum([i//2 for i in l])*n+t) print sum([i//2 for i in l])*n+t sum([i//2 for i in l])*n sum([i//2 for i in l]) sum [i//2 for i in l] n t s=input() input() s c=1 1 c c+=1 1 c n=int(input()) int(input()) n l=[] [] l t=0 0 t
s=input()
n=int(input())
if len(s)==1:print(n//2);exit()
if len(set(s))==1:print(len(s)*n//2);exit()
c=1
l=[]
for x in range(1,len(s)):
    if s[x-1]==s[x]:
        c+=1
        if x==len(s)-1:l.append(c)
    else:l.append(c);c=1

t=0
if s[0]==s[-1] and l[0]%2==1 and l[-1]%2==1:t=n-1
print(sum([i//2 for i in l])*n+t)