import sys
input = sys.stdin.readline

S = input().strip()
K = int(input())

count_l = 0
count_r = 0
f = S.count(S[0]) == len(S)
for x in S:
    if x == S[0]:
        count_l += 1
    else:
        break

for x in S[::-1]:
    if x == S[-1]:
        count_r += 1
    else:
        break

ans = 0
for i in range(len(S) - 1):
    if S[i] == S[i + 1]:
        s = S[i]
        ans += 1
        S = S.replace(s * 2, s + '_', 1)

if count_l % 2 and count_r % 2 and S[0] == S[-1]:
    if f:
        ans = ans * K + K // 2
    else:
        ans = (ans + 1) * K - 1
else:
    ans *= K

print(ans) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline S = input().strip() S input().strip() ().strip () input strip K = int(input()) K int(input()) int input() input count_l = 0 count_l 0 count_r = 0 count_r 0 f = S.count(S[0]) == len(S) f S.count(S[0]) == len(S) S.count(S[0]) S.count S count S[0] S 0 len(S) len S for x in S:
    if x == S[0]:
        count_l += 1
    else:
        break x S if x == S[0]:
        count_l += 1
    else:
        break x == S[0] x S[0] S 0 count_l += 1 count_l 1 break for x in S[::-1]:
    if x == S[-1]:
        count_r += 1
    else:
        break x S[::-1] S ::-1 -1 if x == S[-1]:
        count_r += 1
    else:
        break x == S[-1] x S[-1] S -1 count_r += 1 count_r 1 break ans = 0 ans 0 for i in range(len(S) - 1):
    if S[i] == S[i + 1]:
        s = S[i]
        ans += 1
        S = S.replace(s * 2, s + '_', 1) i range(len(S) - 1) range len(S) - 1 len(S) len S 1 if S[i] == S[i + 1]:
        s = S[i]
        ans += 1
        S = S.replace(s * 2, s + '_', 1) S[i] == S[i + 1] S[i] S i S[i + 1] S i + 1 i 1 s = S[i] s S[i] S i ans += 1 ans 1 S = S.replace(s * 2, s + '_', 1) S S.replace(s * 2, s + '_', 1) S.replace S replace s * 2 s 2 s + '_' s '_' 1 if count_l % 2 and count_r % 2 and S[0] == S[-1]:
    if f:
        ans = ans * K + K // 2
    else:
        ans = (ans + 1) * K - 1
else:
    ans *= K count_l % 2 and count_r % 2 and S[0] == S[-1] count_l % 2 and count_r % 2 count_l % 2 count_l 2 count_r % 2 count_r 2 S[0] == S[-1] S[0] S 0 S[-1] S -1 if f:
        ans = ans * K + K // 2
    else:
        ans = (ans + 1) * K - 1 f ans = ans * K + K // 2 ans ans * K + K // 2 ans * K ans K K // 2 K 2 ans = (ans + 1) * K - 1 ans (ans + 1) * K - 1 (ans + 1) * K ans + 1 ans 1 K 1 ans *= K ans K print(ans) print ans count_r = 0 0 count_r count_r += 1 1 count_r ans = ans * K + K // 2 ans * K + K // 2 ans ans += 1 1 ans S = input().strip() input().strip() S count_l = 0 0 count_l K = int(input()) int(input()) K ans = 0 0 ans count_l += 1 1 count_l s = S[i] S[i] s input = sys.stdin.readline sys.stdin.readline input S = S.replace(s * 2, s + '_', 1) S.replace(s * 2, s + '_', 1) S ans *= K K ans f = S.count(S[0]) == len(S) S.count(S[0]) == len(S) f ans = (ans + 1) * K - 1 (ans + 1) * K - 1 ans
import sys
input = sys.stdin.readline

S = input().strip()
K = int(input())

count_l = 0
count_r = 0
f = S.count(S[0]) == len(S)
for x in S:
    if x == S[0]:
        count_l += 1
    else:
        break

for x in S[::-1]:
    if x == S[-1]:
        count_r += 1
    else:
        break

ans = 0
for i in range(len(S) - 1):
    if S[i] == S[i + 1]:
        s = S[i]
        ans += 1
        S = S.replace(s * 2, s + '_', 1)

if count_l % 2 and count_r % 2 and S[0] == S[-1]:
    if f:
        ans = ans * K + K // 2
    else:
        ans = (ans + 1) * K - 1
else:
    ans *= K

print(ans)
