from itertools import groupby
S=input()
K=int(input())
count=0
group=[len(list(value)) for key,value in groupby(S)]
for value in group:
    count+=value//2
count*=K
if S[0]==S[-1] and group[0]%2!=0 and group[-1]%2!=0:
    if len(S)==group[0]:
        count+=K//2
    else:
        count+=K-1
print(count) from itertools import groupby S=input() S input() input K=int(input()) K int(input()) int input() input count=0 count 0 len(list(value)) for key,value in groupby(S) for key,value in groupby(S) key value groupby(S) groupby S for key,value in groupby(S) len(list(value)) len list(value) list value group=[len(list(value)) for key,value in groupby(S)] group [len(list(value)) for key,value in groupby(S)] for value in group:
    count+=value//2 value group count+=value//2 count value//2 value 2 count*=K count K if S[0]==S[-1] and group[0]%2!=0 and group[-1]%2!=0:
    if len(S)==group[0]:
        count+=K//2
    else:
        count+=K-1 S[0]==S[-1] and group[0]%2!=0 and group[-1]%2!=0 S[0]==S[-1] and group[0]%2!=0 S[0]==S[-1] S[0] S 0 S[-1] S -1 group[0]%2!=0 group[0]%2 group[0] group 0 2 0 group[-1]%2!=0 group[-1]%2 group[-1] group -1 2 0 if len(S)==group[0]:
        count+=K//2
    else:
        count+=K-1 len(S)==group[0] len(S) len S group[0] group 0 count+=K//2 count K//2 K 2 count+=K-1 count K-1 K 1 print(count) print count K=int(input()) int(input()) K S=input() input() S count+=K-1 K-1 count group=[len(list(value)) for key,value in groupby(S)] [len(list(value)) for key,value in groupby(S)] group count=0 0 count count+=value//2 value//2 count count*=K K count count+=K//2 K//2 count
from itertools import groupby
S=input()
K=int(input())
count=0
group=[len(list(value)) for key,value in groupby(S)]
for value in group:
    count+=value//2
count*=K
if S[0]==S[-1] and group[0]%2!=0 and group[-1]%2!=0:
    if len(S)==group[0]:
        count+=K//2
    else:
        count+=K-1
print(count)