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

S1 = list(S)
cnt1 = 0
for i in range(1, len(S1)):
    if S1[i] == S1[i - 1]:
        S1[i] = '*'
        cnt1 += 1

S2 = list(S) * 2
cnt2 = 0
for i in range(1, len(S2)):
    if S2[i] == S2[i - 1]:
        S2[i] = '*'
        cnt2 += 1
        
S3 = list(S) * 3
cnt3 = 0
for i in range(1, len(S3)):
    if S3[i] == S3[i - 1]:
        S3[i] = '*'
        cnt3 += 1

# print("#", S1, S2, S3)
# print("#", cnt1, cnt2, cnt3)
ans = cnt1 + (cnt2 - cnt1) * (K // 2) + (cnt3 - cnt2) * ((K - 1) // 2)
print(ans) S = list(input()) S list(input()) list input() input K = int(input()) K int(input()) int input() input S1 = list(S) S1 list(S) list S cnt1 = 0 cnt1 0 for i in range(1, len(S1)):
    if S1[i] == S1[i - 1]:
        S1[i] = '*'
        cnt1 += 1 i range(1, len(S1)) range 1 len(S1) len S1 if S1[i] == S1[i - 1]:
        S1[i] = '*'
        cnt1 += 1 S1[i] == S1[i - 1] S1[i] S1 i S1[i - 1] S1 i - 1 i 1 S1[i] = '*' S1[i] S1 i '*' cnt1 += 1 cnt1 1 S2 = list(S) * 2 S2 list(S) * 2 list(S) list S 2 cnt2 = 0 cnt2 0 for i in range(1, len(S2)):
    if S2[i] == S2[i - 1]:
        S2[i] = '*'
        cnt2 += 1
         i range(1, len(S2)) range 1 len(S2) len S2 if S2[i] == S2[i - 1]:
        S2[i] = '*'
        cnt2 += 1
         S2[i] == S2[i - 1] S2[i] S2 i S2[i - 1] S2 i - 1 i 1 S2[i] = '*' S2[i] S2 i '*' cnt2 += 1 cnt2 1 S3 = list(S) * 3 S3 list(S) * 3 list(S) list S 3 cnt3 = 0 cnt3 0 for i in range(1, len(S3)):
    if S3[i] == S3[i - 1]:
        S3[i] = '*'
        cnt3 += 1

# print("#", S1, S2, S3)
# print("#", cnt1, cnt2, cnt3) i range(1, len(S3)) range 1 len(S3) len S3 if S3[i] == S3[i - 1]:
        S3[i] = '*'
        cnt3 += 1

# print("#", S1, S2, S3)
# print("#", cnt1, cnt2, cnt3) S3[i] == S3[i - 1] S3[i] S3 i S3[i - 1] S3 i - 1 i 1 S3[i] = '*' S3[i] S3 i '*' cnt3 += 1 cnt3 1 ans = cnt1 + (cnt2 - cnt1) * (K // 2) + (cnt3 - cnt2) * ((K - 1) // 2) ans cnt1 + (cnt2 - cnt1) * (K // 2) + (cnt3 - cnt2) * ((K - 1) // 2) cnt1 + (cnt2 - cnt1) * (K // 2) cnt1 (cnt2 - cnt1) * (K // 2) cnt2 - cnt1 cnt2 cnt1 K // 2 K 2 (cnt3 - cnt2) * ((K - 1) // 2) cnt3 - cnt2 cnt3 cnt2 (K - 1) // 2 K - 1 K 1 2 print(ans) print ans S2 = list(S) * 2 list(S) * 2 S2 cnt1 += 1 1 cnt1 cnt2 += 1 1 cnt2 S1 = list(S) list(S) S1 cnt3 = 0 0 cnt3 S = list(input()) list(input()) S cnt2 = 0 0 cnt2 S3 = list(S) * 3 list(S) * 3 S3 ans = cnt1 + (cnt2 - cnt1) * (K // 2) + (cnt3 - cnt2) * ((K - 1) // 2) cnt1 + (cnt2 - cnt1) * (K // 2) + (cnt3 - cnt2) * ((K - 1) // 2) ans K = int(input()) int(input()) K cnt1 = 0 0 cnt1 cnt3 += 1 1 cnt3
S = list(input())
K = int(input())

S1 = list(S)
cnt1 = 0
for i in range(1, len(S1)):
    if S1[i] == S1[i - 1]:
        S1[i] = '*'
        cnt1 += 1

S2 = list(S) * 2
cnt2 = 0
for i in range(1, len(S2)):
    if S2[i] == S2[i - 1]:
        S2[i] = '*'
        cnt2 += 1
        
S3 = list(S) * 3
cnt3 = 0
for i in range(1, len(S3)):
    if S3[i] == S3[i - 1]:
        S3[i] = '*'
        cnt3 += 1

# print("#", S1, S2, S3)
# print("#", cnt1, cnt2, cnt3)
ans = cnt1 + (cnt2 - cnt1) * (K // 2) + (cnt3 - cnt2) * ((K - 1) // 2)
print(ans)
