def cal(t, u)
  num = 0
  t.length.times do |i|
    num += u[i] / 2
  end
  num
end

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

if t.length == 1
  puts k * u[0] / 2
elsif t[0] == t[-1]
  num = cal(t, u) * k
  x = u[0]/2 + u[-1]/2 - (u[0] + u[-1]) / 2
  num -= x * (k-1)
  puts num
else
  puts cal(t, u) * k
end