def cal(S):
    tmp, a, cnt = S[0], 1, 0
    flag = True
    for s in S[1:]:
        if S[0]!=s: flag=False
        if flag: a+=1
        if tmp[-1]==s:
            s = '*'
            cnt += 1
        tmp += s
    return a, cnt


S = input().replace('\n', '')
k = int(input())
ans = 0
if len(list(set(S)))==1:
    ans = len(S)*k//2
else:
    a, cnt = cal(S)
    b, _ = cal(S[::-1])
    ans = cnt*k
    if S[0]==S[-1]:
        ans -= ((a//2)+(b//2)-((a+b)//2))*(k-1)
print(ans) def cal(S):
    tmp, a, cnt = S[0], 1, 0
    flag = True
    for s in S[1:]:
        if S[0]!=s: flag=False
        if flag: a+=1
        if tmp[-1]==s:
            s = '*'
            cnt += 1
        tmp += s
    return a, cnt cal tmp, a, cnt = S[0], 1, 0 tmp S[0] S 0 a 1 cnt 0 flag = True flag True for s in S[1:]:
        if S[0]!=s: flag=False
        if flag: a+=1
        if tmp[-1]==s:
            s = '*'
            cnt += 1
        tmp += s
     s S[1:] S 1: 1 if S[0]!=s: flag=False
         S[0]!=s S[0] S 0 s if flag: a+=1
         flag if tmp[-1]==s:
            s = '*'
            cnt += 1
         tmp[-1]==s tmp[-1] tmp -1 s s = '*' s '*' cnt += 1 cnt 1 tmp += s tmp s return a, cnt return a, cnt a cnt S S S = input().replace('\n', '') S input().replace('\n', '') ().replace () input replace '\n' '' k = int(input()) k int(input()) int input() input ans = 0 ans 0 if len(list(set(S)))==1:
    ans = len(S)*k//2
else:
    a, cnt = cal(S)
    b, _ = cal(S[::-1])
    ans = cnt*k
    if S[0]==S[-1]:
        ans -= ((a//2)+(b//2)-((a+b)//2))*(k-1) len(list(set(S)))==1 len(list(set(S))) len list(set(S)) list set(S) set S 1 ans = len(S)*k//2 ans len(S)*k//2 len(S)*k len(S) len S k 2 a, cnt = cal(S) a cal(S) cal S cnt b, _ = cal(S[::-1]) b cal(S[::-1]) cal S[::-1] S ::-1 -1 _ ans = cnt*k ans cnt*k cnt k if S[0]==S[-1]:
        ans -= ((a//2)+(b//2)-((a+b)//2))*(k-1) S[0]==S[-1] S[0] S 0 S[-1] S -1 ans -= ((a//2)+(b//2)-((a+b)//2))*(k-1) ans ((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(ans) print ans b, _ = cal(S[::-1]) cal(S[::-1]) b ans = cnt*k cnt*k ans ans = 0 0 ans def cal(S):
    tmp, a, cnt = S[0], 1, 0
    flag = True
    for s in S[1:]:
        if S[0]!=s: flag=False
        if flag: a+=1
        if tmp[-1]==s:
            s = '*'
            cnt += 1
        tmp += s
    return a, cnt def cal(S):
    tmp, a, cnt = S[0], 1, 0
    flag = True
    for s in S[1:]:
        if S[0]!=s: flag=False
        if flag: a+=1
        if tmp[-1]==s:
            s = '*'
            cnt += 1
        tmp += s
    return a, cnt cal a, cnt = cal(S) cal(S) a cnt = cal(S) cal(S) cnt ans = len(S)*k//2 len(S)*k//2 ans S = input().replace('\n', '') input().replace('\n', '') S _ = cal(S[::-1]) cal(S[::-1]) _ ans -= ((a//2)+(b//2)-((a+b)//2))*(k-1) ((a//2)+(b//2)-((a+b)//2))*(k-1) ans k = int(input()) int(input()) k
def cal(S):
    tmp, a, cnt = S[0], 1, 0
    flag = True
    for s in S[1:]:
        if S[0]!=s: flag=False
        if flag: a+=1
        if tmp[-1]==s:
            s = '*'
            cnt += 1
        tmp += s
    return a, cnt


S = input().replace('\n', '')
k = int(input())
ans = 0
if len(list(set(S)))==1:
    ans = len(S)*k//2
else:
    a, cnt = cal(S)
    b, _ = cal(S[::-1])
    ans = cnt*k
    if S[0]==S[-1]:
        ans -= ((a//2)+(b//2)-((a+b)//2))*(k-1)
print(ans)