s = input()
k = int(input())
s = s + '0'

e = 1
l = []
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        e+=1
    else:
        l.append(e)
        e=1

s = s[:-1]

if len(s)==1:
    print(k//2)    
else:
    if s[0]!=s[-1]:
        print(k*sum([i//2 for i in l]))
    else:
        if k==1:
            print(k*sum([i//2 for i in l]))
        else:
            if len(l)==1:
                print((k*l[0])//2)
            else:
                a = l.pop(0)
                b = l.pop(-1)
                l.append(a+b)
                print(k*sum([i//2 for i in l])-(a+b)//2+a//2+b//2) s = input() s input() input k = int(input()) k int(input()) int input() input s = s + '0' s s + '0' s '0' e = 1 e 1 l = [] l [] for i in range(len(s)-1):
    if s[i]==s[i+1]:
        e+=1
    else:
        l.append(e)
        e=1 i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i]==s[i+1]:
        e+=1
    else:
        l.append(e)
        e=1 s[i]==s[i+1] s[i] s i s[i+1] s i+1 i 1 e+=1 e 1 l.append(e) l.append l append e e=1 e 1 s = s[:-1] s s[:-1] s :-1 -1 if len(s)==1:
    print(k//2)    
else:
    if s[0]!=s[-1]:
        print(k*sum([i//2 for i in l]))
    else:
        if k==1:
            print(k*sum([i//2 for i in l]))
        else:
            if len(l)==1:
                print((k*l[0])//2)
            else:
                a = l.pop(0)
                b = l.pop(-1)
                l.append(a+b)
                print(k*sum([i//2 for i in l])-(a+b)//2+a//2+b//2) len(s)==1 len(s) len s 1 print(k//2) print k//2 k 2 if s[0]!=s[-1]:
        print(k*sum([i//2 for i in l]))
    else:
        if k==1:
            print(k*sum([i//2 for i in l]))
        else:
            if len(l)==1:
                print((k*l[0])//2)
            else:
                a = l.pop(0)
                b = l.pop(-1)
                l.append(a+b)
                print(k*sum([i//2 for i in l])-(a+b)//2+a//2+b//2) s[0]!=s[-1] s[0] s 0 s[-1] s -1 i//2 for i in l for i in l i l for i in l i//2 i 2 print(k*sum([i//2 for i in l])) print k*sum([i//2 for i in l]) k sum([i//2 for i in l]) sum [i//2 for i in l] if k==1:
            print(k*sum([i//2 for i in l]))
        else:
            if len(l)==1:
                print((k*l[0])//2)
            else:
                a = l.pop(0)
                b = l.pop(-1)
                l.append(a+b)
                print(k*sum([i//2 for i in l])-(a+b)//2+a//2+b//2) k==1 k 1 i//2 for i in l for i in l i l for i in l i//2 i 2 print(k*sum([i//2 for i in l])) print k*sum([i//2 for i in l]) k sum([i//2 for i in l]) sum [i//2 for i in l] if len(l)==1:
                print((k*l[0])//2)
            else:
                a = l.pop(0)
                b = l.pop(-1)
                l.append(a+b)
                print(k*sum([i//2 for i in l])-(a+b)//2+a//2+b//2) len(l)==1 len(l) len l 1 print((k*l[0])//2) print (k*l[0])//2 k*l[0] k l[0] l 0 2 a = l.pop(0) a l.pop(0) l.pop l pop 0 b = l.pop(-1) b l.pop(-1) l.pop l pop -1 l.append(a+b) l.append l append a+b a b i//2 for i in l for i in l i l for i in l i//2 i 2 print(k*sum([i//2 for i in l])-(a+b)//2+a//2+b//2) print k*sum([i//2 for i in l])-(a+b)//2+a//2+b//2 k*sum([i//2 for i in l])-(a+b)//2+a//2 k*sum([i//2 for i in l])-(a+b)//2 k*sum([i//2 for i in l]) k sum([i//2 for i in l]) sum [i//2 for i in l] (a+b)//2 a+b a b 2 a//2 a 2 b//2 b 2 e=1 1 e e+=1 1 e b = l.pop(-1) l.pop(-1) b e = 1 1 e k = int(input()) int(input()) k s = s + '0' s + '0' s s = s[:-1] s[:-1] s a = l.pop(0) l.pop(0) a l = [] [] l s = input() input() s
s = input()
k = int(input())
s = s + '0'

e = 1
l = []
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        e+=1
    else:
        l.append(e)
        e=1

s = s[:-1]

if len(s)==1:
    print(k//2)    
else:
    if s[0]!=s[-1]:
        print(k*sum([i//2 for i in l]))
    else:
        if k==1:
            print(k*sum([i//2 for i in l]))
        else:
            if len(l)==1:
                print((k*l[0])//2)
            else:
                a = l.pop(0)
                b = l.pop(-1)
                l.append(a+b)
                print(k*sum([i//2 for i in l])-(a+b)//2+a//2+b//2)