S = list(input())
K = int(input())
N = len(S)

C0 = []
cnt = 1
for i in range(1,N):
    if S[i]==S[i-1]:
        cnt+=1
        if i==N-1:
            C0.append(cnt)
    else:
        C0.append(cnt)
        cnt = 1
out0 = 0
for m in C0:
    out0 += m//2

if S[0]!=S[-1]:
    out = out0*K
elif N==1:
    out = K//2
elif len(C0)==1:
    X = C0[0]*K
    out = X//2
else:
    X = (C0[0] + C0[-1])//2
    Y = C0[0]//2 + C0[-1]//2
    out = (out0-Y)*K
    out += X*(K-1)
    out += Y
print(out) S = list(input()) S list(input()) list input() input K = int(input()) K int(input()) int input() input N = len(S) N len(S) len S C0 = [] C0 [] cnt = 1 cnt 1 for i in range(1,N):
    if S[i]==S[i-1]:
        cnt+=1
        if i==N-1:
            C0.append(cnt)
    else:
        C0.append(cnt)
        cnt = 1 i range(1,N) range 1 N if S[i]==S[i-1]:
        cnt+=1
        if i==N-1:
            C0.append(cnt)
    else:
        C0.append(cnt)
        cnt = 1 S[i]==S[i-1] S[i] S i S[i-1] S i-1 i 1 cnt+=1 cnt 1 if i==N-1:
            C0.append(cnt)
     i==N-1 i N-1 N 1 C0.append(cnt) C0.append C0 append cnt C0.append(cnt) C0.append C0 append cnt cnt = 1 cnt 1 out0 = 0 out0 0 for m in C0:
    out0 += m//2 m C0 out0 += m//2 out0 m//2 m 2 if S[0]!=S[-1]:
    out = out0*K
elif N==1:
    out = K//2
elif len(C0)==1:
    X = C0[0]*K
    out = X//2
else:
    X = (C0[0] + C0[-1])//2
    Y = C0[0]//2 + C0[-1]//2
    out = (out0-Y)*K
    out += X*(K-1)
    out += Y S[0]!=S[-1] S[0] S 0 S[-1] S -1 out = out0*K out out0*K out0 K elif N==1:
    out = K//2 N==1 N 1 out = K//2 out K//2 K 2 elif len(C0)==1:
    X = C0[0]*K
    out = X//2 len(C0)==1 len(C0) len C0 1 X = C0[0]*K X C0[0]*K C0[0] C0 0 K out = X//2 out X//2 X 2 X = (C0[0] + C0[-1])//2 X (C0[0] + C0[-1])//2 C0[0] + C0[-1] C0[0] C0 0 C0[-1] C0 -1 2 Y = C0[0]//2 + C0[-1]//2 Y C0[0]//2 + C0[-1]//2 C0[0]//2 C0[0] C0 0 2 C0[-1]//2 C0[-1] C0 -1 2 out = (out0-Y)*K out (out0-Y)*K out0-Y out0 Y K out += X*(K-1) out X*(K-1) X K-1 K 1 out += Y out Y print(out) print out out = out0*K out0*K out cnt = 1 1 cnt C0 = [] [] C0 out0 = 0 0 out0 out = (out0-Y)*K (out0-Y)*K out Y = C0[0]//2 + C0[-1]//2 C0[0]//2 + C0[-1]//2 Y out += X*(K-1) X*(K-1) out S = list(input()) list(input()) S N = len(S) len(S) N X = (C0[0] + C0[-1])//2 (C0[0] + C0[-1])//2 X cnt+=1 1 cnt out = X//2 X//2 out X = C0[0]*K C0[0]*K X out = K//2 K//2 out K = int(input()) int(input()) K cnt = 1 1 cnt out0 += m//2 m//2 out0 out += Y Y out
S = list(input())
K = int(input())
N = len(S)

C0 = []
cnt = 1
for i in range(1,N):
    if S[i]==S[i-1]:
        cnt+=1
        if i==N-1:
            C0.append(cnt)
    else:
        C0.append(cnt)
        cnt = 1
out0 = 0
for m in C0:
    out0 += m//2

if S[0]!=S[-1]:
    out = out0*K
elif N==1:
    out = K//2
elif len(C0)==1:
    X = C0[0]*K
    out = X//2
else:
    X = (C0[0] + C0[-1])//2
    Y = C0[0]//2 + C0[-1]//2
    out = (out0-Y)*K
    out += X*(K-1)
    out += Y
print(out)