S = input()
K = int(input())

ss = []
seq = 1
for a,b in zip(S,S[1:]):
    if a==b:
        seq += 1
    else:
        ss.append(seq)
        seq = 1
ss.append(seq)

if len(ss)==1:
    print(len(S)*K//2)
    exit()

if S[0] != S[-1]:
    ans = sum([v//2 for v in ss]) * K
    print(ans)
else:
    ans = sum([v//2 for v in ss[1:-1]]) * K
    ans += (ss[0]+ss[-1])//2 * (K-1)
    ans += ss[0]//2 + ss[-1]//2
    print(ans) S = input() S input() input K = int(input()) K int(input()) int input() input ss = [] ss [] seq = 1 seq 1 for a,b in zip(S,S[1:]):
    if a==b:
        seq += 1
    else:
        ss.append(seq)
        seq = 1 a b zip(S,S[1:]) zip S S[1:] S 1: 1 if a==b:
        seq += 1
    else:
        ss.append(seq)
        seq = 1 a==b a b seq += 1 seq 1 ss.append(seq) ss.append ss append seq seq = 1 seq 1 ss.append(seq) ss.append ss append seq if len(ss)==1:
    print(len(S)*K//2)
    exit() len(ss)==1 len(ss) len ss 1 print(len(S)*K//2) print len(S)*K//2 len(S)*K len(S) len S K 2 exit() exit if S[0] != S[-1]:
    ans = sum([v//2 for v in ss]) * K
    print(ans)
else:
    ans = sum([v//2 for v in ss[1:-1]]) * K
    ans += (ss[0]+ss[-1])//2 * (K-1)
    ans += ss[0]//2 + ss[-1]//2
    print(ans) S[0] != S[-1] S[0] S 0 S[-1] S -1 v//2 for v in ss for v in ss v ss for v in ss v//2 v 2 ans = sum([v//2 for v in ss]) * K ans sum([v//2 for v in ss]) * K sum([v//2 for v in ss]) sum [v//2 for v in ss] K print(ans) print ans v//2 for v in ss[1:-1] for v in ss[1:-1] v ss[1:-1] ss 1:-1 1 -1 for v in ss[1:-1] v//2 v 2 ans = sum([v//2 for v in ss[1:-1]]) * K ans sum([v//2 for v in ss[1:-1]]) * K sum([v//2 for v in ss[1:-1]]) sum [v//2 for v in ss[1:-1]] K ans += (ss[0]+ss[-1])//2 * (K-1) ans (ss[0]+ss[-1])//2 * (K-1) (ss[0]+ss[-1])//2 ss[0]+ss[-1] ss[0] ss 0 ss[-1] ss -1 2 K-1 K 1 ans += ss[0]//2 + ss[-1]//2 ans ss[0]//2 + ss[-1]//2 ss[0]//2 ss[0] ss 0 2 ss[-1]//2 ss[-1] ss -1 2 print(ans) print ans K = int(input()) int(input()) K ans += ss[0]//2 + ss[-1]//2 ss[0]//2 + ss[-1]//2 ans ans = sum([v//2 for v in ss]) * K sum([v//2 for v in ss]) * K ans seq = 1 1 seq ans += (ss[0]+ss[-1])//2 * (K-1) (ss[0]+ss[-1])//2 * (K-1) ans seq += 1 1 seq ss = [] [] ss seq = 1 1 seq S = input() input() S ans = sum([v//2 for v in ss[1:-1]]) * K sum([v//2 for v in ss[1:-1]]) * K ans
S = input()
K = int(input())

ss = []
seq = 1
for a,b in zip(S,S[1:]):
    if a==b:
        seq += 1
    else:
        ss.append(seq)
        seq = 1
ss.append(seq)

if len(ss)==1:
    print(len(S)*K//2)
    exit()

if S[0] != S[-1]:
    ans = sum([v//2 for v in ss]) * K
    print(ans)
else:
    ans = sum([v//2 for v in ss[1:-1]]) * K
    ans += (ss[0]+ss[-1])//2 * (K-1)
    ans += ss[0]//2 + ss[-1]//2
    print(ans)