import numpy as np
S = input()
K = int(input())
seq = []
init = 1
def seq_count(strings, lst):
    init = 1
    for i in range(len(strings)-1):
        if strings[i] == strings[i+1]:
            init += 1
        else:
            lst.append(init)
            init = 1
    lst.append(init)
seq_count(S, seq)
if S[0] != S[-1]:
    array = np.array(seq)
    ans = array // 2
    print(int(np.sum(ans))*K) 
else:
    seq2 = seq[1:-1]
    array = np.array(seq2)
    part_ans = array // 2
    if len(seq) > 1:
        print(int(np.sum(part_ans))*K+((seq[0]+seq[-1])//2)*(K-1)+(seq[0]//2)+(seq[-1]//2))
    else:
        print((seq[0]*K)//2) import numpy as np numpy S = input() S input() input K = int(input()) K int(input()) int input() input seq = [] seq [] init = 1 init 1 def seq_count(strings, lst):
    init = 1
    for i in range(len(strings)-1):
        if strings[i] == strings[i+1]:
            init += 1
        else:
            lst.append(init)
            init = 1
    lst.append(init) seq_count init = 1 init 1 for i in range(len(strings)-1):
        if strings[i] == strings[i+1]:
            init += 1
        else:
            lst.append(init)
            init = 1
     i range(len(strings)-1) range len(strings)-1 len(strings) len strings 1 if strings[i] == strings[i+1]:
            init += 1
        else:
            lst.append(init)
            init = 1
     strings[i] == strings[i+1] strings[i] strings i strings[i+1] strings i+1 i 1 init += 1 init 1 lst.append(init) lst.append lst append init init = 1 init 1 lst.append(init) lst.append lst append init strings strings lst lst seq_count(S, seq) seq_count S seq if S[0] != S[-1]:
    array = np.array(seq)
    ans = array // 2
    print(int(np.sum(ans))*K) 
else:
    seq2 = seq[1:-1]
    array = np.array(seq2)
    part_ans = array // 2
    if len(seq) > 1:
        print(int(np.sum(part_ans))*K+((seq[0]+seq[-1])//2)*(K-1)+(seq[0]//2)+(seq[-1]//2))
    else:
        print((seq[0]*K)//2) S[0] != S[-1] S[0] S 0 S[-1] S -1 array = np.array(seq) array np.array(seq) np.array np array seq ans = array // 2 ans array // 2 array 2 print(int(np.sum(ans))*K) print int(np.sum(ans))*K int(np.sum(ans)) int np.sum(ans) np.sum np sum ans K seq2 = seq[1:-1] seq2 seq[1:-1] seq 1:-1 1 -1 array = np.array(seq2) array np.array(seq2) np.array np array seq2 part_ans = array // 2 part_ans array // 2 array 2 if len(seq) > 1:
        print(int(np.sum(part_ans))*K+((seq[0]+seq[-1])//2)*(K-1)+(seq[0]//2)+(seq[-1]//2))
    else:
        print((seq[0]*K)//2) len(seq) > 1 len(seq) len seq 1 print(int(np.sum(part_ans))*K+((seq[0]+seq[-1])//2)*(K-1)+(seq[0]//2)+(seq[-1]//2)) print int(np.sum(part_ans))*K+((seq[0]+seq[-1])//2)*(K-1)+(seq[0]//2)+(seq[-1]//2) int(np.sum(part_ans))*K+((seq[0]+seq[-1])//2)*(K-1)+(seq[0]//2) int(np.sum(part_ans))*K+((seq[0]+seq[-1])//2)*(K-1) int(np.sum(part_ans))*K int(np.sum(part_ans)) int np.sum(part_ans) np.sum np sum part_ans K ((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[0] seq 0 2 seq[-1]//2 seq[-1] seq -1 2 print((seq[0]*K)//2) print (seq[0]*K)//2 seq[0]*K seq[0] seq 0 K 2 S = input() input() S part_ans = array // 2 array // 2 part_ans seq = [] [] seq init = 1 1 init array = np.array(seq) np.array(seq) array array = np.array(seq2) np.array(seq2) array ans = array // 2 array // 2 ans def seq_count(strings, lst):
    init = 1
    for i in range(len(strings)-1):
        if strings[i] == strings[i+1]:
            init += 1
        else:
            lst.append(init)
            init = 1
    lst.append(init) def seq_count(strings, lst):
    init = 1
    for i in range(len(strings)-1):
        if strings[i] == strings[i+1]:
            init += 1
        else:
            lst.append(init)
            init = 1
    lst.append(init) seq_count seq2 = seq[1:-1] seq[1:-1] seq2 K = int(input()) int(input()) K
import numpy as np
S = input()
K = int(input())
seq = []
init = 1
def seq_count(strings, lst):
    init = 1
    for i in range(len(strings)-1):
        if strings[i] == strings[i+1]:
            init += 1
        else:
            lst.append(init)
            init = 1
    lst.append(init)
seq_count(S, seq)
if S[0] != S[-1]:
    array = np.array(seq)
    ans = array // 2
    print(int(np.sum(ans))*K) 
else:
    seq2 = seq[1:-1]
    array = np.array(seq2)
    part_ans = array // 2
    if len(seq) > 1:
        print(int(np.sum(part_ans))*K+((seq[0]+seq[-1])//2)*(K-1)+(seq[0]//2)+(seq[-1]//2))
    else:
        print((seq[0]*K)//2)