s = input()
k = int(input())
def seqcnt(s):
    cnt=1
    ans=0
    bk=''
    for c in s+' ':
        if bk==c:
            cnt+=1
        else:
            ans+=(cnt)//2
            cnt=1
        bk=c
    return ans

cnt=seqcnt(s)
cnt2=seqcnt(s*2)    
if len(set(list(s)))==1:
    print(len(s)*k//2)
else:
    print(cnt+(cnt2-cnt)*(k-1)) s = input() s input() input k = int(input()) k int(input()) int input() input def seqcnt(s):
    cnt=1
    ans=0
    bk=''
    for c in s+' ':
        if bk==c:
            cnt+=1
        else:
            ans+=(cnt)//2
            cnt=1
        bk=c
    return ans seqcnt cnt=1 cnt 1 ans=0 ans 0 bk='' bk '' for c in s+' ':
        if bk==c:
            cnt+=1
        else:
            ans+=(cnt)//2
            cnt=1
        bk=c
     c s+' ' s ' ' if bk==c:
            cnt+=1
        else:
            ans+=(cnt)//2
            cnt=1
         bk==c bk c cnt+=1 cnt 1 ans+=(cnt)//2 ans (cnt)//2 cnt 2 cnt=1 cnt 1 bk=c bk c return ans ans s s cnt=seqcnt(s) cnt seqcnt(s) seqcnt s cnt2=seqcnt(s*2) cnt2 seqcnt(s*2) seqcnt s*2 s 2 if len(set(list(s)))==1:
    print(len(s)*k//2)
else:
    print(cnt+(cnt2-cnt)*(k-1)) len(set(list(s)))==1 len(set(list(s))) len set(list(s)) set list(s) list s 1 print(len(s)*k//2) print len(s)*k//2 len(s)*k len(s) len s k 2 print(cnt+(cnt2-cnt)*(k-1)) print cnt+(cnt2-cnt)*(k-1) cnt (cnt2-cnt)*(k-1) cnt2-cnt cnt2 cnt k-1 k 1 k = int(input()) int(input()) k s = input() input() s def seqcnt(s):
    cnt=1
    ans=0
    bk=''
    for c in s+' ':
        if bk==c:
            cnt+=1
        else:
            ans+=(cnt)//2
            cnt=1
        bk=c
    return ans def seqcnt(s):
    cnt=1
    ans=0
    bk=''
    for c in s+' ':
        if bk==c:
            cnt+=1
        else:
            ans+=(cnt)//2
            cnt=1
        bk=c
    return ans seqcnt cnt=seqcnt(s) seqcnt(s) cnt cnt2=seqcnt(s*2) seqcnt(s*2) cnt2
s = input()
k = int(input())
def seqcnt(s):
    cnt=1
    ans=0
    bk=''
    for c in s+' ':
        if bk==c:
            cnt+=1
        else:
            ans+=(cnt)//2
            cnt=1
        bk=c
    return ans

cnt=seqcnt(s)
cnt2=seqcnt(s*2)    
if len(set(list(s)))==1:
    print(len(s)*k//2)
else:
    print(cnt+(cnt2-cnt)*(k-1))