s = input()
k = int(input())

if len(set(list(s))) == 1:
    print(len(s)*k//2)
    exit()

tmp = []
cnt = 1

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

tmp.append(cnt)

if s[0] != s[-1]:
    ans = [i//2 for i in tmp]
    print(sum(ans) * k)
else:
    a = tmp[0]//2
    b = (tmp[0] + tmp[-1])//2
    c = tmp[-1]//2
    ans = [i//2 for i in tmp[1:-1]]
    print(a+sum(ans)*k+b*(k-1)+c) s = input() s input() input k = int(input()) k int(input()) int input() input if len(set(list(s))) == 1:
    print(len(s)*k//2)
    exit() len(set(list(s))) == 1 len(set(list(s))) len set(list(s)) set list(s) list s 1 print(len(s)*k//2) print len(s)*k//2 len(s)*k len(s) len s k 2 exit() exit tmp = [] tmp [] cnt = 1 cnt 1 for i in range(1, len(s)):
    if s[i] == s[i-1]:
        cnt += 1
    else:
        tmp.append(cnt)
        cnt = 1 i range(1, len(s)) range 1 len(s) len s if s[i] == s[i-1]:
        cnt += 1
    else:
        tmp.append(cnt)
        cnt = 1 s[i] == s[i-1] s[i] s i s[i-1] s i-1 i 1 cnt += 1 cnt 1 tmp.append(cnt) tmp.append tmp append cnt cnt = 1 cnt 1 tmp.append(cnt) tmp.append tmp append cnt if s[0] != s[-1]:
    ans = [i//2 for i in tmp]
    print(sum(ans) * k)
else:
    a = tmp[0]//2
    b = (tmp[0] + tmp[-1])//2
    c = tmp[-1]//2
    ans = [i//2 for i in tmp[1:-1]]
    print(a+sum(ans)*k+b*(k-1)+c) s[0] != s[-1] s[0] s 0 s[-1] s -1 i//2 for i in tmp for i in tmp i tmp for i in tmp i//2 i 2 ans = [i//2 for i in tmp] ans [i//2 for i in tmp] print(sum(ans) * k) print sum(ans) * k sum(ans) sum ans k a = tmp[0]//2 a tmp[0]//2 tmp[0] tmp 0 2 b = (tmp[0] + tmp[-1])//2 b (tmp[0] + tmp[-1])//2 tmp[0] + tmp[-1] tmp[0] tmp 0 tmp[-1] tmp -1 2 c = tmp[-1]//2 c tmp[-1]//2 tmp[-1] tmp -1 2 i//2 for i in tmp[1:-1] for i in tmp[1:-1] i tmp[1:-1] tmp 1:-1 1 -1 for i in tmp[1:-1] i//2 i 2 ans = [i//2 for i in tmp[1:-1]] ans [i//2 for i in tmp[1:-1]] print(a+sum(ans)*k+b*(k-1)+c) print a+sum(ans)*k+b*(k-1)+c a+sum(ans)*k+b*(k-1) a+sum(ans)*k a sum(ans)*k sum(ans) sum ans k b*(k-1) b k-1 k 1 c c = tmp[-1]//2 tmp[-1]//2 c tmp = [] [] tmp a = tmp[0]//2 tmp[0]//2 a b = (tmp[0] + tmp[-1])//2 (tmp[0] + tmp[-1])//2 b k = int(input()) int(input()) k ans = [i//2 for i in tmp] [i//2 for i in tmp] ans cnt += 1 1 cnt cnt = 1 1 cnt cnt = 1 1 cnt ans = [i//2 for i in tmp[1:-1]] [i//2 for i in tmp[1:-1]] ans s = input() input() s
s = input()
k = int(input())

if len(set(list(s))) == 1:
    print(len(s)*k//2)
    exit()

tmp = []
cnt = 1

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

tmp.append(cnt)

if s[0] != s[-1]:
    ans = [i//2 for i in tmp]
    print(sum(ans) * k)
else:
    a = tmp[0]//2
    b = (tmp[0] + tmp[-1])//2
    c = tmp[-1]//2
    ans = [i//2 for i in tmp[1:-1]]
    print(a+sum(ans)*k+b*(k-1)+c)