#!/usr/bin/env python3

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

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

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

ans = 0
if len(C) == 1:
    print((C[0][1]*K) // 2)
    exit()
else:
    for c in C:
        ans += c[1] // 2

ans *= K

ans2 = 0
if S[-1] == S[0]:
    ans2 = ((C[0][1]+C[-1][1])//2 - C[0][1]//2 - C[-1][1]//2) * (K-1)
print(ans + ans2) S = input() S input() input K = int(input()) K int(input()) int input() input if len(S) == 1:
    print(K//2)
    exit() len(S) == 1 len(S) len S 1 print(K//2) print K//2 K 2 exit() exit cnt = 1 cnt 1 C = [] C [] for i in range(1,len(S)):
    if S[i-1] == S[i]:
        cnt += 1
    else:
        C.append([S[i-1], cnt])
        cnt = 1 i range(1,len(S)) range 1 len(S) len S if S[i-1] == S[i]:
        cnt += 1
    else:
        C.append([S[i-1], cnt])
        cnt = 1 S[i-1] == S[i] S[i-1] S i-1 i 1 S[i] S i cnt += 1 cnt 1 C.append([S[i-1], cnt]) C.append C append [S[i-1], cnt] S[i-1] S i-1 i 1 cnt cnt = 1 cnt 1 C.append([S[i], cnt]) C.append C append [S[i], cnt] S[i] S i cnt ans = 0 ans 0 if len(C) == 1:
    print((C[0][1]*K) // 2)
    exit()
else:
    for c in C:
        ans += c[1] // 2 len(C) == 1 len(C) len C 1 print((C[0][1]*K) // 2) print (C[0][1]*K) // 2 C[0][1]*K C[0][1] [0] C 0 1 K 2 exit() exit for c in C:
        ans += c[1] // 2 c C ans += c[1] // 2 ans c[1] // 2 c[1] c 1 2 ans *= K ans K ans2 = 0 ans2 0 if S[-1] == S[0]:
    ans2 = ((C[0][1]+C[-1][1])//2 - C[0][1]//2 - C[-1][1]//2) * (K-1) S[-1] == S[0] S[-1] S -1 S[0] S 0 ans2 = ((C[0][1]+C[-1][1])//2 - C[0][1]//2 - C[-1][1]//2) * (K-1) ans2 ((C[0][1]+C[-1][1])//2 - C[0][1]//2 - C[-1][1]//2) * (K-1) (C[0][1]+C[-1][1])//2 - C[0][1]//2 - C[-1][1]//2 (C[0][1]+C[-1][1])//2 - C[0][1]//2 (C[0][1]+C[-1][1])//2 C[0][1]+C[-1][1] C[0][1] [0] C 0 1 C[-1][1] [-1] C -1 1 2 C[0][1]//2 C[0][1] [0] C 0 1 2 C[-1][1]//2 C[-1][1] [-1] C -1 1 2 K-1 K 1 print(ans + ans2) print ans + ans2 ans ans2 ans2 = 0 0 ans2 ans = 0 0 ans cnt = 1 1 cnt K = int(input()) int(input()) K C = [] [] C ans += c[1] // 2 c[1] // 2 ans cnt = 1 1 cnt S = input() input() S ans *= K K ans cnt += 1 1 cnt ans2 = ((C[0][1]+C[-1][1])//2 - C[0][1]//2 - C[-1][1]//2) * (K-1) ((C[0][1]+C[-1][1])//2 - C[0][1]//2 - C[-1][1]//2) * (K-1) ans2
#!/usr/bin/env python3

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

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

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

ans = 0
if len(C) == 1:
    print((C[0][1]*K) // 2)
    exit()
else:
    for c in C:
        ans += c[1] // 2

ans *= K

ans2 = 0
if S[-1] == S[0]:
    ans2 = ((C[0][1]+C[-1][1])//2 - C[0][1]//2 - C[-1][1]//2) * (K-1)
print(ans + ans2)
