S = list(input())
K = int(input())
N = len(S)
left = 1
while left < N and S[0] == S[left]:
    left += 1
right = 0
while N - 1 - right and S[0] == S[N - 1 - right]:
    right += 1
S += S
cnt = 0
for i in range(len(S) - 1):
    if S[i + 1] == S[i]:
        S[i + 1] = 'A'
        cnt += 1
if left + right < N and left % 2 != 0 and right % 2 != 0:
    print(max(0, (cnt + 1) * (K // 2) + ((cnt + 1) // 2) * int(K % 2 != 0) - 1))
else:
    print(cnt * (K // 2) + (cnt // 2) * int(K % 2 != 0)) S = list(input()) S list(input()) list input() input K = int(input()) K int(input()) int input() input N = len(S) N len(S) len S left = 1 left 1 while left < N and S[0] == S[left]:
    left += 1 left < N and S[0] == S[left] left < N left N S[0] == S[left] S[0] S 0 S[left] S left left += 1 left 1 right = 0 right 0 while N - 1 - right and S[0] == S[N - 1 - right]:
    right += 1 N - 1 - right and S[0] == S[N - 1 - right] N - 1 - right N - 1 N 1 right S[0] == S[N - 1 - right] S[0] S 0 S[N - 1 - right] S N - 1 - right N - 1 N 1 right right += 1 right 1 S += S S S cnt = 0 cnt 0 for i in range(len(S) - 1):
    if S[i + 1] == S[i]:
        S[i + 1] = 'A'
        cnt += 1 i range(len(S) - 1) range len(S) - 1 len(S) len S 1 if S[i + 1] == S[i]:
        S[i + 1] = 'A'
        cnt += 1 S[i + 1] == S[i] S[i + 1] S i + 1 i 1 S[i] S i S[i + 1] = 'A' S[i + 1] S i + 1 i 1 'A' cnt += 1 cnt 1 if left + right < N and left % 2 != 0 and right % 2 != 0:
    print(max(0, (cnt + 1) * (K // 2) + ((cnt + 1) // 2) * int(K % 2 != 0) - 1))
else:
    print(cnt * (K // 2) + (cnt // 2) * int(K % 2 != 0)) left + right < N and left % 2 != 0 and right % 2 != 0 left + right < N and left % 2 != 0 left + right < N left + right left right N left % 2 != 0 left % 2 left 2 0 right % 2 != 0 right % 2 right 2 0 print(max(0, (cnt + 1) * (K // 2) + ((cnt + 1) // 2) * int(K % 2 != 0) - 1)) print max(0, (cnt + 1) * (K // 2) + ((cnt + 1) // 2) * int(K % 2 != 0) - 1) max 0 (cnt + 1) * (K // 2) + ((cnt + 1) // 2) * int(K % 2 != 0) - 1 (cnt + 1) * (K // 2) + ((cnt + 1) // 2) * int(K % 2 != 0) (cnt + 1) * (K // 2) cnt + 1 cnt 1 K // 2 K 2 ((cnt + 1) // 2) * int(K % 2 != 0) (cnt + 1) // 2 cnt + 1 cnt 1 2 int(K % 2 != 0) int K % 2 != 0 K % 2 K 2 0 1 print(cnt * (K // 2) + (cnt // 2) * int(K % 2 != 0)) print cnt * (K // 2) + (cnt // 2) * int(K % 2 != 0) cnt * (K // 2) cnt K // 2 K 2 (cnt // 2) * int(K % 2 != 0) cnt // 2 cnt 2 int(K % 2 != 0) int K % 2 != 0 K % 2 K 2 0 S = list(input()) list(input()) S left += 1 1 left K = int(input()) int(input()) K cnt = 0 0 cnt N = len(S) len(S) N right = 0 0 right right += 1 1 right S += S S S cnt += 1 1 cnt left = 1 1 left
S = list(input())
K = int(input())
N = len(S)
left = 1
while left < N and S[0] == S[left]:
    left += 1
right = 0
while N - 1 - right and S[0] == S[N - 1 - right]:
    right += 1
S += S
cnt = 0
for i in range(len(S) - 1):
    if S[i + 1] == S[i]:
        S[i + 1] = 'A'
        cnt += 1
if left + right < N and left % 2 != 0 and right % 2 != 0:
    print(max(0, (cnt + 1) * (K // 2) + ((cnt + 1) // 2) * int(K % 2 != 0) - 1))
else:
    print(cnt * (K // 2) + (cnt // 2) * int(K % 2 != 0))
