S = list(input())
s = len(S)
K = int(input())
A = []
j = 1

for i in range(0,s-1,1):
  if S[i] == S[i+1]:
    j += 1
  else:
    A.append(j)
    j = 1
A.append(j)

a = len(A)

b = 0
for i in range(0,a,1):
  b += A[i]//2
  
x = b*K

if a == 1:
  x = (s*K)//2
elif S[s-1] == S[0] and A[a-1] % 2 == 1 and A[0] % 2 == 1:
  x += K-1

print(x) S = list(input()) S list(input()) list input() input s = len(S) s len(S) len S K = int(input()) K int(input()) int input() input A = [] A [] j = 1 j 1 for i in range(0,s-1,1):
  if S[i] == S[i+1]:
    j += 1
  else:
    A.append(j)
    j = 1 i range(0,s-1,1) range 0 s-1 s 1 1 if S[i] == S[i+1]:
    j += 1
  else:
    A.append(j)
    j = 1 S[i] == S[i+1] S[i] S i S[i+1] S i+1 i 1 j += 1 j 1 A.append(j) A.append A append j j = 1 j 1 A.append(j) A.append A append j a = len(A) a len(A) len A b = 0 b 0 for i in range(0,a,1):
  b += A[i]//2
   i range(0,a,1) range 0 a 1 b += A[i]//2 b A[i]//2 A[i] A i 2 x = b*K x b*K b K if a == 1:
  x = (s*K)//2
elif S[s-1] == S[0] and A[a-1] % 2 == 1 and A[0] % 2 == 1:
  x += K-1 a == 1 a 1 x = (s*K)//2 x (s*K)//2 s*K s K 2 elif S[s-1] == S[0] and A[a-1] % 2 == 1 and A[0] % 2 == 1:
  x += K-1 S[s-1] == S[0] and A[a-1] % 2 == 1 and A[0] % 2 == 1 S[s-1] == S[0] and A[a-1] % 2 == 1 S[s-1] == S[0] S[s-1] S s-1 s 1 S[0] S 0 A[a-1] % 2 == 1 A[a-1] % 2 A[a-1] A a-1 a 1 2 1 A[0] % 2 == 1 A[0] % 2 A[0] A 0 2 1 x += K-1 x K-1 K 1 print(x) print x j = 1 1 j x = b*K b*K x K = int(input()) int(input()) K A = [] [] A j = 1 1 j S = list(input()) list(input()) S a = len(A) len(A) a x += K-1 K-1 x s = len(S) len(S) s b += A[i]//2 A[i]//2 b j += 1 1 j b = 0 0 b x = (s*K)//2 (s*K)//2 x
S = list(input())
s = len(S)
K = int(input())
A = []
j = 1

for i in range(0,s-1,1):
  if S[i] == S[i+1]:
    j += 1
  else:
    A.append(j)
    j = 1
A.append(j)

a = len(A)

b = 0
for i in range(0,a,1):
  b += A[i]//2
  
x = b*K

if a == 1:
  x = (s*K)//2
elif S[s-1] == S[0] and A[a-1] % 2 == 1 and A[0] % 2 == 1:
  x += K-1

print(x)