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

if len(set(S)) == 1:
    print(L*K // 2)
    exit()

def n_changes(s):
    sc = s.copy()
    count = 0
    for i in range(1, len(sc)):
        if sc[i] == sc[i-1]:
            sc[i] = "X"
            count += 1
    return count

print(n_changes(S) + (K-1) * (n_changes(2*S) - n_changes(S))) S = list(input()) S list(input()) list input() input K = int(input()) K int(input()) int input() input L = len(S) L len(S) len S if len(set(S)) == 1:
    print(L*K // 2)
    exit() len(set(S)) == 1 len(set(S)) len set(S) set S 1 print(L*K // 2) print L*K // 2 L*K L K 2 exit() exit def n_changes(s):
    sc = s.copy()
    count = 0
    for i in range(1, len(sc)):
        if sc[i] == sc[i-1]:
            sc[i] = "X"
            count += 1
    return count n_changes sc = s.copy() sc s.copy() s.copy s copy count = 0 count 0 for i in range(1, len(sc)):
        if sc[i] == sc[i-1]:
            sc[i] = "X"
            count += 1
     i range(1, len(sc)) range 1 len(sc) len sc if sc[i] == sc[i-1]:
            sc[i] = "X"
            count += 1
     sc[i] == sc[i-1] sc[i] sc i sc[i-1] sc i-1 i 1 sc[i] = "X" sc[i] sc i "X" count += 1 count 1 return count count s s print(n_changes(S) + (K-1) * (n_changes(2*S) - n_changes(S))) print n_changes(S) + (K-1) * (n_changes(2*S) - n_changes(S)) n_changes(S) n_changes S (K-1) * (n_changes(2*S) - n_changes(S)) K-1 K 1 n_changes(2*S) - n_changes(S) n_changes(2*S) n_changes 2*S 2 S n_changes(S) n_changes S S = list(input()) list(input()) S L = len(S) len(S) L K = int(input()) int(input()) K def n_changes(s):
    sc = s.copy()
    count = 0
    for i in range(1, len(sc)):
        if sc[i] == sc[i-1]:
            sc[i] = "X"
            count += 1
    return count def n_changes(s):
    sc = s.copy()
    count = 0
    for i in range(1, len(sc)):
        if sc[i] == sc[i-1]:
            sc[i] = "X"
            count += 1
    return count n_changes
S = list(input())
K = int(input())
L = len(S)

if len(set(S)) == 1:
    print(L*K // 2)
    exit()

def n_changes(s):
    sc = s.copy()
    count = 0
    for i in range(1, len(sc)):
        if sc[i] == sc[i-1]:
            sc[i] = "X"
            count += 1
    return count

print(n_changes(S) + (K-1) * (n_changes(2*S) - n_changes(S)))
