s = list(input())
k = int(input())
s += '+'

releki = []
cnt = 1
pre = s[0]
for i in range(1,len(s)):
    if pre==s[i]:
        cnt += 1
    else:
        releki.append([pre,cnt])
        pre = s[i]
        cnt = 1
        
ans = 0
for i in range(len(releki)):
    ans += releki[i][1]//2
if len(releki)==1:
    print((len(s)-1)*k//2)
    exit()
if s[0]!=s[-3]:
    print(ans*k)
else:
    a = releki[0][1]
    b = releki[-1][1]
    ans = ans*k - (k-1)*(a//2 +b//2 -(a+b)//2)
    print(ans) 
 s = list(input()) s list(input()) list input() input k = int(input()) k int(input()) int input() input s += '+' s '+' releki = [] releki [] cnt = 1 cnt 1 pre = s[0] pre s[0] s 0 for i in range(1,len(s)):
    if pre==s[i]:
        cnt += 1
    else:
        releki.append([pre,cnt])
        pre = s[i]
        cnt = 1
         i range(1,len(s)) range 1 len(s) len s if pre==s[i]:
        cnt += 1
    else:
        releki.append([pre,cnt])
        pre = s[i]
        cnt = 1
         pre==s[i] pre s[i] s i cnt += 1 cnt 1 releki.append([pre,cnt]) releki.append releki append [pre,cnt] pre cnt pre = s[i] pre s[i] s i cnt = 1 cnt 1 ans = 0 ans 0 for i in range(len(releki)):
    ans += releki[i][1]//2 i range(len(releki)) range len(releki) len releki ans += releki[i][1]//2 ans releki[i][1]//2 releki[i][1] [i] releki i 1 2 if len(releki)==1:
    print((len(s)-1)*k//2)
    exit() len(releki)==1 len(releki) len releki 1 print((len(s)-1)*k//2) print (len(s)-1)*k//2 (len(s)-1)*k len(s)-1 len(s) len s 1 k 2 exit() exit if s[0]!=s[-3]:
    print(ans*k)
else:
    a = releki[0][1]
    b = releki[-1][1]
    ans = ans*k - (k-1)*(a//2 +b//2 -(a+b)//2)
    print(ans)  s[0]!=s[-3] s[0] s 0 s[-3] s -3 print(ans*k) print ans*k ans k a = releki[0][1] a releki[0][1] [0] releki 0 1 b = releki[-1][1] b releki[-1][1] [-1] releki -1 1 ans = ans*k - (k-1)*(a//2 +b//2 -(a+b)//2) ans ans*k - (k-1)*(a//2 +b//2 -(a+b)//2) ans*k ans k (k-1)*(a//2 +b//2 -(a+b)//2) k-1 k 1 a//2 +b//2 -(a+b)//2 a//2 +b//2 a//2 a 2 b//2 b 2 (a+b)//2 a+b a b 2 print(ans) print ans ans = 0 0 ans pre = s[0] s[0] pre ans = ans*k - (k-1)*(a//2 +b//2 -(a+b)//2) ans*k - (k-1)*(a//2 +b//2 -(a+b)//2) ans ans += releki[i][1]//2 releki[i][1]//2 ans s = list(input()) list(input()) s s += '+' '+' s b = releki[-1][1] releki[-1][1] b cnt = 1 1 cnt releki = [] [] releki cnt += 1 1 cnt cnt = 1 1 cnt k = int(input()) int(input()) k pre = s[i] s[i] pre a = releki[0][1] releki[0][1] a
s = list(input())
k = int(input())
s += '+'

releki = []
cnt = 1
pre = s[0]
for i in range(1,len(s)):
    if pre==s[i]:
        cnt += 1
    else:
        releki.append([pre,cnt])
        pre = s[i]
        cnt = 1
        
ans = 0
for i in range(len(releki)):
    ans += releki[i][1]//2
if len(releki)==1:
    print((len(s)-1)*k//2)
    exit()
if s[0]!=s[-3]:
    print(ans*k)
else:
    a = releki[0][1]
    b = releki[-1][1]
    ans = ans*k - (k-1)*(a//2 +b//2 -(a+b)//2)
    print(ans) 

