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

ans = 0
i = 0
while i < N-1:
  if S[i] == S[i+1]:
    ans += 1
    i += 1
  i += 1

if S[0] != S[N-1]:
  print(ans*K)
  exit()

a = 1
while S[0] == S[a]:
  a += 1

b = 1
while S[N-1] == S[N-1-b]:
  b += 1
print(ans*K - (K-1)*(a//2 + b//2 - (a+b)//2)) 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 len(set(S)) == 1:
  print((N*K)//2)
  exit() len(set(S)) == 1 len(set(S)) len set(S) set S 1 print((N*K)//2) print (N*K)//2 N*K N K 2 exit() exit ans = 0 ans 0 i = 0 i 0 while i < N-1:
  if S[i] == S[i+1]:
    ans += 1
    i += 1
  i += 1 i < N-1 i N-1 N 1 if S[i] == S[i+1]:
    ans += 1
    i += 1
   S[i] == S[i+1] S[i] S i S[i+1] S i+1 i 1 ans += 1 ans 1 i += 1 i 1 i += 1 i 1 if S[0] != S[N-1]:
  print(ans*K)
  exit() S[0] != S[N-1] S[0] S 0 S[N-1] S N-1 N 1 print(ans*K) print ans*K ans K exit() exit a = 1 a 1 while S[0] == S[a]:
  a += 1 S[0] == S[a] S[0] S 0 S[a] S a a += 1 a 1 b = 1 b 1 while S[N-1] == S[N-1-b]:
  b += 1 S[N-1] == S[N-1-b] S[N-1] S N-1 N 1 S[N-1-b] S N-1-b N-1 N 1 b b += 1 b 1 print(ans*K - (K-1)*(a//2 + b//2 - (a+b)//2)) print ans*K - (K-1)*(a//2 + b//2 - (a+b)//2) ans*K ans K (K-1)*(a//2 + b//2 - (a+b)//2) K-1 K 1 a//2 + b//2 - (a+b)//2 a//2 + b//2 a//2 a 2 b//2 b 2 (a+b)//2 a+b a b 2 N = len(S) len(S) N ans += 1 1 ans a = 1 1 a S = list(input()) list(input()) S b += 1 1 b K = int(input()) int(input()) K i = 0 0 i a += 1 1 a i += 1 1 i ans = 0 0 ans b = 1 1 b i += 1 1 i
S = list(input())
N = len(S)
K = int(input())
  
if len(set(S)) == 1:
  print((N*K)//2)
  exit()

ans = 0
i = 0
while i < N-1:
  if S[i] == S[i+1]:
    ans += 1
    i += 1
  i += 1

if S[0] != S[N-1]:
  print(ans*K)
  exit()

a = 1
while S[0] == S[a]:
  a += 1

b = 1
while S[N-1] == S[N-1-b]:
  b += 1
print(ans*K - (K-1)*(a//2 + b//2 - (a+b)//2))