s=list(input())
n=len(s)
k=int(input())
count=[]
i=0
while i<=n-1:
    j=0
    while i+j+1<=n-1 and s[i+j]==s[i+j+1]:
        j+=1
    count.append(j+1)
    i+=(j+1)

length=len(count)
if length==1:
    print((n*k)//2)
   
else:
    if s[0]==s[-1]:
        ans=0
        for l in range(length):
            if l!=0 and l!=length-1:
                ans+=(count[l]//2)*k
        ans+=(count[0]//2+count[-1]//2)
        ans+=((count[0]+count[-1])//2)*(k-1)
        print(ans)
    else:
        ans=0
        for m in count:
            ans+=(m//2)*k
        print(ans)
 s=list(input()) s list(input()) list input() input n=len(s) n len(s) len s k=int(input()) k int(input()) int input() input count=[] count [] i=0 i 0 while i<=n-1:
    j=0
    while i+j+1<=n-1 and s[i+j]==s[i+j+1]:
        j+=1
    count.append(j+1)
    i+=(j+1) i<=n-1 i n-1 n 1 j=0 j 0 while i+j+1<=n-1 and s[i+j]==s[i+j+1]:
        j+=1
     i+j+1<=n-1 and s[i+j]==s[i+j+1] i+j+1<=n-1 i+j+1 i+j i j 1 n-1 n 1 s[i+j]==s[i+j+1] s[i+j] s i+j i j s[i+j+1] s i+j+1 i+j i j 1 j+=1 j 1 count.append(j+1) count.append count append j+1 j 1 i+=(j+1) i j+1 j 1 length=len(count) length len(count) len count if length==1:
    print((n*k)//2)
   
else:
    if s[0]==s[-1]:
        ans=0
        for l in range(length):
            if l!=0 and l!=length-1:
                ans+=(count[l]//2)*k
        ans+=(count[0]//2+count[-1]//2)
        ans+=((count[0]+count[-1])//2)*(k-1)
        print(ans)
    else:
        ans=0
        for m in count:
            ans+=(m//2)*k
        print(ans) length==1 length 1 print((n*k)//2) print (n*k)//2 n*k n k 2 if s[0]==s[-1]:
        ans=0
        for l in range(length):
            if l!=0 and l!=length-1:
                ans+=(count[l]//2)*k
        ans+=(count[0]//2+count[-1]//2)
        ans+=((count[0]+count[-1])//2)*(k-1)
        print(ans)
    else:
        ans=0
        for m in count:
            ans+=(m//2)*k
        print(ans) s[0]==s[-1] s[0] s 0 s[-1] s -1 ans=0 ans 0 for l in range(length):
            if l!=0 and l!=length-1:
                ans+=(count[l]//2)*k
         l range(length) range length if l!=0 and l!=length-1:
                ans+=(count[l]//2)*k
         l!=0 and l!=length-1 l!=0 l 0 l!=length-1 l length-1 length 1 ans+=(count[l]//2)*k ans (count[l]//2)*k count[l]//2 count[l] count l 2 k ans+=(count[0]//2+count[-1]//2) ans count[0]//2+count[-1]//2 count[0]//2 count[0] count 0 2 count[-1]//2 count[-1] count -1 2 ans+=((count[0]+count[-1])//2)*(k-1) ans ((count[0]+count[-1])//2)*(k-1) (count[0]+count[-1])//2 count[0]+count[-1] count[0] count 0 count[-1] count -1 2 k-1 k 1 print(ans) print ans ans=0 ans 0 for m in count:
            ans+=(m//2)*k
         m count ans+=(m//2)*k ans (m//2)*k m//2 m 2 k print(ans) print ans i=0 0 i ans+=(count[0]//2+count[-1]//2) count[0]//2+count[-1]//2 ans ans=0 0 ans k=int(input()) int(input()) k length=len(count) len(count) length s=list(input()) list(input()) s j=0 0 j ans=0 0 ans n=len(s) len(s) n ans+=(m//2)*k (m//2)*k ans i+=(j+1) j+1 i ans+=((count[0]+count[-1])//2)*(k-1) ((count[0]+count[-1])//2)*(k-1) ans j+=1 1 j count=[] [] count ans+=(count[l]//2)*k (count[l]//2)*k ans
s=list(input())
n=len(s)
k=int(input())
count=[]
i=0
while i<=n-1:
    j=0
    while i+j+1<=n-1 and s[i+j]==s[i+j+1]:
        j+=1
    count.append(j+1)
    i+=(j+1)

length=len(count)
if length==1:
    print((n*k)//2)
   
else:
    if s[0]==s[-1]:
        ans=0
        for l in range(length):
            if l!=0 and l!=length-1:
                ans+=(count[l]//2)*k
        ans+=(count[0]//2+count[-1]//2)
        ans+=((count[0]+count[-1])//2)*(k-1)
        print(ans)
    else:
        ans=0
        for m in count:
            ans+=(m//2)*k
        print(ans)

