until (n = gets.to_i) == 0
  i = -1
  before_s = nil
  freq = {}
  current_s = gets.split(' ').map(&:to_i)
  freq = current_s.each_with_object({}) {|v, f| f[v] = (f[v] || 0) + 1 }
  until current_s == before_s
    i += 1
    n_freq = {}
    before_s = current_s
    current_s = current_s.map {|v|
      vv = freq[v]
      n_freq[vv] = (n_freq[vv] || 0) + 1
      vv
    }
    freq = n_freq
  end
  puts i, current_s.join(' ')
end