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

res = 0
i = 0
while i < n - 1:
  if S[i] == S[i + 1]:
    res += 1
    i += 1
  i += 1

if S[0] != S[-1]:
  print(res * k)
else:
	i = 1
	while S[0] == S[i]:
		i += 1

	j = 1
	while S[-1] == S[-1 - j]:
		j += 1
	
	if i % 2 == 0 or j % 2 == 0:
		print(res * k)
	else:
		print(res * k + (k - 1))
  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 res = 0 res 0 i = 0 i 0 while i < n - 1:
  if S[i] == S[i + 1]:
    res += 1
    i += 1
  i += 1 i < n - 1 i n - 1 n 1 if S[i] == S[i + 1]:
    res += 1
    i += 1
   S[i] == S[i + 1] S[i] S i S[i + 1] S i + 1 i 1 res += 1 res 1 i += 1 i 1 i += 1 i 1 if S[0] != S[-1]:
  print(res * k)
else:
	i = 1
	while S[0] == S[i]:
		i += 1

	j = 1
	while S[-1] == S[-1 - j]:
		j += 1
	
	if i % 2 == 0 or j % 2 == 0:
		print(res * k)
	else:
		print(res * k + (k - 1))
  S[0] != S[-1] S[0] S 0 S[-1] S -1 print(res * k) print res * k res k i = 1 i 1 while S[0] == S[i]:
		i += 1

	 S[0] == S[i] S[0] S 0 S[i] S i i += 1 i 1 j = 1 j 1 while S[-1] == S[-1 - j]:
		j += 1
	
	 S[-1] == S[-1 - j] S[-1] S -1 S[-1 - j] S -1 - j -1 j j += 1 j 1 if i % 2 == 0 or j % 2 == 0:
		print(res * k)
	else:
		print(res * k + (k - 1))
  i % 2 == 0 or j % 2 == 0 i % 2 == 0 i % 2 i 2 0 j % 2 == 0 j % 2 j 2 0 print(res * k) print res * k res k print(res * k + (k - 1)) print res * k + (k - 1) res * k res k k - 1 k 1 res = 0 0 res i += 1 1 i j += 1 1 j i = 1 1 i S = list(input()) list(input()) S i += 1 1 i i = 0 0 i res += 1 1 res k = int(input()) int(input()) k j = 1 1 j n = len(S) len(S) n i += 1 1 i
S = list(input())
n = len(S)
k = int(input())
  
if len(set(S)) == 1:
  print((n * k) // 2)
  exit()

res = 0
i = 0
while i < n - 1:
  if S[i] == S[i + 1]:
    res += 1
    i += 1
  i += 1

if S[0] != S[-1]:
  print(res * k)
else:
	i = 1
	while S[0] == S[i]:
		i += 1

	j = 1
	while S[-1] == S[-1 - j]:
		j += 1
	
	if i % 2 == 0 or j % 2 == 0:
		print(res * k)
	else:
		print(res * k + (k - 1))
 