S = list(input())
NS = [s for s in S]
K = int(input())
L = len(S)

if "".join(S) == S[0] * L:
  print(L * K // 2)
  exit()

ans = 0
for i in range(L-1):
  f_s = S[i]
  s_s = S[i+1]
  if f_s == s_s:
    S[i+1] = '-'
    ans += 1

# 先頭と末尾が異なる
if S[0] != S[-1]:
  ans *= K
# 一緒
else:
  a = 0
  for i in range(L):
    if NS[i] == NS[0]:
      a += 1
    else:
      break
  
  b = 0
  for i in range(L)[::-1]:
    if NS[i] == NS[-1]:
      b += 1
    else:
      break
      

  ans *= K
  #t = (- (-a // 2)) + (- (-b // 2)) - (- (-a-b) // 2)
  #t = -(-a // 2) - (-b // 2) + (-(a+b) // 2)
  t = a // 2 + b // 2 - (a+b) // 2
  ans -= t * (K-1)
  
print(ans)
   S = list(input()) S list(input()) list input() input s for s in S for s in S s S for s in S s NS = [s for s in S] NS [s for s in S] K = int(input()) K int(input()) int input() input L = len(S) L len(S) len S if "".join(S) == S[0] * L:
  print(L * K // 2)
  exit() "".join(S) == S[0] * L "".join(S) "".join "" join S S[0] * L S[0] S 0 L print(L * K // 2) print L * K // 2 L * K L K 2 exit() exit ans = 0 ans 0 for i in range(L-1):
  f_s = S[i]
  s_s = S[i+1]
  if f_s == s_s:
    S[i+1] = '-'
    ans += 1

# 先頭と末尾が異なる i range(L-1) range L-1 L 1 f_s = S[i] f_s S[i] S i s_s = S[i+1] s_s S[i+1] S i+1 i 1 if f_s == s_s:
    S[i+1] = '-'
    ans += 1

# 先頭と末尾が異なる f_s == s_s f_s s_s S[i+1] = '-' S[i+1] S i+1 i 1 '-' ans += 1 ans 1 if S[0] != S[-1]:
  ans *= K
# 一緒
else:
  a = 0
  for i in range(L):
    if NS[i] == NS[0]:
      a += 1
    else:
      break
  
  b = 0
  for i in range(L)[::-1]:
    if NS[i] == NS[-1]:
      b += 1
    else:
      break
      

  ans *= K
  #t = (- (-a // 2)) + (- (-b // 2)) - (- (-a-b) // 2)
  #t = -(-a // 2) - (-b // 2) + (-(a+b) // 2)
  t = a // 2 + b // 2 - (a+b) // 2
  ans -= t * (K-1)
   S[0] != S[-1] S[0] S 0 S[-1] S -1 ans *= K ans K a = 0 a 0 for i in range(L):
    if NS[i] == NS[0]:
      a += 1
    else:
      break
  
   i range(L) range L if NS[i] == NS[0]:
      a += 1
    else:
      break
  
   NS[i] == NS[0] NS[i] NS i NS[0] NS 0 a += 1 a 1 break b = 0 b 0 for i in range(L)[::-1]:
    if NS[i] == NS[-1]:
      b += 1
    else:
      break
      

   i range(L)[::-1] (L) range L ::-1 -1 if NS[i] == NS[-1]:
      b += 1
    else:
      break
      

   NS[i] == NS[-1] NS[i] NS i NS[-1] NS -1 b += 1 b 1 break ans *= K ans K t = a // 2 + b // 2 - (a+b) // 2 t 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 ans -= t * (K-1) ans t * (K-1) t K-1 K 1 print(ans) print ans ans *= K K ans S = list(input()) list(input()) S s_s = S[i+1] S[i+1] s_s t = a // 2 + b // 2 - (a+b) // 2 a // 2 + b // 2 - (a+b) // 2 t ans -= t * (K-1) t * (K-1) ans ans *= K K ans NS = [s for s in S] [s for s in S] NS L = len(S) len(S) L b = 0 0 b a = 0 0 a f_s = S[i] S[i] f_s b += 1 1 b ans = 0 0 ans a += 1 1 a ans += 1 1 ans K = int(input()) int(input()) K
S = list(input())
NS = [s for s in S]
K = int(input())
L = len(S)

if "".join(S) == S[0] * L:
  print(L * K // 2)
  exit()

ans = 0
for i in range(L-1):
  f_s = S[i]
  s_s = S[i+1]
  if f_s == s_s:
    S[i+1] = '-'
    ans += 1

# 先頭と末尾が異なる
if S[0] != S[-1]:
  ans *= K
# 一緒
else:
  a = 0
  for i in range(L):
    if NS[i] == NS[0]:
      a += 1
    else:
      break
  
  b = 0
  for i in range(L)[::-1]:
    if NS[i] == NS[-1]:
      b += 1
    else:
      break
      

  ans *= K
  #t = (- (-a // 2)) + (- (-b // 2)) - (- (-a-b) // 2)
  #t = -(-a // 2) - (-b // 2) + (-(a+b) // 2)
  t = a // 2 + b // 2 - (a+b) // 2
  ans -= t * (K-1)
  
print(ans)
  
