def f(k):

    T = S*k

    N = len(T)

    cur = T[0]

    cnt = 1

    ans = 0

    for i in range(1,N):

        if T[i]==cur:

            cnt += 1

        else:

            ans += cnt//2

            cur = T[i]

            cnt = 1

    ans += cnt//2

    return ans

S = input().strip()

K = int(eval(input()))

ans1 = f(1)

ans2 = f(2)

ans3 = f(3)

d1 = f(2)-f(1)

d2 = f(3)-f(2)

k = (K-1)//2

if (K-1)%2==0:

    print((f(1)+(d1+d2)*k))

else:

    print((f(1)+(d1+d2)*k+d1))
C = {}

S = input().strip()

N = len(S)

K = int(eval(input()))

for i in range(N):

    s = S[i]

    if s not in C:

        C[s]=0

    C[s] += 1

if len(C)>1:

    a = 0

    cnt = 1

    for i in range(1,N):

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

            cnt += 1

        else:

            a += cnt//2

            cnt = 1

    a += cnt//2

    X = S+S

    b = 0

    cnt = 1

    for i in range(1,2*N):

        if X[i]==X[i-1]:

            cnt += 1

        else:

            b += cnt//2

            cnt = 1

    b += cnt//2

    d = b-a

    print((a+d*(K-1)))

else:

    A = list(C.items())

    k = A[0][1]

    if k%2==0:

        print(((k//2)*K))

    else:

        if K%2==0:

            a = k

            b = 2*k

            d = k

            print((a+d*((K//2)-1)))

        else:

            a = k//2

            b = (k*3)//2

            d = b-a

            print((a+d*(K//2)))
def f(k):
    T = S * k
    N = len(T)
    cur = T[0]
    cnt = 1
    ans = 0
    for i in range(1, N):
        if T[i] == cur:
            cnt += 1
        else:
            ans += cnt // 2
            cur = T[i]
            cnt = 1
    ans += cnt // 2
    return ans


S = input().strip()
K = int(eval(input()))
ans1 = f(1)
ans2 = f(2)
ans3 = f(3)
d1 = f(2) - f(1)
d2 = f(3) - f(2)
k = (K - 1) // 2
if (K - 1) % 2 == 0:
    print((f(1) + (d1 + d2) * k))
else:
    print((f(1) + (d1 + d2) * k + d1))

C = {}
S = input().strip()
N = len(S)
K = int(eval(input()))
for i in range(N):
    s = S[i]
    if s not in C:
        C[s] = 0
    C[s] += 1
if len(C) > 1:
    a = 0
    cnt = 1
    for i in range(1, N):
        if S[i] == S[i - 1]:
            cnt += 1
        else:
            a += cnt // 2
            cnt = 1
    a += cnt // 2
    X = S + S
    b = 0
    cnt = 1
    for i in range(1, 2 * N):
        if X[i] == X[i - 1]:
            cnt += 1
        else:
            b += cnt // 2
            cnt = 1
    b += cnt // 2
    d = b - a
    print((a + d * (K - 1)))
else:
    A = list(C.items())
    k = A[0][1]
    if k % 2 == 0:
        print(((k // 2) * K))
    else:
        if K % 2 == 0:
            a = k
            b = 2 * k
            d = k
            print((a + d * ((K // 2) - 1)))
        else:
            a = k // 2
            b = (k * 3) // 2
            d = b - a
            print((a + d * (K // 2)))

-def f(k): -    T = S * k -    N = len(T) -    cur = T[0] +C = {} +S = input().strip() +N = len(S) +K = int(eval(input())) +for i in range(N): +    s = S[i] +    if s not in C: +        C[s] = 0 +    C[s] += 1 +if len(C) > 1: +    a = 0 -    ans = 0 -        if T[i] == cur: +        if S[i] == S[i - 1]: -            ans += cnt // 2 -            cur = T[i] +            a += cnt // 2 -    ans += cnt // 2 -    return ans - - -S = input().strip() -K = int(eval(input())) -ans1 = f(1) -ans2 = f(2) -ans3 = f(3) -d1 = f(2) - f(1) -d2 = f(3) - f(2) -k = (K - 1) // 2 -if (K - 1) % 2 == 0: -    print((f(1) + (d1 + d2) * k)) +    a += cnt // 2 +    X = S + S +    b = 0 +    cnt = 1 +    for i in range(1, 2 * N): +        if X[i] == X[i - 1]: +            cnt += 1 +        else: +            b += cnt // 2 +            cnt = 1 +    b += cnt // 2 +    d = b - a +    print((a + d * (K - 1))) -    print((f(1) + (d1 + d2) * k + d1)) +    A = list(C.items()) +    k = A[0][1] +    if k % 2 == 0: +        print(((k // 2) * K)) +    else: +        if K % 2 == 0: +            a = k +            b = 2 * k +            d = k +            print((a + d * ((K // 2) - 1))) +        else: +            a = k // 2 +            b = (k * 3) // 2 +            d = b - a +            print((a + d * (K // 2)))