# coding: utf-8

S = gets.chomp
K = gets.to_i

n=0
T=S*4
for i in 1..T.length-2 do 
  if T[i] == T[i-1] then
    T[i] = ((T[i-1].ord + T[i+1].ord+1)%26 + 97).chr
    n+=1
  end      
end
if T[T.length-1] == T[T.length-2] then
  n+=1
end
n=(n/4)*K
print(n)

