s = gets.chomp
k = gets.to_i
count = 0
flag = false

if s.split().to_a.uniq.length == 1
  flag = true
end

(1..s.length).each do |i|
  str_a = ("a".."z").to_a
  if s[i] == s[i - 1]
    str_a.delete(s[i - 1])
    str_a.delete(s[i + 1])
    s[i] = str_a.pop
    count += 1
  end
end

if flag
  puts count * k + (k / 2)
elsif s[0] == s[-1]
  puts count * k + (k - 1)
else
  puts count * k
end