inputs = gets.to_s.chomp.chars
repeat = gets.to_i
lists = []
i = 0
while i < inputs.length do
  key = inputs[i]
  val = 1
  k = i + 1
  while k < inputs.length do
    if inputs[i] == inputs[k]
      val += 1
      k += 1
    else
      break
    end
  end
  list = [key, val]
  lists << list
  i = k
end
i = 1
while i < lists.length - 1  do
  count = 0
  count += lists[i][1] / 2
  i += 1
end
first = lists[0][1] / 2
if lists[0][0] == lists[lists.length - 1][0]
  middle = (lists[0][1] + lists[lists.length - 1][1]) / 2
else
  middle = lists[lists.length - 1][1] / 2 + lists[0][1] / 2
end
last = lists[lists.length - 1][1] / 2
puts first + count.to_i * repeat + middle * (repeat - 1) + last