def run_length_compress(S):
    res = [[S[0], 1]]
    for c in S[1:]:
        if c == res[-1][0]:
            res[-1][1] += 1
        else:
            res.append([c, 1])
    return res


S = input()
N = len(S)
K = int(input())
T = run_length_compress(S)
if T[0][1] == N:
    print(N * K // 2)
    exit()
ans = sum(l // 2 for _, l in T) * K
if T[0][0] == T[-1][0]:
    head, tail = T[0][1], T[-1][1]
    ans += ((head + tail) // 2 - head // 2 - tail // 2) * (K - 1)
print(ans) def run_length_compress(S):
    res = [[S[0], 1]]
    for c in S[1:]:
        if c == res[-1][0]:
            res[-1][1] += 1
        else:
            res.append([c, 1])
    return res run_length_compress res = [[S[0], 1]] res [[S[0], 1]] [S[0], 1] S[0] S 0 1 for c in S[1:]:
        if c == res[-1][0]:
            res[-1][1] += 1
        else:
            res.append([c, 1])
     c S[1:] S 1: 1 if c == res[-1][0]:
            res[-1][1] += 1
        else:
            res.append([c, 1])
     c == res[-1][0] c res[-1][0] [-1] res -1 0 res[-1][1] += 1 res[-1][1] [-1] res -1 1 1 res.append([c, 1]) res.append res append [c, 1] c 1 return res res S S S = input() S input() input N = len(S) N len(S) len S K = int(input()) K int(input()) int input() input T = run_length_compress(S) T run_length_compress(S) run_length_compress S if T[0][1] == N:
    print(N * K // 2)
    exit() T[0][1] == N T[0][1] [0] T 0 1 N print(N * K // 2) print N * K // 2 N * K N K 2 exit() exit ans = sum(l // 2 for _, l in T) * K ans sum(l // 2 for _, l in T) * K sum(l // 2 for _, l in T) sum l // 2 l 2 K if T[0][0] == T[-1][0]:
    head, tail = T[0][1], T[-1][1]
    ans += ((head + tail) // 2 - head // 2 - tail // 2) * (K - 1) T[0][0] == T[-1][0] T[0][0] [0] T 0 0 T[-1][0] [-1] T -1 0 head, tail = T[0][1], T[-1][1] head T[0][1] [0] T 0 1 tail T[-1][1] [-1] T -1 1 ans += ((head + tail) // 2 - head // 2 - tail // 2) * (K - 1) ans ((head + tail) // 2 - head // 2 - tail // 2) * (K - 1) (head + tail) // 2 - head // 2 - tail // 2 (head + tail) // 2 - head // 2 (head + tail) // 2 head + tail head tail 2 head // 2 head 2 tail // 2 tail 2 K - 1 K 1 print(ans) print ans ans += ((head + tail) // 2 - head // 2 - tail // 2) * (K - 1) ((head + tail) // 2 - head // 2 - tail // 2) * (K - 1) ans S = input() input() S T = run_length_compress(S) run_length_compress(S) T K = int(input()) int(input()) K def run_length_compress(S):
    res = [[S[0], 1]]
    for c in S[1:]:
        if c == res[-1][0]:
            res[-1][1] += 1
        else:
            res.append([c, 1])
    return res def run_length_compress(S):
    res = [[S[0], 1]]
    for c in S[1:]:
        if c == res[-1][0]:
            res[-1][1] += 1
        else:
            res.append([c, 1])
    return res run_length_compress N = len(S) len(S) N tail = T[0][1], T[-1][1] T[-1][1] tail ans = sum(l // 2 for _, l in T) * K sum(l // 2 for _, l in T) * K ans head, tail = T[0][1], T[-1][1] T[0][1] head
def run_length_compress(S):
    res = [[S[0], 1]]
    for c in S[1:]:
        if c == res[-1][0]:
            res[-1][1] += 1
        else:
            res.append([c, 1])
    return res


S = input()
N = len(S)
K = int(input())
T = run_length_compress(S)
if T[0][1] == N:
    print(N * K // 2)
    exit()
ans = sum(l // 2 for _, l in T) * K
if T[0][0] == T[-1][0]:
    head, tail = T[0][1], T[-1][1]
    ans += ((head + tail) // 2 - head // 2 - tail // 2) * (K - 1)
print(ans)
