S = list(input())
N = len(S)
K = int(input())
old = S[0]
a = 0
c = 1
for i in range(1,N):
  if S[i] == old:
    c += 1
  else:
    a += c // 2
    old = S[i]
    c = 1
b = 0
a += c // 2
for i in range(N):
  if S[i] == old:
      b += 1
  else:
    break
ans = a * K + ((b + c) // 2 - b // 2 - c // 2) * (K - 1)
if c == N:
  ans = N * K // 2
print(ans) 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 old = S[0] old S[0] S 0 a = 0 a 0 c = 1 c 1 for i in range(1,N):
  if S[i] == old:
    c += 1
  else:
    a += c // 2
    old = S[i]
    c = 1 i range(1,N) range 1 N if S[i] == old:
    c += 1
  else:
    a += c // 2
    old = S[i]
    c = 1 S[i] == old S[i] S i old c += 1 c 1 a += c // 2 a c // 2 c 2 old = S[i] old S[i] S i c = 1 c 1 b = 0 b 0 a += c // 2 a c // 2 c 2 for i in range(N):
  if S[i] == old:
      b += 1
  else:
    break i range(N) range N if S[i] == old:
      b += 1
  else:
    break S[i] == old S[i] S i old b += 1 b 1 break ans = a * K + ((b + c) // 2 - b // 2 - c // 2) * (K - 1) ans a * K + ((b + c) // 2 - b // 2 - c // 2) * (K - 1) a * K a K ((b + c) // 2 - b // 2 - c // 2) * (K - 1) (b + c) // 2 - b // 2 - c // 2 (b + c) // 2 - b // 2 (b + c) // 2 b + c b c 2 b // 2 b 2 c // 2 c 2 K - 1 K 1 if c == N:
  ans = N * K // 2 c == N c N ans = N * K // 2 ans N * K // 2 N * K N K 2 print(ans) print ans N = len(S) len(S) N c = 1 1 c b += 1 1 b ans = N * K // 2 N * K // 2 ans K = int(input()) int(input()) K old = S[0] S[0] old a = 0 0 a ans = a * K + ((b + c) // 2 - b // 2 - c // 2) * (K - 1) a * K + ((b + c) // 2 - b // 2 - c // 2) * (K - 1) ans a += c // 2 c // 2 a old = S[i] S[i] old c = 1 1 c S = list(input()) list(input()) S c += 1 1 c a += c // 2 c // 2 a b = 0 0 b
S = list(input())
N = len(S)
K = int(input())
old = S[0]
a = 0
c = 1
for i in range(1,N):
  if S[i] == old:
    c += 1
  else:
    a += c // 2
    old = S[i]
    c = 1
b = 0
a += c // 2
for i in range(N):
  if S[i] == old:
      b += 1
  else:
    break
ans = a * K + ((b + c) // 2 - b // 2 - c // 2) * (K - 1)
if c == N:
  ans = N * K // 2
print(ans)