def main(argv)
  s = gets.chomp
  k = gets.chomp.to_i

  ts = []
  t = s[0]
  (1...s.size).each do |i|
    if t[0] == s[i] then
      t += s[i]
    else
      ts.push(t)
      t = s[i]
    end
  end
  ts.push(t)

  if ts.size == 1 then
    puts ((s.size * k) / 2).to_s
  else
    c = ts.map{|t| t.size / 2}.reduce(:+) * k
    if ts[0][0] == ts[ts.size - 1][0] then
      a = ts[0].size
      b = ts[ts.size - 1].size
      c -= ((a / 2) + (b / 2) - ((a + b) / 2)) * (k - 1)      
    end
    puts c.to_s
  end
end

if self.to_s == 'main' then
  main(ARGV)
end