S = gets.chomp
K = gets.to_i
t = ""

# S = "issii"
# K = 2
# t = ""

K.times do |i|
  t += S
end



t_list = t.split("")
duplicate = []
temp = []
t_list.length.times do |i|
  s = t_list.shift
  if s != temp[0] && i !=0
    duplicate.push(temp)
    temp = []
  end

  temp.push(s)
end
duplicate.push(temp)
temp = []

k = 0
duplicate.each do |d|
  k += d.length / 2
end

puts k