s = gets.chomp
k = gets.chomp.to_i

def pp(o)
  STDERR.puts o.inspect
end

groups = []
current_count = 0
for i in 0..s.length-1 do
  current_count += 1
  if (s[i] != s[i+1]) or i==s.length-1 then
    groups.push(current_count)
    current_count = 0
  end
end
pp groups
# 前後でつながらない場合
if s[0] != s[-1] then
  pp 'A'
  sum = groups.map{|v| v/2}.inject(&:+) * k
else
  # 全部つながる場合
  if groups.length == 1 then
    pp 'B'
    sum = groups[0] * k /2
  else
  # 飛び飛びにつながる場合
    if k==1 then
      pp 'C'
      sum = groups.map{|v| v/2}.inject(&:+)
    else
      pp 'D'
      g_s = groups.clone
      g_m = groups.clone
      g_e = groups.clone
      g_s[-1] += groups[0]
      g_m[-1] += groups[0]
      g_m.delete_at(0)
      g_e.delete_at(0)
      sum = 0
      sum += g_s.map{|v| v/2}.inject(&:+)
      pp sum
      sum += (g_m.map{|v| v/2}.inject(&:+)) * (k-2)
      pp sum
      sum += g_e.map{|v| v/2}.inject(&:+)
      pp sum
    end
  end
end
# 前後でつながる場合
  

print "#{sum}\n"