s = gets.chomp.split('')
k = gets.to_i
t = [s[0]]
u = []
y = s[0]
num = 1
s[1..-1].each do |x|
  if x != y
    u << num
    t << x
    y = x
    num = 1
  else
    num += 1
  end
end
u << num
ans = 0
if k == 1
elsif t.length == 1
  u[0] -= 1
  u << 1
  t << '*'
elsif t[0] == t[-1]
  if u[0].odd? && u[-1].odd?
    ans += 1
  end
end
t.length.times do |i|
  if t[i] == '*'
    ans += 1
  elsif u[i] > 1
    ans += u[i] / 2
  end
end

puts ans * k