S = list(input())
N = len(S)
K = int(input())
if N == 1:
  print(K//2)
  quit()

S = S + S + S
ans_first = ans_odd = ans_even = 0
for i in range(1, N):
  pre_s = S[i-1]
  s = S[i]
  if s == pre_s:
    ans_first += 1
    S[i] = '#'

for i in range(N, 2*N):
  pre_s = S[i-1]
  s = S[i]
  if s == pre_s:
    ans_even += 1
    S[i] = '#'

for i in range(2*N, 3*N):
  pre_s = S[i-1]
  s = S[i]
  if s == pre_s:
    ans_odd += 1
    S[i] = '#'

k_even = K // 2
k_odd = K - k_even - 1
print(ans_first + k_odd*ans_odd + k_even*ans_even) S = list(input()) S list(input()) list input() input N = len(S) N len(S) len S K = int(input()) K int(input()) int input() input if N == 1:
  print(K//2)
  quit() N == 1 N 1 print(K//2) print K//2 K 2 quit() quit S = S + S + S S S + S + S S + S S S S ans_first = ans_odd = ans_even = 0 ans_first 0 = ans_odd = ans_even = 0 ans_odd 0 ans_even for i in range(1, N):
  pre_s = S[i-1]
  s = S[i]
  if s == pre_s:
    ans_first += 1
    S[i] = '#' i range(1, N) range 1 N pre_s = S[i-1] pre_s S[i-1] S i-1 i 1 s = S[i] s S[i] S i if s == pre_s:
    ans_first += 1
    S[i] = '#' s == pre_s s pre_s ans_first += 1 ans_first 1 S[i] = '#' S[i] S i '#' for i in range(N, 2*N):
  pre_s = S[i-1]
  s = S[i]
  if s == pre_s:
    ans_even += 1
    S[i] = '#' i range(N, 2*N) range N 2*N 2 N pre_s = S[i-1] pre_s S[i-1] S i-1 i 1 s = S[i] s S[i] S i if s == pre_s:
    ans_even += 1
    S[i] = '#' s == pre_s s pre_s ans_even += 1 ans_even 1 S[i] = '#' S[i] S i '#' for i in range(2*N, 3*N):
  pre_s = S[i-1]
  s = S[i]
  if s == pre_s:
    ans_odd += 1
    S[i] = '#' i range(2*N, 3*N) range 2*N 2 N 3*N 3 N pre_s = S[i-1] pre_s S[i-1] S i-1 i 1 s = S[i] s S[i] S i if s == pre_s:
    ans_odd += 1
    S[i] = '#' s == pre_s s pre_s ans_odd += 1 ans_odd 1 S[i] = '#' S[i] S i '#' k_even = K // 2 k_even K // 2 K 2 k_odd = K - k_even - 1 k_odd K - k_even - 1 K - k_even K k_even 1 print(ans_first + k_odd*ans_odd + k_even*ans_even) print ans_first + k_odd*ans_odd + k_even*ans_even ans_first + k_odd*ans_odd ans_first k_odd*ans_odd k_odd ans_odd k_even*ans_even k_even ans_even N = len(S) len(S) N ans_odd = ans_even = 0 0 ans_odd ans_even = 0 0 ans_even ans_even += 1 1 ans_even S = S + S + S S + S + S S K = int(input()) int(input()) K k_odd = K - k_even - 1 K - k_even - 1 k_odd s = S[i] S[i] s pre_s = S[i-1] S[i-1] pre_s s = S[i] S[i] s k_even = K // 2 K // 2 k_even ans_first = ans_odd = ans_even = 0 0 ans_first ans_first += 1 1 ans_first s = S[i] S[i] s pre_s = S[i-1] S[i-1] pre_s ans_odd += 1 1 ans_odd pre_s = S[i-1] S[i-1] pre_s S = list(input()) list(input()) S
S = list(input())
N = len(S)
K = int(input())
if N == 1:
  print(K//2)
  quit()

S = S + S + S
ans_first = ans_odd = ans_even = 0
for i in range(1, N):
  pre_s = S[i-1]
  s = S[i]
  if s == pre_s:
    ans_first += 1
    S[i] = '#'

for i in range(N, 2*N):
  pre_s = S[i-1]
  s = S[i]
  if s == pre_s:
    ans_even += 1
    S[i] = '#'

for i in range(2*N, 3*N):
  pre_s = S[i-1]
  s = S[i]
  if s == pre_s:
    ans_odd += 1
    S[i] = '#'

k_even = K // 2
k_odd = K - k_even - 1
print(ans_first + k_odd*ans_odd + k_even*ans_even)