s=gets.chomp
f=s[0]
sl=s.length-1
k=gets.chomp.to_i
n=0
n2=0
s.each_char.with_index do |c,i|
  next if i==0
  if s[i-1]==c
    s[i]='0'
    n +=1
  else
    if i==sl && f==c
      n2+=1
    end
  end
end
bs=n*k
cb=n2*k-1
puts(cb < 0 ? bs : bs+cb)