s = gets.chomp.split('')
t = [s[0]]
y = s[0]
num = 1
s[1..-1].each do |x|
  if x != y
    t << num if num > 1
    t << x
    y = x
    num = 1
  else
    num += 1
  end
end
t = t.join
k = gets.to_i
ans = 0
ans = 1 if s[0] == s[-1]
t.scan(/[0-9]+/).each do |u|
  ans += u.to_i / 2
end
puts ans * k