S = list(input())
N = len(S)
K = int(input())
if len(set(S)) == 1:
    print((N*K)//2)
    exit()

cnt = 0
tmpS = S*1
for i in range(N-1):
    if tmpS[i] == tmpS[i+1]:
        cnt += 1
        tmpS[i+1] = '!'

if S[N-1] == S[0]:
    a = 1
    while a <= N-1 and S[a-1] == S[a]:
        a += 1
    b = 1
    while b <= N-1 and S[N-b] == S[N-b-1]:
        b += 1
    print(cnt*K-(a//2+b//2-(a+b)//2)*(K-1))
else:
    print(cnt*K) S = list(input()) S list(input()) list input() input N = len(S) N len(S) len S K = int(input()) K int(input()) int input() input if len(set(S)) == 1:
    print((N*K)//2)
    exit() len(set(S)) == 1 len(set(S)) len set(S) set S 1 print((N*K)//2) print (N*K)//2 N*K N K 2 exit() exit cnt = 0 cnt 0 tmpS = S*1 tmpS S*1 S 1 for i in range(N-1):
    if tmpS[i] == tmpS[i+1]:
        cnt += 1
        tmpS[i+1] = '!' i range(N-1) range N-1 N 1 if tmpS[i] == tmpS[i+1]:
        cnt += 1
        tmpS[i+1] = '!' tmpS[i] == tmpS[i+1] tmpS[i] tmpS i tmpS[i+1] tmpS i+1 i 1 cnt += 1 cnt 1 tmpS[i+1] = '!' tmpS[i+1] tmpS i+1 i 1 '!' if S[N-1] == S[0]:
    a = 1
    while a <= N-1 and S[a-1] == S[a]:
        a += 1
    b = 1
    while b <= N-1 and S[N-b] == S[N-b-1]:
        b += 1
    print(cnt*K-(a//2+b//2-(a+b)//2)*(K-1))
else:
    print(cnt*K) S[N-1] == S[0] S[N-1] S N-1 N 1 S[0] S 0 a = 1 a 1 while a <= N-1 and S[a-1] == S[a]:
        a += 1
     a <= N-1 and S[a-1] == S[a] a <= N-1 a N-1 N 1 S[a-1] == S[a] S[a-1] S a-1 a 1 S[a] S a a += 1 a 1 b = 1 b 1 while b <= N-1 and S[N-b] == S[N-b-1]:
        b += 1
     b <= N-1 and S[N-b] == S[N-b-1] b <= N-1 b N-1 N 1 S[N-b] == S[N-b-1] S[N-b] S N-b N b S[N-b-1] S N-b-1 N-b N b 1 b += 1 b 1 print(cnt*K-(a//2+b//2-(a+b)//2)*(K-1)) print cnt*K-(a//2+b//2-(a+b)//2)*(K-1) cnt*K cnt K (a//2+b//2-(a+b)//2)*(K-1) a//2+b//2-(a+b)//2 a//2+b//2 a//2 a 2 b//2 b 2 (a+b)//2 a+b a b 2 K-1 K 1 print(cnt*K) print cnt*K cnt K N = len(S) len(S) N a += 1 1 a a = 1 1 a cnt += 1 1 cnt S = list(input()) list(input()) S K = int(input()) int(input()) K cnt = 0 0 cnt b = 1 1 b tmpS = S*1 S*1 tmpS b += 1 1 b
S = list(input())
N = len(S)
K = int(input())
if len(set(S)) == 1:
    print((N*K)//2)
    exit()

cnt = 0
tmpS = S*1
for i in range(N-1):
    if tmpS[i] == tmpS[i+1]:
        cnt += 1
        tmpS[i+1] = '!'

if S[N-1] == S[0]:
    a = 1
    while a <= N-1 and S[a-1] == S[a]:
        a += 1
    b = 1
    while b <= N-1 and S[N-b] == S[N-b-1]:
        b += 1
    print(cnt*K-(a//2+b//2-(a+b)//2)*(K-1))
else:
    print(cnt*K)