S = input()
k = int(input())
from itertools import groupby
x = y = 0
g = [len(list(v)) for k,v in groupby(S)]
for c in g:
    x += c//2
#print(len(S),g[0])
if S[-1] == S[0]:
    if g[-1]%2 == 0 or g[0]%2 == 0:
        pass
    elif len(S) == 1:
        y = k//2
    elif len(S) == g[0]:
        y = k//2
        #print('?',y)
    else:
        y = k-1
print(x*k + y) S = input() S input() input k = int(input()) k int(input()) int input() input from itertools import groupby x = y = 0 x 0 = y = 0 y 0 len(list(v)) for k,v in groupby(S) for k,v in groupby(S) k v groupby(S) groupby S for k,v in groupby(S) len(list(v)) len list(v) list v g = [len(list(v)) for k,v in groupby(S)] g [len(list(v)) for k,v in groupby(S)] for c in g:
    x += c//2
#print(len(S),g[0]) c g x += c//2 x c//2 c 2 if S[-1] == S[0]:
    if g[-1]%2 == 0 or g[0]%2 == 0:
        pass
    elif len(S) == 1:
        y = k//2
    elif len(S) == g[0]:
        y = k//2
        #print('?',y)
    else:
        y = k-1 S[-1] == S[0] S[-1] S -1 S[0] S 0 if g[-1]%2 == 0 or g[0]%2 == 0:
        pass
    elif len(S) == 1:
        y = k//2
    elif len(S) == g[0]:
        y = k//2
        #print('?',y)
    else:
        y = k-1 g[-1]%2 == 0 or g[0]%2 == 0 g[-1]%2 == 0 g[-1]%2 g[-1] g -1 2 0 g[0]%2 == 0 g[0]%2 g[0] g 0 2 0 elif len(S) == 1:
        y = k//2
     len(S) == 1 len(S) len S 1 y = k//2 y k//2 k 2 elif len(S) == g[0]:
        y = k//2
        #print('?',y)
     len(S) == g[0] len(S) len S g[0] g 0 y = k//2 y k//2 k 2 y = k-1 y k-1 k 1 print(x*k + y) print x*k + y x*k x k y g = [len(list(v)) for k,v in groupby(S)] [len(list(v)) for k,v in groupby(S)] g x += c//2 c//2 x y = k-1 k-1 y k = int(input()) int(input()) k y = 0 0 y S = input() input() S x = y = 0 0 x y = k//2 k//2 y y = k//2 k//2 y
S = input()
k = int(input())
from itertools import groupby
x = y = 0
g = [len(list(v)) for k,v in groupby(S)]
for c in g:
    x += c//2
#print(len(S),g[0])
if S[-1] == S[0]:
    if g[-1]%2 == 0 or g[0]%2 == 0:
        pass
    elif len(S) == 1:
        y = k//2
    elif len(S) == g[0]:
        y = k//2
        #print('?',y)
    else:
        y = k-1
print(x*k + y)
