s = gets.chomp.split('')
k = gets.chomp.to_i
prev = s[0]
list = []
current = 1
(1..s.count).each do |i|
  if i < s.count
    if prev == s[i]
      current += 1
    else
      list << current
      current = 1
    end
    prev = s[i]
  else
    list << current
  end
end
count = 0
if list.count == 1
  count = s.count * k / 2
else
  base = 0
  list.each do |i|
    base += i / 2
  end
  count = base * k
  head = s.slice(0...list.first)
  tail = s.reverse.slice(0...list.last).reverse
  if head[0] == tail[0] && head.count % 2 == 1 && tail.count % 2 == 1
    count += k - 1
  end
end
puts count