S = list(input())
K = int(input())


def solve(S, K):
    T = S * K
    ans = 0
    for i in range(len(T) - 1):
        if T[i] == T[i + 1]:
            ans += 1
            T[i + 1] = "*"
    return ans


A = [solve(S, i) for i in range(6)]
if K <= 5:
    print(A[K])
else:
    if K % 2 == 1:
        d = A[5] - A[3]
        print(A[5] + (K - 5) // 2 * d)
    else:
        d = A[4] - A[2]
        print(A[4] + (K - 4) // 2 * d) S = list(input()) S list(input()) list input() input K = int(input()) K int(input()) int input() input def solve(S, K):
    T = S * K
    ans = 0
    for i in range(len(T) - 1):
        if T[i] == T[i + 1]:
            ans += 1
            T[i + 1] = "*"
    return ans solve T = S * K T S * K S K ans = 0 ans 0 for i in range(len(T) - 1):
        if T[i] == T[i + 1]:
            ans += 1
            T[i + 1] = "*"
     i range(len(T) - 1) range len(T) - 1 len(T) len T 1 if T[i] == T[i + 1]:
            ans += 1
            T[i + 1] = "*"
     T[i] == T[i + 1] T[i] T i T[i + 1] T i + 1 i 1 ans += 1 ans 1 T[i + 1] = "*" T[i + 1] T i + 1 i 1 "*" return ans ans S S K K solve(S, i) for i in range(6) for i in range(6) i range(6) range 6 for i in range(6) solve(S, i) solve S i A = [solve(S, i) for i in range(6)] A [solve(S, i) for i in range(6)] if K <= 5:
    print(A[K])
else:
    if K % 2 == 1:
        d = A[5] - A[3]
        print(A[5] + (K - 5) // 2 * d)
    else:
        d = A[4] - A[2]
        print(A[4] + (K - 4) // 2 * d) K <= 5 K 5 print(A[K]) print A[K] A K if K % 2 == 1:
        d = A[5] - A[3]
        print(A[5] + (K - 5) // 2 * d)
    else:
        d = A[4] - A[2]
        print(A[4] + (K - 4) // 2 * d) K % 2 == 1 K % 2 K 2 1 d = A[5] - A[3] d A[5] - A[3] A[5] A 5 A[3] A 3 print(A[5] + (K - 5) // 2 * d) print A[5] + (K - 5) // 2 * d A[5] A 5 (K - 5) // 2 * d (K - 5) // 2 K - 5 K 5 2 d d = A[4] - A[2] d A[4] - A[2] A[4] A 4 A[2] A 2 print(A[4] + (K - 4) // 2 * d) print A[4] + (K - 4) // 2 * d A[4] A 4 (K - 4) // 2 * d (K - 4) // 2 K - 4 K 4 2 d d = A[4] - A[2] A[4] - A[2] d S = list(input()) list(input()) S A = [solve(S, i) for i in range(6)] [solve(S, i) for i in range(6)] A def solve(S, K):
    T = S * K
    ans = 0
    for i in range(len(T) - 1):
        if T[i] == T[i + 1]:
            ans += 1
            T[i + 1] = "*"
    return ans def solve(S, K):
    T = S * K
    ans = 0
    for i in range(len(T) - 1):
        if T[i] == T[i + 1]:
            ans += 1
            T[i + 1] = "*"
    return ans solve K = int(input()) int(input()) K d = A[5] - A[3] A[5] - A[3] d
S = list(input())
K = int(input())


def solve(S, K):
    T = S * K
    ans = 0
    for i in range(len(T) - 1):
        if T[i] == T[i + 1]:
            ans += 1
            T[i + 1] = "*"
    return ans


A = [solve(S, i) for i in range(6)]
if K <= 5:
    print(A[K])
else:
    if K % 2 == 1:
        d = A[5] - A[3]
        print(A[5] + (K - 5) // 2 * d)
    else:
        d = A[4] - A[2]
        print(A[4] + (K - 4) // 2 * d)
