# A - Connection and Disconnection
# https://atcoder.jp/contests/agc039/tasks/agc039_a

S = list(input())
k = int(input())

S_cnt = 0
repS = S[:]
for i in range(1, len(S)):
  if repS[i] == repS[i - 1]:
    repS[i] = "*"
    S_cnt += 1

if all(i == j for i, j in zip(S, S[1:])):
  ans = len(S) * k // 2
else:
  if S[0] != S[-1]:
    ans = S_cnt * k
  else:
    l = 0
    for s in S:
      if s == S[0]:
        l += 1
      else:
        break
    r = 0
    for s in S[::-1]:
      if s == S[-1]:
        r += 1
      else:
        break
    ans = S_cnt * k - (l // 2 + r // 2 - (l + r) // 2) * (k - 1)

print(ans) S = list(input()) S list(input()) list input() input k = int(input()) k int(input()) int input() input S_cnt = 0 S_cnt 0 repS = S[:] repS S[:] S : for i in range(1, len(S)):
  if repS[i] == repS[i - 1]:
    repS[i] = "*"
    S_cnt += 1 i range(1, len(S)) range 1 len(S) len S if repS[i] == repS[i - 1]:
    repS[i] = "*"
    S_cnt += 1 repS[i] == repS[i - 1] repS[i] repS i repS[i - 1] repS i - 1 i 1 repS[i] = "*" repS[i] repS i "*" S_cnt += 1 S_cnt 1 if all(i == j for i, j in zip(S, S[1:])):
  ans = len(S) * k // 2
else:
  if S[0] != S[-1]:
    ans = S_cnt * k
  else:
    l = 0
    for s in S:
      if s == S[0]:
        l += 1
      else:
        break
    r = 0
    for s in S[::-1]:
      if s == S[-1]:
        r += 1
      else:
        break
    ans = S_cnt * k - (l // 2 + r // 2 - (l + r) // 2) * (k - 1) all(i == j for i, j in zip(S, S[1:])) all i == j i j ans = len(S) * k // 2 ans len(S) * k // 2 len(S) * k len(S) len S k 2 if S[0] != S[-1]:
    ans = S_cnt * k
  else:
    l = 0
    for s in S:
      if s == S[0]:
        l += 1
      else:
        break
    r = 0
    for s in S[::-1]:
      if s == S[-1]:
        r += 1
      else:
        break
    ans = S_cnt * k - (l // 2 + r // 2 - (l + r) // 2) * (k - 1) S[0] != S[-1] S[0] S 0 S[-1] S -1 ans = S_cnt * k ans S_cnt * k S_cnt k l = 0 l 0 for s in S:
      if s == S[0]:
        l += 1
      else:
        break
     s S if s == S[0]:
        l += 1
      else:
        break
     s == S[0] s S[0] S 0 l += 1 l 1 break r = 0 r 0 for s in S[::-1]:
      if s == S[-1]:
        r += 1
      else:
        break
     s S[::-1] S ::-1 -1 if s == S[-1]:
        r += 1
      else:
        break
     s == S[-1] s S[-1] S -1 r += 1 r 1 break ans = S_cnt * k - (l // 2 + r // 2 - (l + r) // 2) * (k - 1) ans S_cnt * k - (l // 2 + r // 2 - (l + r) // 2) * (k - 1) S_cnt * k S_cnt k (l // 2 + r // 2 - (l + r) // 2) * (k - 1) l // 2 + r // 2 - (l + r) // 2 l // 2 + r // 2 l // 2 l 2 r // 2 r 2 (l + r) // 2 l + r l r 2 k - 1 k 1 print(ans) print ans S_cnt = 0 0 S_cnt ans = len(S) * k // 2 len(S) * k // 2 ans ans = S_cnt * k - (l // 2 + r // 2 - (l + r) // 2) * (k - 1) S_cnt * k - (l // 2 + r // 2 - (l + r) // 2) * (k - 1) ans l = 0 0 l r += 1 1 r S_cnt += 1 1 S_cnt k = int(input()) int(input()) k S = list(input()) list(input()) S ans = S_cnt * k S_cnt * k ans r = 0 0 r repS = S[:] S[:] repS l += 1 1 l
# A - Connection and Disconnection
# https://atcoder.jp/contests/agc039/tasks/agc039_a

S = list(input())
k = int(input())

S_cnt = 0
repS = S[:]
for i in range(1, len(S)):
  if repS[i] == repS[i - 1]:
    repS[i] = "*"
    S_cnt += 1

if all(i == j for i, j in zip(S, S[1:])):
  ans = len(S) * k // 2
else:
  if S[0] != S[-1]:
    ans = S_cnt * k
  else:
    l = 0
    for s in S:
      if s == S[0]:
        l += 1
      else:
        break
    r = 0
    for s in S[::-1]:
      if s == S[-1]:
        r += 1
      else:
        break
    ans = S_cnt * k - (l // 2 + r // 2 - (l + r) // 2) * (k - 1)

print(ans)