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

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

b = [1]
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        b[-1] += 1
    else:
        b.append(1)

ans = 0
for i in b:
    ans += i//2
ans *= K

if S[0] == S[-1] and b[0]%2 == b[-1]%2 == 1:
    ans += K - 1
print(ans) S = input() S input() input K = int(input()) K int(input()) int input() input if len(set(S)) == 1:
    print(len(S)*K//2)
    exit() len(set(S)) == 1 len(set(S)) len set(S) set S 1 print(len(S)*K//2) print len(S)*K//2 len(S)*K len(S) len S K 2 exit() exit b = [1] b [1] 1 for i in range(len(S)-1):
    if S[i] == S[i+1]:
        b[-1] += 1
    else:
        b.append(1) i range(len(S)-1) range len(S)-1 len(S) len S 1 if S[i] == S[i+1]:
        b[-1] += 1
    else:
        b.append(1) S[i] == S[i+1] S[i] S i S[i+1] S i+1 i 1 b[-1] += 1 b[-1] b -1 1 b.append(1) b.append b append 1 ans = 0 ans 0 for i in b:
    ans += i//2 i b ans += i//2 ans i//2 i 2 ans *= K ans K if S[0] == S[-1] and b[0]%2 == b[-1]%2 == 1:
    ans += K - 1 S[0] == S[-1] and b[0]%2 == b[-1]%2 == 1 S[0] == S[-1] S[0] S 0 S[-1] S -1 b[0]%2 == b[-1]%2 == 1 b[0]%2 == b[-1]%2 b[0]%2 b[0] b 0 2 b[-1]%2 b[-1] b -1 2 1 ans += K - 1 ans K - 1 K 1 print(ans) print ans ans += K - 1 K - 1 ans S = input() input() S K = int(input()) int(input()) K ans = 0 0 ans ans += i//2 i//2 ans ans *= K K ans b = [1] [1] b
S = input()
K = int(input())

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

b = [1]
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        b[-1] += 1
    else:
        b.append(1)

ans = 0
for i in b:
    ans += i//2
ans *= K

if S[0] == S[-1] and b[0]%2 == b[-1]%2 == 1:
    ans += K - 1
print(ans)