N = gets.to_i A = N.times.map { gets.to_i } counter = Hash.new(0) A.each do |a| counter[a] += 1 end nums = [*0...N].sort_by { |i| -counter[i] } ans = Array.new(N, -1) nums.each do |n| ok = false N.times do |i| next if ans[i] != -1 next if A[i] == n ok = true ans[i] = n break end if not ok puts -1 exit end end puts ans