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

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

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

if s[0] != s[-1]:
    ans = [i//2 for i in ans]
    print(sum(ans) * k)
elif s[0] == s[-1]:
    f, m, l = ans[0] // 2, (ans[0] + ans[-1]) // 2, ans[-1] // 2
    ans = [i//2 for i in ans[1:-1]]
    print(f + sum(ans) * k + m * (k - 1) + l) s, k = input(), int(input()) s input() 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 ans, cnt = [], 1 ans [] cnt 1 for i in range(1, len(s)):
    if s[i] == s[i - 1]:
        cnt += 1
    else:
        ans.append(cnt)
        cnt = 1
else:
    ans.append(cnt) i range(1, len(s)) range 1 len(s) len s if s[i] == s[i - 1]:
        cnt += 1
    else:
        ans.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 ans.append(cnt) ans.append ans append cnt cnt = 1 cnt 1 ans.append(cnt) ans.append ans append cnt if s[0] != s[-1]:
    ans = [i//2 for i in ans]
    print(sum(ans) * k)
elif s[0] == s[-1]:
    f, m, l = ans[0] // 2, (ans[0] + ans[-1]) // 2, ans[-1] // 2
    ans = [i//2 for i in ans[1:-1]]
    print(f + sum(ans) * k + m * (k - 1) + l) s[0] != s[-1] s[0] s 0 s[-1] s -1 i//2 for i in ans for i in ans i ans for i in ans i//2 i 2 ans = [i//2 for i in ans] ans [i//2 for i in ans] print(sum(ans) * k) print sum(ans) * k sum(ans) sum ans k elif s[0] == s[-1]:
    f, m, l = ans[0] // 2, (ans[0] + ans[-1]) // 2, ans[-1] // 2
    ans = [i//2 for i in ans[1:-1]]
    print(f + sum(ans) * k + m * (k - 1) + l) s[0] == s[-1] s[0] s 0 s[-1] s -1 f, m, l = ans[0] // 2, (ans[0] + ans[-1]) // 2, ans[-1] // 2 f ans[0] // 2 ans[0] ans 0 2 m (ans[0] + ans[-1]) // 2 ans[0] + ans[-1] ans[0] ans 0 ans[-1] ans -1 2 l ans[-1] // 2 ans[-1] ans -1 2 i//2 for i in ans[1:-1] for i in ans[1:-1] i ans[1:-1] ans 1:-1 1 -1 for i in ans[1:-1] i//2 i 2 ans = [i//2 for i in ans[1:-1]] ans [i//2 for i in ans[1:-1]] print(f + sum(ans) * k + m * (k - 1) + l) print f + sum(ans) * k + m * (k - 1) + l f + sum(ans) * k + m * (k - 1) f + sum(ans) * k f sum(ans) * k sum(ans) sum ans k m * (k - 1) m k - 1 k 1 l ans, cnt = [], 1 [] ans f, m, l = ans[0] // 2, (ans[0] + ans[-1]) // 2, ans[-1] // 2 ans[0] // 2 f s, k = input(), int(input()) input() s l = ans[0] // 2, (ans[0] + ans[-1]) // 2, ans[-1] // 2 ans[-1] // 2 l cnt += 1 1 cnt ans = [i//2 for i in ans[1:-1]] [i//2 for i in ans[1:-1]] ans cnt = 1 1 cnt k = input(), int(input()) int(input()) k cnt = [], 1 1 cnt m, l = ans[0] // 2, (ans[0] + ans[-1]) // 2, ans[-1] // 2 (ans[0] + ans[-1]) // 2 m ans = [i//2 for i in ans] [i//2 for i in ans] ans
s, k = input(), int(input())

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

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

if s[0] != s[-1]:
    ans = [i//2 for i in ans]
    print(sum(ans) * k)
elif s[0] == s[-1]:
    f, m, l = ans[0] // 2, (ans[0] + ans[-1]) // 2, ans[-1] // 2
    ans = [i//2 for i in ans[1:-1]]
    print(f + sum(ans) * k + m * (k - 1) + l)
