s=input()
k=int(input())

def count_change(st):
    st=st+'!'
    cnt=0
    moji=st[0]
    l=0
    r=0
    for i in range(1,len(st)):
        if moji!=st[i]:
            cnt+=(r-l+1)//2
            l=i
            r=i
            moji=st[i]
        else:
            r=i

    return cnt

if len(set(s))==1:
    ans=len(s)*k//2
    print(ans)
    exit()

if s[0]==s[-1]:
    a=1
    for i in range(len(s)):
        if s[i]!=s[i+1]:
            break
        else:
            a+=1
    
    b=1
    for i in range(len(s)-1,0,-1):
        if s[i]!=s[i-1]:
            break
        else:
            b+=1
    
    ans=count_change(s)*k-(a//2+b//2-(a+b)//2)*(k-1)

else:
    ans=count_change(s)*k

print(ans) s=input() s input() input k=int(input()) k int(input()) int input() input def count_change(st):
    st=st+'!'
    cnt=0
    moji=st[0]
    l=0
    r=0
    for i in range(1,len(st)):
        if moji!=st[i]:
            cnt+=(r-l+1)//2
            l=i
            r=i
            moji=st[i]
        else:
            r=i

    return cnt count_change st=st+'!' st st+'!' st '!' cnt=0 cnt 0 moji=st[0] moji st[0] st 0 l=0 l 0 r=0 r 0 for i in range(1,len(st)):
        if moji!=st[i]:
            cnt+=(r-l+1)//2
            l=i
            r=i
            moji=st[i]
        else:
            r=i

     i range(1,len(st)) range 1 len(st) len st if moji!=st[i]:
            cnt+=(r-l+1)//2
            l=i
            r=i
            moji=st[i]
        else:
            r=i

     moji!=st[i] moji st[i] st i cnt+=(r-l+1)//2 cnt (r-l+1)//2 r-l+1 r-l r l 1 2 l=i l i r=i r i moji=st[i] moji st[i] st i r=i r i return cnt cnt st st if len(set(s))==1:
    ans=len(s)*k//2
    print(ans)
    exit() len(set(s))==1 len(set(s)) len set(s) set s 1 ans=len(s)*k//2 ans len(s)*k//2 len(s)*k len(s) len s k 2 print(ans) print ans exit() exit if s[0]==s[-1]:
    a=1
    for i in range(len(s)):
        if s[i]!=s[i+1]:
            break
        else:
            a+=1
    
    b=1
    for i in range(len(s)-1,0,-1):
        if s[i]!=s[i-1]:
            break
        else:
            b+=1
    
    ans=count_change(s)*k-(a//2+b//2-(a+b)//2)*(k-1)

else:
    ans=count_change(s)*k s[0]==s[-1] s[0] s 0 s[-1] s -1 a=1 a 1 for i in range(len(s)):
        if s[i]!=s[i+1]:
            break
        else:
            a+=1
    
     i range(len(s)) range len(s) len s if s[i]!=s[i+1]:
            break
        else:
            a+=1
    
     s[i]!=s[i+1] s[i] s i s[i+1] s i+1 i 1 break a+=1 a 1 b=1 b 1 for i in range(len(s)-1,0,-1):
        if s[i]!=s[i-1]:
            break
        else:
            b+=1
    
     i range(len(s)-1,0,-1) range len(s)-1 len(s) len s 1 0 -1 if s[i]!=s[i-1]:
            break
        else:
            b+=1
    
     s[i]!=s[i-1] s[i] s i s[i-1] s i-1 i 1 break b+=1 b 1 ans=count_change(s)*k-(a//2+b//2-(a+b)//2)*(k-1) ans count_change(s)*k-(a//2+b//2-(a+b)//2)*(k-1) count_change(s)*k count_change(s) count_change s k (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 ans=count_change(s)*k ans count_change(s)*k count_change(s) count_change s k print(ans) print ans s=input() input() s ans=count_change(s)*k count_change(s)*k ans ans=len(s)*k//2 len(s)*k//2 ans a=1 1 a a+=1 1 a ans=count_change(s)*k-(a//2+b//2-(a+b)//2)*(k-1) count_change(s)*k-(a//2+b//2-(a+b)//2)*(k-1) ans b=1 1 b k=int(input()) int(input()) k b+=1 1 b def count_change(st):
    st=st+'!'
    cnt=0
    moji=st[0]
    l=0
    r=0
    for i in range(1,len(st)):
        if moji!=st[i]:
            cnt+=(r-l+1)//2
            l=i
            r=i
            moji=st[i]
        else:
            r=i

    return cnt def count_change(st):
    st=st+'!'
    cnt=0
    moji=st[0]
    l=0
    r=0
    for i in range(1,len(st)):
        if moji!=st[i]:
            cnt+=(r-l+1)//2
            l=i
            r=i
            moji=st[i]
        else:
            r=i

    return cnt count_change
s=input()
k=int(input())

def count_change(st):
    st=st+'!'
    cnt=0
    moji=st[0]
    l=0
    r=0
    for i in range(1,len(st)):
        if moji!=st[i]:
            cnt+=(r-l+1)//2
            l=i
            r=i
            moji=st[i]
        else:
            r=i

    return cnt

if len(set(s))==1:
    ans=len(s)*k//2
    print(ans)
    exit()

if s[0]==s[-1]:
    a=1
    for i in range(len(s)):
        if s[i]!=s[i+1]:
            break
        else:
            a+=1
    
    b=1
    for i in range(len(s)-1,0,-1):
        if s[i]!=s[i-1]:
            break
        else:
            b+=1
    
    ans=count_change(s)*k-(a//2+b//2-(a+b)//2)*(k-1)

else:
    ans=count_change(s)*k

print(ans)