s=gets.chomp
k=gets.chomp.to_i


if s.split('').all?{|x|x==s[0]}
  puts s.length*k/2
else
  n=0
  s.each_char.with_index do |c,i|
    next if i == 0
    n+=1 if s[i-1]==c
  end
  puts n

  a=0
  s.each_char.with_index do |c,i|
    next if i == 0
    break if s[0] != c
    a+=1
  end

  b=0
  rs=s.reverse
  rs.each_char.with_index do |c,i|
    next if i == 0
    break if rs[0] != c
    b+=1
  end
end