s = gets.chomp
k = gets.to_i
prenum = 1
pre = s[0]
cnt = []
len = s.length
(len-1).times do |i|
  if s[i+1] == pre
    prenum += 1
  else
    cnt << prenum
    prenum = 1
  end
  pre = s[i+1]
end
cnt << prenum
sum = 0
l = cnt.length
if l == 1
  sum = len * k / 2
elsif s[0] == s[-1]
  (l-2).times do |i|
    sum += cnt[i+1]/2
  end
  sum *= k
  connect = (cnt[0] + cnt[-1]) / 2
  sum += connect * (k-1)
  sum += cnt[0]/2 + cnt[-1]/2
else
  cnt.each do |x|
    sum += x/2
  end
  sum *= k
end
puts sum