#!/usr/bin/env python3
s = input()
k = int(input())
n = len(s)
b = [0] * n
c = [0] * n
c[0] = 1

for i in range(n):
    if s[i - 1] == s[i] and not c[i - 1]:
        c[i] = 1
    if i and s[i - 1] == s[i] and not b[i - 1]:
        b[i] = 1
s1 = sum(b)
s2 = sum(c)
if s[-1] != s[0] or b[-1]:
    print(s1 * k)
else:
    if c[-1]:
        print((s1 + s2) * (k // 2) + s1 * (k % 2))
    else:
        print(s1 + (k - 1) * s2) s = input() s input() input k = int(input()) k int(input()) int input() input n = len(s) n len(s) len s b = [0] * n b [0] * n [0] 0 n c = [0] * n c [0] * n [0] 0 n c[0] = 1 c[0] c 0 1 for i in range(n):
    if s[i - 1] == s[i] and not c[i - 1]:
        c[i] = 1
    if i and s[i - 1] == s[i] and not b[i - 1]:
        b[i] = 1 i range(n) range n if s[i - 1] == s[i] and not c[i - 1]:
        c[i] = 1
     s[i - 1] == s[i] and not c[i - 1] s[i - 1] == s[i] s[i - 1] s i - 1 i 1 s[i] s i not c[i - 1] c[i - 1] c i - 1 i 1 c[i] = 1 c[i] c i 1 if i and s[i - 1] == s[i] and not b[i - 1]:
        b[i] = 1 i and s[i - 1] == s[i] and not b[i - 1] i and s[i - 1] == s[i] i s[i - 1] == s[i] s[i - 1] s i - 1 i 1 s[i] s i not b[i - 1] b[i - 1] b i - 1 i 1 b[i] = 1 b[i] b i 1 s1 = sum(b) s1 sum(b) sum b s2 = sum(c) s2 sum(c) sum c if s[-1] != s[0] or b[-1]:
    print(s1 * k)
else:
    if c[-1]:
        print((s1 + s2) * (k // 2) + s1 * (k % 2))
    else:
        print(s1 + (k - 1) * s2) s[-1] != s[0] or b[-1] s[-1] != s[0] s[-1] s -1 s[0] s 0 b[-1] b -1 print(s1 * k) print s1 * k s1 k if c[-1]:
        print((s1 + s2) * (k // 2) + s1 * (k % 2))
    else:
        print(s1 + (k - 1) * s2) c[-1] c -1 print((s1 + s2) * (k // 2) + s1 * (k % 2)) print (s1 + s2) * (k // 2) + s1 * (k % 2) (s1 + s2) * (k // 2) s1 + s2 s1 s2 k // 2 k 2 s1 * (k % 2) s1 k % 2 k 2 print(s1 + (k - 1) * s2) print s1 + (k - 1) * s2 s1 (k - 1) * s2 k - 1 k 1 s2 b = [0] * n [0] * n b s1 = sum(b) sum(b) s1 s2 = sum(c) sum(c) s2 s = input() input() s k = int(input()) int(input()) k n = len(s) len(s) n c = [0] * n [0] * n c
#!/usr/bin/env python3
s = input()
k = int(input())
n = len(s)
b = [0] * n
c = [0] * n
c[0] = 1

for i in range(n):
    if s[i - 1] == s[i] and not c[i - 1]:
        c[i] = 1
    if i and s[i - 1] == s[i] and not b[i - 1]:
        b[i] = 1
s1 = sum(b)
s2 = sum(c)
if s[-1] != s[0] or b[-1]:
    print(s1 * k)
else:
    if c[-1]:
        print((s1 + s2) * (k // 2) + s1 * (k % 2))
    else:
        print(s1 + (k - 1) * s2)
