class Array
  def fq
    return self.map do |e|
      self.count e
    end
  end
end

while 0 != n = gets.to_i
  a = gets.split.map(&:to_i)
  c, _a = 0, nil
  loop do
    _a = a.fq
    break if _a == a
    a = _a
    c += 1
  end
  puts c
  puts _a.join(" ")
end