import numpy as np
s=input()
k=int(input())
cnt=1
a=[]
ss=s+"."
for i in range(len(s)):
    if ss[i]==ss[i+1]:
        cnt+=1
    else:
        a.append(cnt)
        cnt=1

pp=0
if s[0]==s[len(s)-1]:
    pp=a[0]+a[-1]
    
    b=[]
    if len(a)>1:
        b.append(pp)
        b+=a[1:len(a)-1]

    else:
        a=[len(s)*k]
        b=[]

else:
    
    b=a
arr=np.array(a)
arr2=np.array(b)

a=arr//2
b=arr2//2
if len(s)>=2:
    print(np.sum(a)+int((k-1)*np.sum(b)))
else:
    print(k//2) import numpy as np numpy s=input() s input() input k=int(input()) k int(input()) int input() input cnt=1 cnt 1 a=[] a [] ss=s+"." ss s+"." s "." for i in range(len(s)):
    if ss[i]==ss[i+1]:
        cnt+=1
    else:
        a.append(cnt)
        cnt=1 i range(len(s)) range len(s) len s if ss[i]==ss[i+1]:
        cnt+=1
    else:
        a.append(cnt)
        cnt=1 ss[i]==ss[i+1] ss[i] ss i ss[i+1] ss i+1 i 1 cnt+=1 cnt 1 a.append(cnt) a.append a append cnt cnt=1 cnt 1 pp=0 pp 0 if s[0]==s[len(s)-1]:
    pp=a[0]+a[-1]
    
    b=[]
    if len(a)>1:
        b.append(pp)
        b+=a[1:len(a)-1]

    else:
        a=[len(s)*k]
        b=[]

else:
    
    b=a s[0]==s[len(s)-1] s[0] s 0 s[len(s)-1] s len(s)-1 len(s) len s 1 pp=a[0]+a[-1] pp a[0]+a[-1] a[0] a 0 a[-1] a -1 b=[] b [] if len(a)>1:
        b.append(pp)
        b+=a[1:len(a)-1]

    else:
        a=[len(s)*k]
        b=[] len(a)>1 len(a) len a 1 b.append(pp) b.append b append pp b+=a[1:len(a)-1] b a[1:len(a)-1] a 1:len(a)-1 1 len(a)-1 len(a) len a 1 a=[len(s)*k] a [len(s)*k] len(s)*k len(s) len s k b=[] b [] b=a b a arr=np.array(a) arr np.array(a) np.array np array a arr2=np.array(b) arr2 np.array(b) np.array np array b a=arr//2 a arr//2 arr 2 b=arr2//2 b arr2//2 arr2 2 if len(s)>=2:
    print(np.sum(a)+int((k-1)*np.sum(b)))
else:
    print(k//2) len(s)>=2 len(s) len s 2 print(np.sum(a)+int((k-1)*np.sum(b))) print np.sum(a)+int((k-1)*np.sum(b)) np.sum(a) np.sum np sum a int((k-1)*np.sum(b)) int (k-1)*np.sum(b) k-1 k 1 np.sum(b) np.sum np sum b print(k//2) print k//2 k 2 b+=a[1:len(a)-1] a[1:len(a)-1] b a=[] [] a b=arr2//2 arr2//2 b cnt=1 1 cnt pp=a[0]+a[-1] a[0]+a[-1] pp a=[len(s)*k] [len(s)*k] a arr=np.array(a) np.array(a) arr cnt=1 1 cnt s=input() input() s b=[] [] b ss=s+"." s+"." ss b=[] [] b a=arr//2 arr//2 a cnt+=1 1 cnt pp=0 0 pp b=a a b k=int(input()) int(input()) k arr2=np.array(b) np.array(b) arr2
import numpy as np
s=input()
k=int(input())
cnt=1
a=[]
ss=s+"."
for i in range(len(s)):
    if ss[i]==ss[i+1]:
        cnt+=1
    else:
        a.append(cnt)
        cnt=1

pp=0
if s[0]==s[len(s)-1]:
    pp=a[0]+a[-1]
    
    b=[]
    if len(a)>1:
        b.append(pp)
        b+=a[1:len(a)-1]

    else:
        a=[len(s)*k]
        b=[]

else:
    
    b=a
arr=np.array(a)
arr2=np.array(b)

a=arr//2
b=arr2//2
if len(s)>=2:
    print(np.sum(a)+int((k-1)*np.sum(b)))
else:
    print(k//2)