from itertools import groupby



S = eval(input())

K = int(eval(input()))



A = [len(tuple(v)) for _, v in groupby(S)]

if len(A) == 1:

    print(((len(S) * K) // 2))

    quit()



t = sum(a // 2 for a in A)

if S[0] == S[-1]:

    l, r = A[0], A[-1]

    m = t - l // 2 - r // 2

    print((K * m + (K - 1) * ((r + l) // 2) + r // 2 + l // 2))

else:

    print((t * K))

from itertools import groupby



S = eval(input())

K = int(eval(input()))



A = [len(tuple(v)) for _, v in groupby(S)]

if len(A) == 1:

    print(((A[0] * K) // 2))

    quit()



if S[0] == S[-1]:

    m = sum(a // 2 for a in A) - A[0] // 2 - A[-1] // 2

    print((K * m + (K - 1) * ((A[0] + A[-1]) // 2) + A[0] // 2 + A[-1] // 2))

else:

    print((sum(a // 2 for a in A) * K))

from itertools import groupby

S = eval(input())
K = int(eval(input()))
A = [len(tuple(v)) for _, v in groupby(S)]
if len(A) == 1:
    print(((len(S) * K) // 2))
    quit()
t = sum(a // 2 for a in A)
if S[0] == S[-1]:
    l, r = A[0], A[-1]
    m = t - l // 2 - r // 2
    print((K * m + (K - 1) * ((r + l) // 2) + r // 2 + l // 2))
else:
    print((t * K))

from itertools import groupby

S = eval(input())
K = int(eval(input()))
A = [len(tuple(v)) for _, v in groupby(S)]
if len(A) == 1:
    print(((A[0] * K) // 2))
    quit()
if S[0] == S[-1]:
    m = sum(a // 2 for a in A) - A[0] // 2 - A[-1] // 2
    print((K * m + (K - 1) * ((A[0] + A[-1]) // 2) + A[0] // 2 + A[-1] // 2))
else:
    print((sum(a // 2 for a in A) * K))

-    print(((len(S) * K) // 2)) +    print(((A[0] * K) // 2)) -t = sum(a // 2 for a in A) -    l, r = A[0], A[-1] -    m = t - l // 2 - r // 2 -    print((K * m + (K - 1) * ((r + l) // 2) + r // 2 + l // 2)) +    m = sum(a // 2 for a in A) - A[0] // 2 - A[-1] // 2 +    print((K * m + (K - 1) * ((A[0] + A[-1]) // 2) + A[0] // 2 + A[-1] // 2)) -    print((t * K)) +    print((sum(a // 2 for a in A) * K))