from itertools import groupby

# RUN LENGTH ENCODING str -> tuple
def run_length_encode(S: str):
    """
    'AAAABBBCCDAABBB' -> [('A', 4), ('B', 3), ('C', 2), ('D', 1), ('A', 2), ('B', 3)]
    """
    grouped = groupby(S)
    res = []
    for k, v in grouped:
        res.append((k, len(list(v))))
    return res


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

if len(set(list(S))) == 1:
    print((len(S) * K) // 2)
else:
    rle = run_length_encode(S)
    cnt = 0
    for w, length in rle:
        if length > 1:
            cnt += length // 2

    ans = cnt * K
    if S[0] == S[-1]:
        a = rle[0][1]
        b = rle[-1][1]
        ans -= (a // 2 + b // 2 - (a + b) // 2) * (K - 1)
    print(ans)

 from itertools import groupby def run_length_encode(S: str):
    """
    'AAAABBBCCDAABBB' -> [('A', 4), ('B', 3), ('C', 2), ('D', 1), ('A', 2), ('B', 3)]
    """
    grouped = groupby(S)
    res = []
    for k, v in grouped:
        res.append((k, len(list(v))))
    return res run_length_encode """
    'AAAABBBCCDAABBB' -> [('A', 4), ('B', 3), ('C', 2), ('D', 1), ('A', 2), ('B', 3)]
    """ grouped = groupby(S) grouped groupby(S) groupby S res = [] res [] for k, v in grouped:
        res.append((k, len(list(v))))
     k v grouped res.append((k, len(list(v)))) res.append res append (k, len(list(v))) k len(list(v)) len list(v) list v return res res S: str S S = input() S input() input K = int(input()) K int(input()) int input() input if len(set(list(S))) == 1:
    print((len(S) * K) // 2)
else:
    rle = run_length_encode(S)
    cnt = 0
    for w, length in rle:
        if length > 1:
            cnt += length // 2

    ans = cnt * K
    if S[0] == S[-1]:
        a = rle[0][1]
        b = rle[-1][1]
        ans -= (a // 2 + b // 2 - (a + b) // 2) * (K - 1)
    print(ans) len(set(list(S))) == 1 len(set(list(S))) len set(list(S)) set list(S) list S 1 print((len(S) * K) // 2) print (len(S) * K) // 2 len(S) * K len(S) len S K 2 rle = run_length_encode(S) rle run_length_encode(S) run_length_encode S cnt = 0 cnt 0 for w, length in rle:
        if length > 1:
            cnt += length // 2

     w length rle if length > 1:
            cnt += length // 2

     length > 1 length 1 cnt += length // 2 cnt length // 2 length 2 ans = cnt * K ans cnt * K cnt K if S[0] == S[-1]:
        a = rle[0][1]
        b = rle[-1][1]
        ans -= (a // 2 + b // 2 - (a + b) // 2) * (K - 1)
     S[0] == S[-1] S[0] S 0 S[-1] S -1 a = rle[0][1] a rle[0][1] [0] rle 0 1 b = rle[-1][1] b rle[-1][1] [-1] rle -1 1 ans -= (a // 2 + b // 2 - (a + b) // 2) * (K - 1) ans (a // 2 + b // 2 - (a + b) // 2) * (K - 1) a // 2 + b // 2 - (a + b) // 2 a // 2 + b // 2 a // 2 a 2 b // 2 b 2 (a + b) // 2 a + b a b 2 K - 1 K 1 print(ans) print ans ans = cnt * K cnt * K ans cnt = 0 0 cnt b = rle[-1][1] rle[-1][1] b cnt += length // 2 length // 2 cnt ans -= (a // 2 + b // 2 - (a + b) // 2) * (K - 1) (a // 2 + b // 2 - (a + b) // 2) * (K - 1) ans S = input() input() S K = int(input()) int(input()) K rle = run_length_encode(S) run_length_encode(S) rle def run_length_encode(S: str):
    """
    'AAAABBBCCDAABBB' -> [('A', 4), ('B', 3), ('C', 2), ('D', 1), ('A', 2), ('B', 3)]
    """
    grouped = groupby(S)
    res = []
    for k, v in grouped:
        res.append((k, len(list(v))))
    return res def run_length_encode(S: str):
    """
    'AAAABBBCCDAABBB' -> [('A', 4), ('B', 3), ('C', 2), ('D', 1), ('A', 2), ('B', 3)]
    """
    grouped = groupby(S)
    res = []
    for k, v in grouped:
        res.append((k, len(list(v))))
    return res run_length_encode a = rle[0][1] rle[0][1] a
from itertools import groupby

# RUN LENGTH ENCODING str -> tuple
def run_length_encode(S: str):
    """
    'AAAABBBCCDAABBB' -> [('A', 4), ('B', 3), ('C', 2), ('D', 1), ('A', 2), ('B', 3)]
    """
    grouped = groupby(S)
    res = []
    for k, v in grouped:
        res.append((k, len(list(v))))
    return res


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

if len(set(list(S))) == 1:
    print((len(S) * K) // 2)
else:
    rle = run_length_encode(S)
    cnt = 0
    for w, length in rle:
        if length > 1:
            cnt += length // 2

    ans = cnt * K
    if S[0] == S[-1]:
        a = rle[0][1]
        b = rle[-1][1]
        ans -= (a // 2 + b // 2 - (a + b) // 2) * (K - 1)
    print(ans)


