s=input()
k=int(input())
s1=[]
num1=1
str1=s[0]
for i in range(1,len(s)):
    if str1==s[i]:
        num1+=1
    else:
        s1.append([str1,num1])
        num1=1
        str1=s[i]
s1.append([str1,num1])
if len(s1)>1:
    if s1[0][0]!=s1[-1][0]:
        num2=0
        for i in range(len(s1)):
            num2+=s1[i][1]//2
        print(k*num2)
    else:
        num2=0
        num3=s1[0][1]//2
        num4=s1[-1][1]//2
        num5=(s1[0][1]+s1[-1][1])//2
        for i in range(1,len(s1)-1):
            num2+=s1[i][1]//2
        print((num2*k)+(num5*(k-1))+num3+num4)
else:
    print((len(s)*k)//2) s=input() s input() input k=int(input()) k int(input()) int input() input s1=[] s1 [] num1=1 num1 1 str1=s[0] str1 s[0] s 0 for i in range(1,len(s)):
    if str1==s[i]:
        num1+=1
    else:
        s1.append([str1,num1])
        num1=1
        str1=s[i] i range(1,len(s)) range 1 len(s) len s if str1==s[i]:
        num1+=1
    else:
        s1.append([str1,num1])
        num1=1
        str1=s[i] str1==s[i] str1 s[i] s i num1+=1 num1 1 s1.append([str1,num1]) s1.append s1 append [str1,num1] str1 num1 num1=1 num1 1 str1=s[i] str1 s[i] s i s1.append([str1,num1]) s1.append s1 append [str1,num1] str1 num1 if len(s1)>1:
    if s1[0][0]!=s1[-1][0]:
        num2=0
        for i in range(len(s1)):
            num2+=s1[i][1]//2
        print(k*num2)
    else:
        num2=0
        num3=s1[0][1]//2
        num4=s1[-1][1]//2
        num5=(s1[0][1]+s1[-1][1])//2
        for i in range(1,len(s1)-1):
            num2+=s1[i][1]//2
        print((num2*k)+(num5*(k-1))+num3+num4)
else:
    print((len(s)*k)//2) len(s1)>1 len(s1) len s1 1 if s1[0][0]!=s1[-1][0]:
        num2=0
        for i in range(len(s1)):
            num2+=s1[i][1]//2
        print(k*num2)
    else:
        num2=0
        num3=s1[0][1]//2
        num4=s1[-1][1]//2
        num5=(s1[0][1]+s1[-1][1])//2
        for i in range(1,len(s1)-1):
            num2+=s1[i][1]//2
        print((num2*k)+(num5*(k-1))+num3+num4) s1[0][0]!=s1[-1][0] s1[0][0] [0] s1 0 0 s1[-1][0] [-1] s1 -1 0 num2=0 num2 0 for i in range(len(s1)):
            num2+=s1[i][1]//2
         i range(len(s1)) range len(s1) len s1 num2+=s1[i][1]//2 num2 s1[i][1]//2 s1[i][1] [i] s1 i 1 2 print(k*num2) print k*num2 k num2 num2=0 num2 0 num3=s1[0][1]//2 num3 s1[0][1]//2 s1[0][1] [0] s1 0 1 2 num4=s1[-1][1]//2 num4 s1[-1][1]//2 s1[-1][1] [-1] s1 -1 1 2 num5=(s1[0][1]+s1[-1][1])//2 num5 (s1[0][1]+s1[-1][1])//2 s1[0][1]+s1[-1][1] s1[0][1] [0] s1 0 1 s1[-1][1] [-1] s1 -1 1 2 for i in range(1,len(s1)-1):
            num2+=s1[i][1]//2
         i range(1,len(s1)-1) range 1 len(s1)-1 len(s1) len s1 1 num2+=s1[i][1]//2 num2 s1[i][1]//2 s1[i][1] [i] s1 i 1 2 print((num2*k)+(num5*(k-1))+num3+num4) print (num2*k)+(num5*(k-1))+num3+num4 (num2*k)+(num5*(k-1))+num3 (num2*k)+(num5*(k-1)) num2*k num2 k num5*(k-1) num5 k-1 k 1 num3 num4 print((len(s)*k)//2) print (len(s)*k)//2 len(s)*k len(s) len s k 2 num2=0 0 num2 s=input() input() s s1=[] [] s1 num2=0 0 num2 num2+=s1[i][1]//2 s1[i][1]//2 num2 k=int(input()) int(input()) k str1=s[i] s[i] str1 num2+=s1[i][1]//2 s1[i][1]//2 num2 num4=s1[-1][1]//2 s1[-1][1]//2 num4 str1=s[0] s[0] str1 num1+=1 1 num1 num1=1 1 num1 num1=1 1 num1 num5=(s1[0][1]+s1[-1][1])//2 (s1[0][1]+s1[-1][1])//2 num5 num3=s1[0][1]//2 s1[0][1]//2 num3
s=input()
k=int(input())
s1=[]
num1=1
str1=s[0]
for i in range(1,len(s)):
    if str1==s[i]:
        num1+=1
    else:
        s1.append([str1,num1])
        num1=1
        str1=s[i]
s1.append([str1,num1])
if len(s1)>1:
    if s1[0][0]!=s1[-1][0]:
        num2=0
        for i in range(len(s1)):
            num2+=s1[i][1]//2
        print(k*num2)
    else:
        num2=0
        num3=s1[0][1]//2
        num4=s1[-1][1]//2
        num5=(s1[0][1]+s1[-1][1])//2
        for i in range(1,len(s1)-1):
            num2+=s1[i][1]//2
        print((num2*k)+(num5*(k-1))+num3+num4)
else:
    print((len(s)*k)//2)
