S = input()
K = int(input())

if S==S[0]*len(S):
    print(len(S)*K//2)
    exit()
    
rle = []
cnt = 1

for i in range(len(S)-1):
    if S[i]!=S[i+1]:
        rle.append((S[i], cnt))
        cnt = 1
    else:
        cnt += 1

rle.append((S[-1], cnt))
#print(rle)

if rle[0][0]==rle[-1][0]:
    ans = rle[0][1]//2+rle[-1][1]//2
    
    for i in range(1, len(rle)-1):
        ans += rle[i][1]//2*K
    
    ans += (rle[0][1]+rle[-1][1])//2*(K-1)
else:
    ans = 0
    
    for i in range(len(rle)):
        ans += rle[i][1]//2*K
    
print(ans) S = input() S input() input K = int(input()) K int(input()) int input() input if S==S[0]*len(S):
    print(len(S)*K//2)
    exit()
     S==S[0]*len(S) S S[0]*len(S) S[0] S 0 len(S) len S print(len(S)*K//2) print len(S)*K//2 len(S)*K len(S) len S K 2 exit() exit rle = [] rle [] cnt = 1 cnt 1 for i in range(len(S)-1):
    if S[i]!=S[i+1]:
        rle.append((S[i], cnt))
        cnt = 1
    else:
        cnt += 1 i range(len(S)-1) range len(S)-1 len(S) len S 1 if S[i]!=S[i+1]:
        rle.append((S[i], cnt))
        cnt = 1
    else:
        cnt += 1 S[i]!=S[i+1] S[i] S i S[i+1] S i+1 i 1 rle.append((S[i], cnt)) rle.append rle append (S[i], cnt) S[i] S i cnt cnt = 1 cnt 1 cnt += 1 cnt 1 rle.append((S[-1], cnt)) rle.append rle append (S[-1], cnt) S[-1] S -1 cnt if rle[0][0]==rle[-1][0]:
    ans = rle[0][1]//2+rle[-1][1]//2
    
    for i in range(1, len(rle)-1):
        ans += rle[i][1]//2*K
    
    ans += (rle[0][1]+rle[-1][1])//2*(K-1)
else:
    ans = 0
    
    for i in range(len(rle)):
        ans += rle[i][1]//2*K
     rle[0][0]==rle[-1][0] rle[0][0] [0] rle 0 0 rle[-1][0] [-1] rle -1 0 ans = rle[0][1]//2+rle[-1][1]//2 ans rle[0][1]//2+rle[-1][1]//2 rle[0][1]//2 rle[0][1] [0] rle 0 1 2 rle[-1][1]//2 rle[-1][1] [-1] rle -1 1 2 for i in range(1, len(rle)-1):
        ans += rle[i][1]//2*K
    
     i range(1, len(rle)-1) range 1 len(rle)-1 len(rle) len rle 1 ans += rle[i][1]//2*K ans rle[i][1]//2*K rle[i][1]//2 rle[i][1] [i] rle i 1 2 K ans += (rle[0][1]+rle[-1][1])//2*(K-1) ans (rle[0][1]+rle[-1][1])//2*(K-1) (rle[0][1]+rle[-1][1])//2 rle[0][1]+rle[-1][1] rle[0][1] [0] rle 0 1 rle[-1][1] [-1] rle -1 1 2 K-1 K 1 ans = 0 ans 0 for i in range(len(rle)):
        ans += rle[i][1]//2*K
     i range(len(rle)) range len(rle) len rle ans += rle[i][1]//2*K ans rle[i][1]//2*K rle[i][1]//2 rle[i][1] [i] rle i 1 2 K print(ans) print ans S = input() input() S cnt = 1 1 cnt ans += rle[i][1]//2*K rle[i][1]//2*K ans cnt += 1 1 cnt ans = rle[0][1]//2+rle[-1][1]//2 rle[0][1]//2+rle[-1][1]//2 ans ans += rle[i][1]//2*K rle[i][1]//2*K ans ans += (rle[0][1]+rle[-1][1])//2*(K-1) (rle[0][1]+rle[-1][1])//2*(K-1) ans rle = [] [] rle K = int(input()) int(input()) K cnt = 1 1 cnt ans = 0 0 ans
S = input()
K = int(input())

if S==S[0]*len(S):
    print(len(S)*K//2)
    exit()
    
rle = []
cnt = 1

for i in range(len(S)-1):
    if S[i]!=S[i+1]:
        rle.append((S[i], cnt))
        cnt = 1
    else:
        cnt += 1

rle.append((S[-1], cnt))
#print(rle)

if rle[0][0]==rle[-1][0]:
    ans = rle[0][1]//2+rle[-1][1]//2
    
    for i in range(1, len(rle)-1):
        ans += rle[i][1]//2*K
    
    ans += (rle[0][1]+rle[-1][1])//2*(K-1)
else:
    ans = 0
    
    for i in range(len(rle)):
        ans += rle[i][1]//2*K
    
print(ans)