# A - Connection and Disconnection
S = input()
K = int(input())
S = S + '1'# 番兵

# 連続する文字数をカウント
cnt = []
conti = 1
for i in range(1,len(S)):
    if S[i-1] == S[i]:
        conti += 1
    else:
        cnt.append(conti)
        conti = 1
        
# 最初と最後の文字が同じときの補正値
comp = 0
if S[0] == S[-2]:
    # 奇数個 + 奇数個のとき
    if cnt[0]%2 == 1 and cnt[-1]%2 == 1:
        comp = K - 1
    # S =aaa などのとき
    if len(set(S[:-1])) == 1 and len(S[:-1])%2 == 1:
        comp = K // 2
        
ans = [a//2 for a in cnt if a >= 2]
ans = sum(ans)*K + comp
print(ans)         S = input() S input() input K = int(input()) K int(input()) int input() input S = S + '1' S S + '1' S '1' cnt = [] cnt [] conti = 1 conti 1 for i in range(1,len(S)):
    if S[i-1] == S[i]:
        conti += 1
    else:
        cnt.append(conti)
        conti = 1
        
# 最初と最後の文字が同じときの補正値 i range(1,len(S)) range 1 len(S) len S if S[i-1] == S[i]:
        conti += 1
    else:
        cnt.append(conti)
        conti = 1
        
# 最初と最後の文字が同じときの補正値 S[i-1] == S[i] S[i-1] S i-1 i 1 S[i] S i conti += 1 conti 1 cnt.append(conti) cnt.append cnt append conti conti = 1 conti 1 comp = 0 comp 0 if S[0] == S[-2]:
    # 奇数個 + 奇数個のとき
    if cnt[0]%2 == 1 and cnt[-1]%2 == 1:
        comp = K - 1
    # S =aaa などのとき
    if len(set(S[:-1])) == 1 and len(S[:-1])%2 == 1:
        comp = K // 2
         S[0] == S[-2] S[0] S 0 S[-2] S -2 if cnt[0]%2 == 1 and cnt[-1]%2 == 1:
        comp = K - 1
    # S =aaa などのとき
     cnt[0]%2 == 1 and cnt[-1]%2 == 1 cnt[0]%2 == 1 cnt[0]%2 cnt[0] cnt 0 2 1 cnt[-1]%2 == 1 cnt[-1]%2 cnt[-1] cnt -1 2 1 comp = K - 1 comp K - 1 K 1 if len(set(S[:-1])) == 1 and len(S[:-1])%2 == 1:
        comp = K // 2
         len(set(S[:-1])) == 1 and len(S[:-1])%2 == 1 len(set(S[:-1])) == 1 len(set(S[:-1])) len set(S[:-1]) set S[:-1] S :-1 -1 1 len(S[:-1])%2 == 1 len(S[:-1])%2 len(S[:-1]) len S[:-1] S :-1 -1 2 1 comp = K // 2 comp K // 2 K 2 a//2 for a in cnt if a >= 2 for a in cnt if a >= 2 a cnt a >= 2 a 2 if a >= 2 a//2 a 2 ans = [a//2 for a in cnt if a >= 2] ans [a//2 for a in cnt if a >= 2] ans = sum(ans)*K + comp ans sum(ans)*K + comp sum(ans)*K sum(ans) sum ans K comp print(ans) print ans conti += 1 1 conti S = S + '1' S + '1' S K = int(input()) int(input()) K comp = K - 1 K - 1 comp comp = K // 2 K // 2 comp ans = [a//2 for a in cnt if a >= 2] [a//2 for a in cnt if a >= 2] ans cnt = [] [] cnt conti = 1 1 conti S = input() input() S ans = sum(ans)*K + comp sum(ans)*K + comp ans conti = 1 1 conti comp = 0 0 comp
# A - Connection and Disconnection
S = input()
K = int(input())
S = S + '1'# 番兵

# 連続する文字数をカウント
cnt = []
conti = 1
for i in range(1,len(S)):
    if S[i-1] == S[i]:
        conti += 1
    else:
        cnt.append(conti)
        conti = 1
        
# 最初と最後の文字が同じときの補正値
comp = 0
if S[0] == S[-2]:
    # 奇数個 + 奇数個のとき
    if cnt[0]%2 == 1 and cnt[-1]%2 == 1:
        comp = K - 1
    # S =aaa などのとき
    if len(set(S[:-1])) == 1 and len(S[:-1])%2 == 1:
        comp = K // 2
        
ans = [a//2 for a in cnt if a >= 2]
ans = sum(ans)*K + comp
print(ans)        