from itertools import groupby

S = input()
K = int(input())
grp = [[k, len(list(g))] for k, g in groupby(S)]  # grp[文字][個数]
if len(grp) == 1:
    print(grp[0][1] * K // 2)
else:
    head = grp[0][1]
    tail = grp[-1][1]
    body_sum = 0
    for g in grp[1:len(grp) - 1]:
        body_sum += g[1] // 2 * K
    if grp[0][0] == grp[-1][0]:
        print(head // 2 + tail // 2 + (head + tail) // 2 * (K - 1) + body_sum)
    else:
        print(head // 2 * K + tail // 2 * K + body_sum) from itertools import groupby S = input() S input() input K = int(input()) K int(input()) int input() input [k, len(list(g))] for k, g in groupby(S) for k, g in groupby(S) k g groupby(S) groupby S for k, g in groupby(S) [k, len(list(g))] k len(list(g)) len list(g) list g grp = [[k, len(list(g))] for k, g in groupby(S)] grp [[k, len(list(g))] for k, g in groupby(S)] if len(grp) == 1:
    print(grp[0][1] * K // 2)
else:
    head = grp[0][1]
    tail = grp[-1][1]
    body_sum = 0
    for g in grp[1:len(grp) - 1]:
        body_sum += g[1] // 2 * K
    if grp[0][0] == grp[-1][0]:
        print(head // 2 + tail // 2 + (head + tail) // 2 * (K - 1) + body_sum)
    else:
        print(head // 2 * K + tail // 2 * K + body_sum) len(grp) == 1 len(grp) len grp 1 print(grp[0][1] * K // 2) print grp[0][1] * K // 2 grp[0][1] * K grp[0][1] [0] grp 0 1 K 2 head = grp[0][1] head grp[0][1] [0] grp 0 1 tail = grp[-1][1] tail grp[-1][1] [-1] grp -1 1 body_sum = 0 body_sum 0 for g in grp[1:len(grp) - 1]:
        body_sum += g[1] // 2 * K
     g grp[1:len(grp) - 1] grp 1:len(grp) - 1 1 len(grp) - 1 len(grp) len grp 1 body_sum += g[1] // 2 * K body_sum g[1] // 2 * K g[1] // 2 g[1] g 1 2 K if grp[0][0] == grp[-1][0]:
        print(head // 2 + tail // 2 + (head + tail) // 2 * (K - 1) + body_sum)
    else:
        print(head // 2 * K + tail // 2 * K + body_sum) grp[0][0] == grp[-1][0] grp[0][0] [0] grp 0 0 grp[-1][0] [-1] grp -1 0 print(head // 2 + tail // 2 + (head + tail) // 2 * (K - 1) + body_sum) print head // 2 + tail // 2 + (head + tail) // 2 * (K - 1) + body_sum head // 2 + tail // 2 + (head + tail) // 2 * (K - 1) head // 2 + tail // 2 head // 2 head 2 tail // 2 tail 2 (head + tail) // 2 * (K - 1) (head + tail) // 2 head + tail head tail 2 K - 1 K 1 body_sum print(head // 2 * K + tail // 2 * K + body_sum) print head // 2 * K + tail // 2 * K + body_sum head // 2 * K + tail // 2 * K head // 2 * K head // 2 head 2 K tail // 2 * K tail // 2 tail 2 K body_sum tail = grp[-1][1] grp[-1][1] tail body_sum = 0 0 body_sum body_sum += g[1] // 2 * K g[1] // 2 * K body_sum grp = [[k, len(list(g))] for k, g in groupby(S)] [[k, len(list(g))] for k, g in groupby(S)] grp S = input() input() S K = int(input()) int(input()) K head = grp[0][1] grp[0][1] head
from itertools import groupby

S = input()
K = int(input())
grp = [[k, len(list(g))] for k, g in groupby(S)]  # grp[文字][個数]
if len(grp) == 1:
    print(grp[0][1] * K // 2)
else:
    head = grp[0][1]
    tail = grp[-1][1]
    body_sum = 0
    for g in grp[1:len(grp) - 1]:
        body_sum += g[1] // 2 * K
    if grp[0][0] == grp[-1][0]:
        print(head // 2 + tail // 2 + (head + tail) // 2 * (K - 1) + body_sum)
    else:
        print(head // 2 * K + tail // 2 * K + body_sum)
