S = input()
K = int(input())
X = 0
i = 1
while i < len(S):
  if S[i] == S[i - 1]:
    X += 1
    i += 1
  i += 1
X *= K
if S == S[0] * len(S) and len(S) % 2 == 1:
  X += K // 2
elif i == len(S) and S[0] == S[-1]:
  x = 1
  i = 2
  while i < len(S):
    if S[i] == S[i - 1]:
      x += 1
      i += 1
    i += 1
  X += (K - 1) * (x - X // K)
print(X) S = input() S input() input K = int(input()) K int(input()) int input() input X = 0 X 0 i = 1 i 1 while i < len(S):
  if S[i] == S[i - 1]:
    X += 1
    i += 1
  i += 1 i < len(S) i len(S) len S if S[i] == S[i - 1]:
    X += 1
    i += 1
   S[i] == S[i - 1] S[i] S i S[i - 1] S i - 1 i 1 X += 1 X 1 i += 1 i 1 i += 1 i 1 X *= K X K if S == S[0] * len(S) and len(S) % 2 == 1:
  X += K // 2
elif i == len(S) and S[0] == S[-1]:
  x = 1
  i = 2
  while i < len(S):
    if S[i] == S[i - 1]:
      x += 1
      i += 1
    i += 1
  X += (K - 1) * (x - X // K) S == S[0] * len(S) and len(S) % 2 == 1 S == S[0] * len(S) S S[0] * len(S) S[0] S 0 len(S) len S len(S) % 2 == 1 len(S) % 2 len(S) len S 2 1 X += K // 2 X K // 2 K 2 elif i == len(S) and S[0] == S[-1]:
  x = 1
  i = 2
  while i < len(S):
    if S[i] == S[i - 1]:
      x += 1
      i += 1
    i += 1
  X += (K - 1) * (x - X // K) i == len(S) and S[0] == S[-1] i == len(S) i len(S) len S S[0] == S[-1] S[0] S 0 S[-1] S -1 x = 1 x 1 i = 2 i 2 while i < len(S):
    if S[i] == S[i - 1]:
      x += 1
      i += 1
    i += 1
   i < len(S) i len(S) len S if S[i] == S[i - 1]:
      x += 1
      i += 1
     S[i] == S[i - 1] S[i] S i S[i - 1] S i - 1 i 1 x += 1 x 1 i += 1 i 1 i += 1 i 1 X += (K - 1) * (x - X // K) X (K - 1) * (x - X // K) K - 1 K 1 x - X // K x X // K X K print(X) print X i += 1 1 i i += 1 1 i i = 2 2 i x += 1 1 x X += 1 1 X S = input() input() S X *= K K X X = 0 0 X i += 1 1 i i += 1 1 i K = int(input()) int(input()) K X += (K - 1) * (x - X // K) (K - 1) * (x - X // K) X i = 1 1 i X += K // 2 K // 2 X x = 1 1 x
S = input()
K = int(input())
X = 0
i = 1
while i < len(S):
  if S[i] == S[i - 1]:
    X += 1
    i += 1
  i += 1
X *= K
if S == S[0] * len(S) and len(S) % 2 == 1:
  X += K // 2
elif i == len(S) and S[0] == S[-1]:
  x = 1
  i = 2
  while i < len(S):
    if S[i] == S[i - 1]:
      x += 1
      i += 1
    i += 1
  X += (K - 1) * (x - X // K)
print(X)
