S = input()
K = int(input())
cot = 0
before = ""
seq = []


for i in range(len(S)):
    c = S[i]
    if cot == 0:
        cot += 1
        before =c
    else:
        if c == before:
            cot += 1
        else:
            before = c
            seq.append(cot)
            cot = 1

seq.append(cot)
ans = 0
for temp in seq: #素の状態で連続してる文字列
    ans +=temp//2
ans *= K
if S[0] == S[-1]: #頭と尾で一緒→つなげたときに長い連続区間が発生
    ans += (seq[0] + seq[-1]) //2 * (K - 1) - (seq[0] //2 + seq[-1]//2 )* (K - 1)
if len(seq) == 1:
    ans = min(ans,seq[0] * K //2)
print(ans) S = input() S input() input K = int(input()) K int(input()) int input() input cot = 0 cot 0 before = "" before "" seq = [] seq [] for i in range(len(S)):
    c = S[i]
    if cot == 0:
        cot += 1
        before =c
    else:
        if c == before:
            cot += 1
        else:
            before = c
            seq.append(cot)
            cot = 1 i range(len(S)) range len(S) len S c = S[i] c S[i] S i if cot == 0:
        cot += 1
        before =c
    else:
        if c == before:
            cot += 1
        else:
            before = c
            seq.append(cot)
            cot = 1 cot == 0 cot 0 cot += 1 cot 1 before =c before c if c == before:
            cot += 1
        else:
            before = c
            seq.append(cot)
            cot = 1 c == before c before cot += 1 cot 1 before = c before c seq.append(cot) seq.append seq append cot cot = 1 cot 1 seq.append(cot) seq.append seq append cot ans = 0 ans 0 for temp in seq: #素の状態で連続してる文字列
    ans +=temp//2 temp seq ans +=temp//2 ans temp//2 temp 2 ans *= K ans K if S[0] == S[-1]: #頭と尾で一緒→つなげたときに長い連続区間が発生
    ans += (seq[0] + seq[-1]) //2 * (K - 1) - (seq[0] //2 + seq[-1]//2 )* (K - 1) S[0] == S[-1] S[0] S 0 S[-1] S -1 ans += (seq[0] + seq[-1]) //2 * (K - 1) - (seq[0] //2 + seq[-1]//2 )* (K - 1) ans (seq[0] + seq[-1]) //2 * (K - 1) - (seq[0] //2 + seq[-1]//2 )* (K - 1) (seq[0] + seq[-1]) //2 * (K - 1) (seq[0] + seq[-1]) //2 seq[0] + seq[-1] seq[0] seq 0 seq[-1] seq -1 2 K - 1 K 1 (seq[0] //2 + seq[-1]//2 )* (K - 1) seq[0] //2 + seq[-1]//2 seq[0] //2 seq[0] seq 0 2 seq[-1]//2 seq[-1] seq -1 2 K - 1 K 1 if len(seq) == 1:
    ans = min(ans,seq[0] * K //2) len(seq) == 1 len(seq) len seq 1 ans = min(ans,seq[0] * K //2) ans min(ans,seq[0] * K //2) min ans seq[0] * K //2 seq[0] * K seq[0] seq 0 K 2 print(ans) print ans before = "" "" before ans *= K K ans seq = [] [] seq cot += 1 1 cot S = input() input() S K = int(input()) int(input()) K before = c c before cot += 1 1 cot cot = 1 1 cot cot = 0 0 cot before =c c before ans = 0 0 ans ans = min(ans,seq[0] * K //2) min(ans,seq[0] * K //2) ans ans +=temp//2 temp//2 ans c = S[i] S[i] c ans += (seq[0] + seq[-1]) //2 * (K - 1) - (seq[0] //2 + seq[-1]//2 )* (K - 1) (seq[0] + seq[-1]) //2 * (K - 1) - (seq[0] //2 + seq[-1]//2 )* (K - 1) ans
S = input()
K = int(input())
cot = 0
before = ""
seq = []


for i in range(len(S)):
    c = S[i]
    if cot == 0:
        cot += 1
        before =c
    else:
        if c == before:
            cot += 1
        else:
            before = c
            seq.append(cot)
            cot = 1

seq.append(cot)
ans = 0
for temp in seq: #素の状態で連続してる文字列
    ans +=temp//2
ans *= K
if S[0] == S[-1]: #頭と尾で一緒→つなげたときに長い連続区間が発生
    ans += (seq[0] + seq[-1]) //2 * (K - 1) - (seq[0] //2 + seq[-1]//2 )* (K - 1)
if len(seq) == 1:
    ans = min(ans,seq[0] * K //2)
print(ans)