S = input()
K = int(input())

lst = []
b = ""
tmp = 0
rlt = 0
for s in S:
  if s == b:
    tmp += 1
  else:
    lst.append(tmp)
    tmp = 1
  b = s
    
lst.append(tmp)

if len(lst) == 2:
  rlt = (lst[1]*K)//2

elif S[0] == S[-1]:
  rlt = ((lst[1]+lst[-1])//2)*(K-1) + lst[1]//2 + lst[-1]//2
  for t in lst[2:-1]:
    rlt += (t//2)*K
else:
  for t in lst[1:]:
    rlt += (t//2)*K
    
print(rlt) S = input() S input() input K = int(input()) K int(input()) int input() input lst = [] lst [] b = "" b "" tmp = 0 tmp 0 rlt = 0 rlt 0 for s in S:
  if s == b:
    tmp += 1
  else:
    lst.append(tmp)
    tmp = 1
  b = s
     s S if s == b:
    tmp += 1
  else:
    lst.append(tmp)
    tmp = 1
   s == b s b tmp += 1 tmp 1 lst.append(tmp) lst.append lst append tmp tmp = 1 tmp 1 b = s b s lst.append(tmp) lst.append lst append tmp if len(lst) == 2:
  rlt = (lst[1]*K)//2

elif S[0] == S[-1]:
  rlt = ((lst[1]+lst[-1])//2)*(K-1) + lst[1]//2 + lst[-1]//2
  for t in lst[2:-1]:
    rlt += (t//2)*K
else:
  for t in lst[1:]:
    rlt += (t//2)*K
     len(lst) == 2 len(lst) len lst 2 rlt = (lst[1]*K)//2 rlt (lst[1]*K)//2 lst[1]*K lst[1] lst 1 K 2 elif S[0] == S[-1]:
  rlt = ((lst[1]+lst[-1])//2)*(K-1) + lst[1]//2 + lst[-1]//2
  for t in lst[2:-1]:
    rlt += (t//2)*K S[0] == S[-1] S[0] S 0 S[-1] S -1 rlt = ((lst[1]+lst[-1])//2)*(K-1) + lst[1]//2 + lst[-1]//2 rlt ((lst[1]+lst[-1])//2)*(K-1) + lst[1]//2 + lst[-1]//2 ((lst[1]+lst[-1])//2)*(K-1) + lst[1]//2 ((lst[1]+lst[-1])//2)*(K-1) (lst[1]+lst[-1])//2 lst[1]+lst[-1] lst[1] lst 1 lst[-1] lst -1 2 K-1 K 1 lst[1]//2 lst[1] lst 1 2 lst[-1]//2 lst[-1] lst -1 2 for t in lst[2:-1]:
    rlt += (t//2)*K t lst[2:-1] lst 2:-1 2 -1 rlt += (t//2)*K rlt (t//2)*K t//2 t 2 K for t in lst[1:]:
    rlt += (t//2)*K
     t lst[1:] lst 1: 1 rlt += (t//2)*K rlt (t//2)*K t//2 t 2 K print(rlt) print rlt rlt += (t//2)*K (t//2)*K rlt lst = [] [] lst rlt = (lst[1]*K)//2 (lst[1]*K)//2 rlt b = "" "" b rlt = 0 0 rlt rlt += (t//2)*K (t//2)*K rlt tmp += 1 1 tmp S = input() input() S K = int(input()) int(input()) K b = s s b rlt = ((lst[1]+lst[-1])//2)*(K-1) + lst[1]//2 + lst[-1]//2 ((lst[1]+lst[-1])//2)*(K-1) + lst[1]//2 + lst[-1]//2 rlt tmp = 1 1 tmp tmp = 0 0 tmp
S = input()
K = int(input())

lst = []
b = ""
tmp = 0
rlt = 0
for s in S:
  if s == b:
    tmp += 1
  else:
    lst.append(tmp)
    tmp = 1
  b = s
    
lst.append(tmp)

if len(lst) == 2:
  rlt = (lst[1]*K)//2

elif S[0] == S[-1]:
  rlt = ((lst[1]+lst[-1])//2)*(K-1) + lst[1]//2 + lst[-1]//2
  for t in lst[2:-1]:
    rlt += (t//2)*K
else:
  for t in lst[1:]:
    rlt += (t//2)*K
    
print(rlt)
