S = input()
K = int(input())
prev = S[0]
compressed = [1]
for c in S[1:]:
    if c == prev:
        compressed[-1] += 1
    else:
        prev = c
        compressed.append(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] + compressed[-1]) // 2
        tmp -= compressed[0] // 2
        tmp -= compressed[-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 = [1] compressed [1] 1 for c in S[1:]:
    if c == prev:
        compressed[-1] += 1
    else:
        prev = c
        compressed.append(1) c S[1:] S 1: 1 if c == prev:
        compressed[-1] += 1
    else:
        prev = c
        compressed.append(1) c == prev c prev compressed[-1] += 1 compressed[-1] compressed -1 1 prev = c prev c compressed.append(1) compressed.append compressed append 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] + compressed[-1]) // 2
        tmp -= compressed[0] // 2
        tmp -= compressed[-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] + compressed[-1]) // 2
        tmp -= compressed[0] // 2
        tmp -= compressed[-1] // 2
        ans += tmp * (K - 1)
     S[0] == S[-1] S[0] S 0 S[-1] S -1 tmp = (compressed[0] + compressed[-1]) // 2 tmp (compressed[0] + compressed[-1]) // 2 compressed[0] + compressed[-1] compressed[0] compressed 0 compressed[-1] compressed -1 2 tmp -= compressed[0] // 2 tmp compressed[0] // 2 compressed[0] compressed 0 2 tmp -= compressed[-1] // 2 tmp compressed[-1] // 2 compressed[-1] compressed -1 2 ans += tmp * (K - 1) ans tmp * (K - 1) tmp K - 1 K 1 print(ans) print ans tmp = (compressed[0] + compressed[-1]) // 2 (compressed[0] + compressed[-1]) // 2 tmp K = int(input()) int(input()) K prev = c c prev compressed = [1] [1] compressed S = input() input() S prev = S[0] S[0] prev ans = sum(cnt // 2 for cnt in compressed) * K sum(cnt // 2 for cnt in compressed) * K ans tmp -= compressed[0] // 2 compressed[0] // 2 tmp tmp -= compressed[-1] // 2 compressed[-1] // 2 tmp ans += tmp * (K - 1) tmp * (K - 1) ans
S = input()
K = int(input())
prev = S[0]
compressed = [1]
for c in S[1:]:
    if c == prev:
        compressed[-1] += 1
    else:
        prev = c
        compressed.append(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] + compressed[-1]) // 2
        tmp -= compressed[0] // 2
        tmp -= compressed[-1] // 2
        ans += tmp * (K - 1)
    print(ans)
