import sys
S=input()
k=int(input())
ans=0
flag=0
left=0
right=0
if S[0]==S[-1]:
    left=1
    for i in range(len(S)-1):
        if S[i+1]==S[0]:
            left+=1
        else:
            break
    if left==len(S):
        print(left*k//2)
        sys.exit()
    right=1
    for i in range(len(S)-1):
        if S[-i-2]==S[0]:
            right+=1
        else:
            break
    
now=""
for i in range(left,len(S)-right):
    if flag==1:
        flag=0
        now=S[i]
        continue
    if now==S[i]:
        ans+=1
        flag=1
    now=S[i]
ans*=k

if S[0]==S[-1]:
    ans+=(left+right)//2*(k-1)
    ans+=left//2+right//2

print(ans) import sys sys S=input() S input() input k=int(input()) k int(input()) int input() input ans=0 ans 0 flag=0 flag 0 left=0 left 0 right=0 right 0 if S[0]==S[-1]:
    left=1
    for i in range(len(S)-1):
        if S[i+1]==S[0]:
            left+=1
        else:
            break
    if left==len(S):
        print(left*k//2)
        sys.exit()
    right=1
    for i in range(len(S)-1):
        if S[-i-2]==S[0]:
            right+=1
        else:
            break
     S[0]==S[-1] S[0] S 0 S[-1] S -1 left=1 left 1 for i in range(len(S)-1):
        if S[i+1]==S[0]:
            left+=1
        else:
            break
     i range(len(S)-1) range len(S)-1 len(S) len S 1 if S[i+1]==S[0]:
            left+=1
        else:
            break
     S[i+1]==S[0] S[i+1] S i+1 i 1 S[0] S 0 left+=1 left 1 break if left==len(S):
        print(left*k//2)
        sys.exit()
     left==len(S) left len(S) len S print(left*k//2) print left*k//2 left*k left k 2 sys.exit() sys.exit sys exit right=1 right 1 for i in range(len(S)-1):
        if S[-i-2]==S[0]:
            right+=1
        else:
            break
     i range(len(S)-1) range len(S)-1 len(S) len S 1 if S[-i-2]==S[0]:
            right+=1
        else:
            break
     S[-i-2]==S[0] S[-i-2] S -i-2 -i i 2 S[0] S 0 right+=1 right 1 break now="" now "" for i in range(left,len(S)-right):
    if flag==1:
        flag=0
        now=S[i]
        continue
    if now==S[i]:
        ans+=1
        flag=1
    now=S[i] i range(left,len(S)-right) range left len(S)-right len(S) len S right if flag==1:
        flag=0
        now=S[i]
        continue
     flag==1 flag 1 flag=0 flag 0 now=S[i] now S[i] S i continue if now==S[i]:
        ans+=1
        flag=1
     now==S[i] now S[i] S i ans+=1 ans 1 flag=1 flag 1 now=S[i] now S[i] S i ans*=k ans k if S[0]==S[-1]:
    ans+=(left+right)//2*(k-1)
    ans+=left//2+right//2 S[0]==S[-1] S[0] S 0 S[-1] S -1 ans+=(left+right)//2*(k-1) ans (left+right)//2*(k-1) (left+right)//2 left+right left right 2 k-1 k 1 ans+=left//2+right//2 ans left//2+right//2 left//2 left 2 right//2 right 2 print(ans) print ans flag=1 1 flag ans+=1 1 ans right=0 0 right now=S[i] S[i] now left=0 0 left ans+=left//2+right//2 left//2+right//2 ans ans=0 0 ans left+=1 1 left now=S[i] S[i] now ans*=k k ans right=1 1 right left=1 1 left right+=1 1 right k=int(input()) int(input()) k flag=0 0 flag S=input() input() S now="" "" now flag=0 0 flag ans+=(left+right)//2*(k-1) (left+right)//2*(k-1) ans
import sys
S=input()
k=int(input())
ans=0
flag=0
left=0
right=0
if S[0]==S[-1]:
    left=1
    for i in range(len(S)-1):
        if S[i+1]==S[0]:
            left+=1
        else:
            break
    if left==len(S):
        print(left*k//2)
        sys.exit()
    right=1
    for i in range(len(S)-1):
        if S[-i-2]==S[0]:
            right+=1
        else:
            break
    
now=""
for i in range(left,len(S)-right):
    if flag==1:
        flag=0
        now=S[i]
        continue
    if now==S[i]:
        ans+=1
        flag=1
    now=S[i]
ans*=k

if S[0]==S[-1]:
    ans+=(left+right)//2*(k-1)
    ans+=left//2+right//2

print(ans)