s = gets
k = gets.to_i

c = 0
f = false
for i in 0..(s.length - 2)
  if s[i] == s[i + 1]
    if i == s.length - 2
      f = true
    end
    s[i + 1] = "!"
    c += 1
  end
end

if s[0] == s[s.length - 1]
  c += 1
end

c *= k

if f
  c -= 1
end

puts c
