s,k = input(),int(input())
n = len(s)
c = 0
x = []
a = 1
 
for i in range(n):
    if i<n-1 and s[i]==s[i+1]:
        a += 1
    else:
        c += a//2
        x.append(a)
        a = 1
 
c2 = 0
if s[0]==s[-1]:
    c2 = x[0]//2+x[-1]//2-(x[0]+x[-1])//2
 
print(len(s)*k//2 if len(set(s))==1 else c*k-c2*(k-1)) s,k = input(),int(input()) s input() input k int(input()) int input() input n = len(s) n len(s) len s c = 0 c 0 x = [] x [] a = 1 a 1 for i in range(n):
    if i<n-1 and s[i]==s[i+1]:
        a += 1
    else:
        c += a//2
        x.append(a)
        a = 1
  i range(n) range n if i<n-1 and s[i]==s[i+1]:
        a += 1
    else:
        c += a//2
        x.append(a)
        a = 1
  i<n-1 and s[i]==s[i+1] i<n-1 i n-1 n 1 s[i]==s[i+1] s[i] s i s[i+1] s i+1 i 1 a += 1 a 1 c += a//2 c a//2 a 2 x.append(a) x.append x append a a = 1 a 1 c2 = 0 c2 0 if s[0]==s[-1]:
    c2 = x[0]//2+x[-1]//2-(x[0]+x[-1])//2
  s[0]==s[-1] s[0] s 0 s[-1] s -1 c2 = x[0]//2+x[-1]//2-(x[0]+x[-1])//2 c2 x[0]//2+x[-1]//2-(x[0]+x[-1])//2 x[0]//2+x[-1]//2 x[0]//2 x[0] x 0 2 x[-1]//2 x[-1] x -1 2 (x[0]+x[-1])//2 x[0]+x[-1] x[0] x 0 x[-1] x -1 2 print(len(s)*k//2 if len(set(s))==1 else c*k-c2*(k-1)) print len(s)*k//2 if len(set(s))==1 else c*k-c2*(k-1) len(set(s))==1 len(set(s)) len set(s) set s 1 len(s)*k//2 len(s)*k len(s) len s k 2 c*k-c2*(k-1) c*k c k c2*(k-1) c2 k-1 k 1 s,k = input(),int(input()) input() s x = [] [] x k = input(),int(input()) int(input()) k a = 1 1 a n = len(s) len(s) n c = 0 0 c a = 1 1 a a += 1 1 a c += a//2 a//2 c c2 = 0 0 c2 c2 = x[0]//2+x[-1]//2-(x[0]+x[-1])//2 x[0]//2+x[-1]//2-(x[0]+x[-1])//2 c2
s,k = input(),int(input())
n = len(s)
c = 0
x = []
a = 1
 
for i in range(n):
    if i<n-1 and s[i]==s[i+1]:
        a += 1
    else:
        c += a//2
        x.append(a)
        a = 1
 
c2 = 0
if s[0]==s[-1]:
    c2 = x[0]//2+x[-1]//2-(x[0]+x[-1])//2
 
print(len(s)*k//2 if len(set(s))==1 else c*k-c2*(k-1))