s = gets.chomp.split(//)
k = gets.chomp.to_i

ans = 0

if s.all?{|c| s[0]==c}
  puts s.size * k / 2
  exit
end

if s.first == s.last
  firstc = 0
  lastc = 0
  s.each do |c|
    if c == s.first
      firstc += 1
    else
      break
    end
  end
  s.reverse.each do |c|
    if c == s.last
      lastc += 1
    else
      break
    end
  end
  # p [firstc, lastc]
  ans += firstc / 2 + lastc / 2
  ans += (firstc + lastc) * (k-1) /2
end

count = 0

ren = 1
(s.length-2).times do |i|
  if s[i] == s[i+1]
    ren += 1
  else
    if 0<ren
      count += ren/2
      ren = 1
    end
  end
end

puts ans + count * k
