s=str(input())
k=int(input())
ans=0
count=1
c1=0
c2=0

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

if s[0]==s[-1]:
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            count+=1
        else:
            if 2<=count:
                ans+=count//2
            count=1
    ans+=count//2
    i=0
    while s[i]==s[0]:
        c1+=1
        i+=1
    
    i=len(s)-1
    while s[i]==s[-1]:
        c2+=1
        i-=1
    #print(c1,c2)
    ans*=k
    if c1%2==1 and c2%2==1:
        ans+=k-1

    print(ans)


else:
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            count+=1
        else:
            if 2<=count:
                ans+=count//2
            count=1
    ans+=count//2
    print(ans*k) s=str(input()) s str(input()) str input() input k=int(input()) k int(input()) int input() input ans=0 ans 0 count=1 count 1 c1=0 c1 0 c2=0 c2 0 if len(set(s))==1:
    print(len(s)*k//2)
    exit() len(set(s))==1 len(set(s)) len set(s) set s 1 print(len(s)*k//2) print len(s)*k//2 len(s)*k len(s) len s k 2 exit() exit if s[0]==s[-1]:
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            count+=1
        else:
            if 2<=count:
                ans+=count//2
            count=1
    ans+=count//2
    i=0
    while s[i]==s[0]:
        c1+=1
        i+=1
    
    i=len(s)-1
    while s[i]==s[-1]:
        c2+=1
        i-=1
    #print(c1,c2)
    ans*=k
    if c1%2==1 and c2%2==1:
        ans+=k-1

    print(ans)


else:
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            count+=1
        else:
            if 2<=count:
                ans+=count//2
            count=1
    ans+=count//2
    print(ans*k) s[0]==s[-1] s[0] s 0 s[-1] s -1 for i in range(len(s)-1):
        if s[i]==s[i+1]:
            count+=1
        else:
            if 2<=count:
                ans+=count//2
            count=1
     i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i]==s[i+1]:
            count+=1
        else:
            if 2<=count:
                ans+=count//2
            count=1
     s[i]==s[i+1] s[i] s i s[i+1] s i+1 i 1 count+=1 count 1 if 2<=count:
                ans+=count//2
             2<=count 2 count ans+=count//2 ans count//2 count 2 count=1 count 1 ans+=count//2 ans count//2 count 2 i=0 i 0 while s[i]==s[0]:
        c1+=1
        i+=1
    
     s[i]==s[0] s[i] s i s[0] s 0 c1+=1 c1 1 i+=1 i 1 i=len(s)-1 i len(s)-1 len(s) len s 1 while s[i]==s[-1]:
        c2+=1
        i-=1
    #print(c1,c2)
     s[i]==s[-1] s[i] s i s[-1] s -1 c2+=1 c2 1 i-=1 i 1 ans*=k ans k if c1%2==1 and c2%2==1:
        ans+=k-1

     c1%2==1 and c2%2==1 c1%2==1 c1%2 c1 2 1 c2%2==1 c2%2 c2 2 1 ans+=k-1 ans k-1 k 1 print(ans) print ans for i in range(len(s)-1):
        if s[i]==s[i+1]:
            count+=1
        else:
            if 2<=count:
                ans+=count//2
            count=1
     i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i]==s[i+1]:
            count+=1
        else:
            if 2<=count:
                ans+=count//2
            count=1
     s[i]==s[i+1] s[i] s i s[i+1] s i+1 i 1 count+=1 count 1 if 2<=count:
                ans+=count//2
             2<=count 2 count ans+=count//2 ans count//2 count 2 count=1 count 1 ans+=count//2 ans count//2 count 2 print(ans*k) print ans*k ans k s=str(input()) str(input()) s count=1 1 count c2+=1 1 c2 i+=1 1 i ans*=k k ans count+=1 1 count c1=0 0 c1 ans=0 0 ans ans+=k-1 k-1 ans i=len(s)-1 len(s)-1 i count=1 1 count ans+=count//2 count//2 ans i=0 0 i c2=0 0 c2 ans+=count//2 count//2 ans count=1 1 count i-=1 1 i ans+=count//2 count//2 ans k=int(input()) int(input()) k count+=1 1 count c1+=1 1 c1 ans+=count//2 count//2 ans
s=str(input())
k=int(input())
ans=0
count=1
c1=0
c2=0

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

if s[0]==s[-1]:
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            count+=1
        else:
            if 2<=count:
                ans+=count//2
            count=1
    ans+=count//2
    i=0
    while s[i]==s[0]:
        c1+=1
        i+=1
    
    i=len(s)-1
    while s[i]==s[-1]:
        c2+=1
        i-=1
    #print(c1,c2)
    ans*=k
    if c1%2==1 and c2%2==1:
        ans+=k-1

    print(ans)


else:
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            count+=1
        else:
            if 2<=count:
                ans+=count//2
            count=1
    ans+=count//2
    print(ans*k)