s = input()
k = int(input())
l=len(s)
s+='?'
ch = 1
ans=0
j=0

for i in range(l):
    if s[i]==s[i+1]:
        ch+=1
    else:
        ans+=ch//2
        if j==0:
            st=ch
        if s[i+1]=='?':
            gl=ch
        ch=1
        j=1
ans*=k
if st%2==1 and gl%2==1 and s[0]==s[l-1]:
    ans+=k-1

if st==l:
    ans=l*k//2

print(ans) s = input() s input() input k = int(input()) k int(input()) int input() input l=len(s) l len(s) len s s+='?' s '?' ch = 1 ch 1 ans=0 ans 0 j=0 j 0 for i in range(l):
    if s[i]==s[i+1]:
        ch+=1
    else:
        ans+=ch//2
        if j==0:
            st=ch
        if s[i+1]=='?':
            gl=ch
        ch=1
        j=1 i range(l) range l if s[i]==s[i+1]:
        ch+=1
    else:
        ans+=ch//2
        if j==0:
            st=ch
        if s[i+1]=='?':
            gl=ch
        ch=1
        j=1 s[i]==s[i+1] s[i] s i s[i+1] s i+1 i 1 ch+=1 ch 1 ans+=ch//2 ans ch//2 ch 2 if j==0:
            st=ch
         j==0 j 0 st=ch st ch if s[i+1]=='?':
            gl=ch
         s[i+1]=='?' s[i+1] s i+1 i 1 '?' gl=ch gl ch ch=1 ch 1 j=1 j 1 ans*=k ans k if st%2==1 and gl%2==1 and s[0]==s[l-1]:
    ans+=k-1 st%2==1 and gl%2==1 and s[0]==s[l-1] st%2==1 and gl%2==1 st%2==1 st%2 st 2 1 gl%2==1 gl%2 gl 2 1 s[0]==s[l-1] s[0] s 0 s[l-1] s l-1 l 1 ans+=k-1 ans k-1 k 1 if st==l:
    ans=l*k//2 st==l st l ans=l*k//2 ans l*k//2 l*k l k 2 print(ans) print ans l=len(s) len(s) l s+='?' '?' s j=0 0 j ans+=ch//2 ch//2 ans k = int(input()) int(input()) k gl=ch ch gl ans+=k-1 k-1 ans ans=l*k//2 l*k//2 ans ch = 1 1 ch s = input() input() s ch+=1 1 ch st=ch ch st ans=0 0 ans ans*=k k ans ch=1 1 ch j=1 1 j
s = input()
k = int(input())
l=len(s)
s+='?'
ch = 1
ans=0
j=0

for i in range(l):
    if s[i]==s[i+1]:
        ch+=1
    else:
        ans+=ch//2
        if j==0:
            st=ch
        if s[i+1]=='?':
            gl=ch
        ch=1
        j=1
ans*=k
if st%2==1 and gl%2==1 and s[0]==s[l-1]:
    ans+=k-1

if st==l:
    ans=l*k//2

print(ans)
