

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    S=list(input())
    K=I()
    
    S3=S*3
    S2=S*2
    
    ans=0
    
    N=len(S)
    
    flag=0
    if S.count(S[0])==N:
        flag=1
    
    if N==1 or flag:
        ans=(K*N)//2
    else:
        ans2=0
        for i in range(N*2-1):
            if S2[i]==S2[i+1]:
                S2[i+1]="#"
                ans2+=1
                
        ans3=0
        for i in range(N*3-1):
            if S3[i]==S3[i+1]:
                S3[i+1]="#"
                ans3+=1
                
        ansd=ans3-ans2
        if K==2:
            ans=ans2
        else:
            ans=ans2+(K-2)*ansd

        
    print(ans)

main() def I(): return int(input()) I def MI(): return map(int, input().split()) MI def LI(): return list(map(int, input().split())) LI def main():
    mod=10**9+7
    S=list(input())
    K=I()
    
    S3=S*3
    S2=S*2
    
    ans=0
    
    N=len(S)
    
    flag=0
    if S.count(S[0])==N:
        flag=1
    
    if N==1 or flag:
        ans=(K*N)//2
    else:
        ans2=0
        for i in range(N*2-1):
            if S2[i]==S2[i+1]:
                S2[i+1]="#"
                ans2+=1
                
        ans3=0
        for i in range(N*3-1):
            if S3[i]==S3[i+1]:
                S3[i+1]="#"
                ans3+=1
                
        ansd=ans3-ans2
        if K==2:
            ans=ans2
        else:
            ans=ans2+(K-2)*ansd

        
    print(ans) main mod=10**9+7 mod 10**9+7 10**9 10 9 7 S=list(input()) S list(input()) list input() input K=I() K I() I S3=S*3 S3 S*3 S 3 S2=S*2 S2 S*2 S 2 ans=0 ans 0 N=len(S) N len(S) len S flag=0 flag 0 if S.count(S[0])==N:
        flag=1
    
     S.count(S[0])==N S.count(S[0]) S.count S count S[0] S 0 N flag=1 flag 1 if N==1 or flag:
        ans=(K*N)//2
    else:
        ans2=0
        for i in range(N*2-1):
            if S2[i]==S2[i+1]:
                S2[i+1]="#"
                ans2+=1
                
        ans3=0
        for i in range(N*3-1):
            if S3[i]==S3[i+1]:
                S3[i+1]="#"
                ans3+=1
                
        ansd=ans3-ans2
        if K==2:
            ans=ans2
        else:
            ans=ans2+(K-2)*ansd

        
     N==1 or flag N==1 N 1 flag ans=(K*N)//2 ans (K*N)//2 K*N K N 2 ans2=0 ans2 0 for i in range(N*2-1):
            if S2[i]==S2[i+1]:
                S2[i+1]="#"
                ans2+=1
                
         i range(N*2-1) range N*2-1 N*2 N 2 1 if S2[i]==S2[i+1]:
                S2[i+1]="#"
                ans2+=1
                
         S2[i]==S2[i+1] S2[i] S2 i S2[i+1] S2 i+1 i 1 S2[i+1]="#" S2[i+1] S2 i+1 i 1 "#" ans2+=1 ans2 1 ans3=0 ans3 0 for i in range(N*3-1):
            if S3[i]==S3[i+1]:
                S3[i+1]="#"
                ans3+=1
                
         i range(N*3-1) range N*3-1 N*3 N 3 1 if S3[i]==S3[i+1]:
                S3[i+1]="#"
                ans3+=1
                
         S3[i]==S3[i+1] S3[i] S3 i S3[i+1] S3 i+1 i 1 S3[i+1]="#" S3[i+1] S3 i+1 i 1 "#" ans3+=1 ans3 1 ansd=ans3-ans2 ansd ans3-ans2 ans3 ans2 if K==2:
            ans=ans2
        else:
            ans=ans2+(K-2)*ansd

        
     K==2 K 2 ans=ans2 ans ans2 ans=ans2+(K-2)*ansd ans ans2+(K-2)*ansd ans2 (K-2)*ansd K-2 K 2 ansd print(ans) print ans main() main def LI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) LI def I(): return int(input()) def I(): return int(input()) I def MI(): return map(int, input().split()) def MI(): return map(int, input().split()) MI def main():
    mod=10**9+7
    S=list(input())
    K=I()
    
    S3=S*3
    S2=S*2
    
    ans=0
    
    N=len(S)
    
    flag=0
    if S.count(S[0])==N:
        flag=1
    
    if N==1 or flag:
        ans=(K*N)//2
    else:
        ans2=0
        for i in range(N*2-1):
            if S2[i]==S2[i+1]:
                S2[i+1]="#"
                ans2+=1
                
        ans3=0
        for i in range(N*3-1):
            if S3[i]==S3[i+1]:
                S3[i+1]="#"
                ans3+=1
                
        ansd=ans3-ans2
        if K==2:
            ans=ans2
        else:
            ans=ans2+(K-2)*ansd

        
    print(ans) def main():
    mod=10**9+7
    S=list(input())
    K=I()
    
    S3=S*3
    S2=S*2
    
    ans=0
    
    N=len(S)
    
    flag=0
    if S.count(S[0])==N:
        flag=1
    
    if N==1 or flag:
        ans=(K*N)//2
    else:
        ans2=0
        for i in range(N*2-1):
            if S2[i]==S2[i+1]:
                S2[i+1]="#"
                ans2+=1
                
        ans3=0
        for i in range(N*3-1):
            if S3[i]==S3[i+1]:
                S3[i+1]="#"
                ans3+=1
                
        ansd=ans3-ans2
        if K==2:
            ans=ans2
        else:
            ans=ans2+(K-2)*ansd

        
    print(ans) main


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    S=list(input())
    K=I()
    
    S3=S*3
    S2=S*2
    
    ans=0
    
    N=len(S)
    
    flag=0
    if S.count(S[0])==N:
        flag=1
    
    if N==1 or flag:
        ans=(K*N)//2
    else:
        ans2=0
        for i in range(N*2-1):
            if S2[i]==S2[i+1]:
                S2[i+1]="#"
                ans2+=1
                
        ans3=0
        for i in range(N*3-1):
            if S3[i]==S3[i+1]:
                S3[i+1]="#"
                ans3+=1
                
        ansd=ans3-ans2
        if K==2:
            ans=ans2
        else:
            ans=ans2+(K-2)*ansd

        
    print(ans)

main()
