s = gets.chomp
k = gets.to_i
n = s.size
ss = s*2

t = 0
(1..n-1).each do |i|
  if s[i-1] == s[i]
    t += 1
    s[i] = '*'
  end
end

t2 = 0
(1..n*2-1).each do |i|
  if ss[i-1] == ss[i]
    t2 += 1
    ss[i] = '*'
  end
end

if n == 1
  puts t
else
  puts t + (t2-t)*(k-1)
end
