from itertools import groupby
S = input()
K = int(input())
if len(set(list(S)))==1:
  print(len(S)*K//2)
  exit()
ans = 0
L = []
for key, val in groupby(S):
  tmp = len(list(val))
  L.append(tmp)
sum_A = sum(k//2 for k in L)
ans = sum_A * K
if S[0] == S[-1]:
  ans += ((L[0]+L[-1])//2 - (L[0]//2+L[-1]//2))*(K-1)
print(ans) from itertools import groupby S = input() S input() input K = int(input()) K int(input()) int input() input if len(set(list(S)))==1:
  print(len(S)*K//2)
  exit() len(set(list(S)))==1 len(set(list(S))) len set(list(S)) set list(S) list S 1 print(len(S)*K//2) print len(S)*K//2 len(S)*K len(S) len S K 2 exit() exit ans = 0 ans 0 L = [] L [] for key, val in groupby(S):
  tmp = len(list(val))
  L.append(tmp) key val groupby(S) groupby S tmp = len(list(val)) tmp len(list(val)) len list(val) list val L.append(tmp) L.append L append tmp sum_A = sum(k//2 for k in L) sum_A sum(k//2 for k in L) sum k//2 k 2 ans = sum_A * K ans sum_A * K sum_A K if S[0] == S[-1]:
  ans += ((L[0]+L[-1])//2 - (L[0]//2+L[-1]//2))*(K-1) S[0] == S[-1] S[0] S 0 S[-1] S -1 ans += ((L[0]+L[-1])//2 - (L[0]//2+L[-1]//2))*(K-1) ans ((L[0]+L[-1])//2 - (L[0]//2+L[-1]//2))*(K-1) (L[0]+L[-1])//2 - (L[0]//2+L[-1]//2) (L[0]+L[-1])//2 L[0]+L[-1] L[0] L 0 L[-1] L -1 2 L[0]//2+L[-1]//2 L[0]//2 L[0] L 0 2 L[-1]//2 L[-1] L -1 2 K-1 K 1 print(ans) print ans ans += ((L[0]+L[-1])//2 - (L[0]//2+L[-1]//2))*(K-1) ((L[0]+L[-1])//2 - (L[0]//2+L[-1]//2))*(K-1) ans K = int(input()) int(input()) K S = input() input() S ans = 0 0 ans tmp = len(list(val)) len(list(val)) tmp ans = sum_A * K sum_A * K ans sum_A = sum(k//2 for k in L) sum(k//2 for k in L) sum_A L = [] [] L
from itertools import groupby
S = input()
K = int(input())
if len(set(list(S)))==1:
  print(len(S)*K//2)
  exit()
ans = 0
L = []
for key, val in groupby(S):
  tmp = len(list(val))
  L.append(tmp)
sum_A = sum(k//2 for k in L)
ans = sum_A * K
if S[0] == S[-1]:
  ans += ((L[0]+L[-1])//2 - (L[0]//2+L[-1]//2))*(K-1)
print(ans)