while gets.chomp.to_i != 0
  sequence = gets.split
  before_sequence = sequence
  count = 0
  while true
    sequence = sequence.map {|item| sequence.count(item)}
    break if before_sequence == sequence
    before_sequence = sequence
    count += 1
  end
  puts count, sequence.join(" ")
end