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 solve():
    S = input()
    N = len(S)
    K = int(input())
    T = run_length_compress(S)
    if T[0][1] == N:
        return N * K // 2
    ans = sum(l // 2 for _, l in T) * K
    if T[0][0] == T[-1][0]:
        head_cnt, tail_cnt = T[0][1], T[-1][1]
        tmp = (head_cnt + tail_cnt) // 2 - head_cnt // 2 - tail_cnt // 2
        ans += tmp * (K - 1)
    return ans


print(solve()) 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 def solve():
    S = input()
    N = len(S)
    K = int(input())
    T = run_length_compress(S)
    if T[0][1] == N:
        return N * K // 2
    ans = sum(l // 2 for _, l in T) * K
    if T[0][0] == T[-1][0]:
        head_cnt, tail_cnt = T[0][1], T[-1][1]
        tmp = (head_cnt + tail_cnt) // 2 - head_cnt // 2 - tail_cnt // 2
        ans += tmp * (K - 1)
    return ans solve 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:
        return N * K // 2
     T[0][1] == N T[0][1] [0] T 0 1 N return N * K // 2 N * K // 2 N * K N K 2 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_cnt, tail_cnt = T[0][1], T[-1][1]
        tmp = (head_cnt + tail_cnt) // 2 - head_cnt // 2 - tail_cnt // 2
        ans += tmp * (K - 1)
     T[0][0] == T[-1][0] T[0][0] [0] T 0 0 T[-1][0] [-1] T -1 0 head_cnt, tail_cnt = T[0][1], T[-1][1] head_cnt T[0][1] [0] T 0 1 tail_cnt T[-1][1] [-1] T -1 1 tmp = (head_cnt + tail_cnt) // 2 - head_cnt // 2 - tail_cnt // 2 tmp (head_cnt + tail_cnt) // 2 - head_cnt // 2 - tail_cnt // 2 (head_cnt + tail_cnt) // 2 - head_cnt // 2 (head_cnt + tail_cnt) // 2 head_cnt + tail_cnt head_cnt tail_cnt 2 head_cnt // 2 head_cnt 2 tail_cnt // 2 tail_cnt 2 ans += tmp * (K - 1) ans tmp * (K - 1) tmp K - 1 K 1 return ans ans print(solve()) print solve() solve def solve():
    S = input()
    N = len(S)
    K = int(input())
    T = run_length_compress(S)
    if T[0][1] == N:
        return N * K // 2
    ans = sum(l // 2 for _, l in T) * K
    if T[0][0] == T[-1][0]:
        head_cnt, tail_cnt = T[0][1], T[-1][1]
        tmp = (head_cnt + tail_cnt) // 2 - head_cnt // 2 - tail_cnt // 2
        ans += tmp * (K - 1)
    return ans def solve():
    S = input()
    N = len(S)
    K = int(input())
    T = run_length_compress(S)
    if T[0][1] == N:
        return N * K // 2
    ans = sum(l // 2 for _, l in T) * K
    if T[0][0] == T[-1][0]:
        head_cnt, tail_cnt = T[0][1], T[-1][1]
        tmp = (head_cnt + tail_cnt) // 2 - head_cnt // 2 - tail_cnt // 2
        ans += tmp * (K - 1)
    return ans solve 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
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 solve():
    S = input()
    N = len(S)
    K = int(input())
    T = run_length_compress(S)
    if T[0][1] == N:
        return N * K // 2
    ans = sum(l // 2 for _, l in T) * K
    if T[0][0] == T[-1][0]:
        head_cnt, tail_cnt = T[0][1], T[-1][1]
        tmp = (head_cnt + tail_cnt) // 2 - head_cnt // 2 - tail_cnt // 2
        ans += tmp * (K - 1)
    return ans


print(solve())
