s=gets.chomp
f=s[0]
sl=s.length-1
k=gets.chomp.to_i
n=0
n2=0
i=0
if s.split('').all?{|x| x==f }
  puts s.length*k/2
else
  s.each_char do |c|
    if i==0
      i+=1
      next
    end
    if s[i-1]==c
      s[i]='0'
      n +=1
    end
    if i==sl && f==c
      n2+=1
    end
    i+=1
  end
  bs=n*k
  cb=n2*(k-1)
  puts(bs+cb)
end