S = input()
K = int(input())
prev = S[0]
compressed = [[prev, 1]]
for c in S[1:]:
    if c == compressed[-1][0]:
        compressed[-1][1] += 1
    else:
        compressed.append([c, 1])
if len(compressed) == 1:
    print(len(S) * K // 2)
else:
    ans = sum(cnt // 2 for _, cnt in compressed) * K
    if S[0] == S[-1]:
        tmp = (compressed[0][1] + compressed[-1][1]) // 2
        tmp -= compressed[0][1] // 2
        tmp -= compressed[-1][1] // 2
        ans += tmp * (K - 1)
    print(ans) S = input() S input() input K = int(input()) K int(input()) int input() input prev = S[0] prev S[0] S 0 compressed = [[prev, 1]] compressed [[prev, 1]] [prev, 1] prev 1 for c in S[1:]:
    if c == compressed[-1][0]:
        compressed[-1][1] += 1
    else:
        compressed.append([c, 1]) c S[1:] S 1: 1 if c == compressed[-1][0]:
        compressed[-1][1] += 1
    else:
        compressed.append([c, 1]) c == compressed[-1][0] c compressed[-1][0] [-1] compressed -1 0 compressed[-1][1] += 1 compressed[-1][1] [-1] compressed -1 1 1 compressed.append([c, 1]) compressed.append compressed append [c, 1] c 1 if len(compressed) == 1:
    print(len(S) * K // 2)
else:
    ans = sum(cnt // 2 for _, cnt in compressed) * K
    if S[0] == S[-1]:
        tmp = (compressed[0][1] + compressed[-1][1]) // 2
        tmp -= compressed[0][1] // 2
        tmp -= compressed[-1][1] // 2
        ans += tmp * (K - 1)
    print(ans) len(compressed) == 1 len(compressed) len compressed 1 print(len(S) * K // 2) print len(S) * K // 2 len(S) * K len(S) len S K 2 ans = sum(cnt // 2 for _, cnt in compressed) * K ans sum(cnt // 2 for _, cnt in compressed) * K sum(cnt // 2 for _, cnt in compressed) sum cnt // 2 cnt 2 K if S[0] == S[-1]:
        tmp = (compressed[0][1] + compressed[-1][1]) // 2
        tmp -= compressed[0][1] // 2
        tmp -= compressed[-1][1] // 2
        ans += tmp * (K - 1)
     S[0] == S[-1] S[0] S 0 S[-1] S -1 tmp = (compressed[0][1] + compressed[-1][1]) // 2 tmp (compressed[0][1] + compressed[-1][1]) // 2 compressed[0][1] + compressed[-1][1] compressed[0][1] [0] compressed 0 1 compressed[-1][1] [-1] compressed -1 1 2 tmp -= compressed[0][1] // 2 tmp compressed[0][1] // 2 compressed[0][1] [0] compressed 0 1 2 tmp -= compressed[-1][1] // 2 tmp compressed[-1][1] // 2 compressed[-1][1] [-1] compressed -1 1 2 ans += tmp * (K - 1) ans tmp * (K - 1) tmp K - 1 K 1 print(ans) print ans ans = sum(cnt // 2 for _, cnt in compressed) * K sum(cnt // 2 for _, cnt in compressed) * K ans S = input() input() S ans += tmp * (K - 1) tmp * (K - 1) ans tmp = (compressed[0][1] + compressed[-1][1]) // 2 (compressed[0][1] + compressed[-1][1]) // 2 tmp K = int(input()) int(input()) K compressed = [[prev, 1]] [[prev, 1]] compressed tmp -= compressed[0][1] // 2 compressed[0][1] // 2 tmp prev = S[0] S[0] prev tmp -= compressed[-1][1] // 2 compressed[-1][1] // 2 tmp
S = input()
K = int(input())
prev = S[0]
compressed = [[prev, 1]]
for c in S[1:]:
    if c == compressed[-1][0]:
        compressed[-1][1] += 1
    else:
        compressed.append([c, 1])
if len(compressed) == 1:
    print(len(S) * K // 2)
else:
    ans = sum(cnt // 2 for _, cnt in compressed) * K
    if S[0] == S[-1]:
        tmp = (compressed[0][1] + compressed[-1][1]) // 2
        tmp -= compressed[0][1] // 2
        tmp -= compressed[-1][1] // 2
        ans += tmp * (K - 1)
    print(ans)
