s = input()
n = int(input())

def f(s):
    prev = ''
    ct = 0
    for i in s:
        if i == prev:
            ct += 1
            prev = ''
        else:
            prev = i
    return ct
        

if len(set(s)) == 1:
    print(len(s) *n//2)
elif s[0]!=s[-1]:
    print(f(s) * n)
else:
    ans = f(s) + (f(s*2) - f(s)) * (n-1)
    print(ans)
    
     s = input() s input() input n = int(input()) n int(input()) int input() input def f(s):
    prev = ''
    ct = 0
    for i in s:
        if i == prev:
            ct += 1
            prev = ''
        else:
            prev = i
    return ct
         f prev = '' prev '' ct = 0 ct 0 for i in s:
        if i == prev:
            ct += 1
            prev = ''
        else:
            prev = i
     i s if i == prev:
            ct += 1
            prev = ''
        else:
            prev = i
     i == prev i prev ct += 1 ct 1 prev = '' prev '' prev = i prev i return ct ct s s if len(set(s)) == 1:
    print(len(s) *n//2)
elif s[0]!=s[-1]:
    print(f(s) * n)
else:
    ans = f(s) + (f(s*2) - f(s)) * (n-1)
    print(ans)
    
     len(set(s)) == 1 len(set(s)) len set(s) set s 1 print(len(s) *n//2) print len(s) *n//2 len(s) *n len(s) len s n 2 elif s[0]!=s[-1]:
    print(f(s) * n) s[0]!=s[-1] s[0] s 0 s[-1] s -1 print(f(s) * n) print f(s) * n f(s) f s n ans = f(s) + (f(s*2) - f(s)) * (n-1) ans f(s) + (f(s*2) - f(s)) * (n-1) f(s) f s (f(s*2) - f(s)) * (n-1) f(s*2) - f(s) f(s*2) f s*2 s 2 f(s) f s n-1 n 1 print(ans) print ans ans = f(s) + (f(s*2) - f(s)) * (n-1) f(s) + (f(s*2) - f(s)) * (n-1) ans def f(s):
    prev = ''
    ct = 0
    for i in s:
        if i == prev:
            ct += 1
            prev = ''
        else:
            prev = i
    return ct
         def f(s):
    prev = ''
    ct = 0
    for i in s:
        if i == prev:
            ct += 1
            prev = ''
        else:
            prev = i
    return ct
         f n = int(input()) int(input()) n s = input() input() s
s = input()
n = int(input())

def f(s):
    prev = ''
    ct = 0
    for i in s:
        if i == prev:
            ct += 1
            prev = ''
        else:
            prev = i
    return ct
        

if len(set(s)) == 1:
    print(len(s) *n//2)
elif s[0]!=s[-1]:
    print(f(s) * n)
else:
    ans = f(s) + (f(s*2) - f(s)) * (n-1)
    print(ans)
    
    
