Under construction

Still being built. Things may change

Restore the permutation

Interview

Time limit2sMemory limit1024 MB

Summary
Given an N by N comparison matrix, restore a permutation that produces it, or print -1 if no permutation matches.
Level

Easy3 of 10

Topics
Matrix, Sorting, Implementation
Solved
No attempts yet

Problem

A permutation of length NN is a sequence in which each integer from 11 to NN appears exactly once. For example, [1][1] and [3,1,4,2,5][3,1,4,2,5] are permutations, but [−1,0,1,3,2][-1,0,1,3,2] and [1,3,5,4][1,3,5,4] are not.

For a permutation PP of length NN, the comparison matrix AA is an N×NN \times N matrix. Each element AijA_{ij} is set as follows, based on how PiP_i compares with PjP_j.

  • If Pi>PjP_i > P_j, then Aij=−1A_{ij} = -1.
  • If Pi=PjP_i = P_j, then Aij=0A_{ij} = 0.
  • If Pi<PjP_i < P_j, then Aij=1A_{ij} = 1.

Given the comparison matrix AA, write a program that restores the permutation PP. If no permutation satisfies AA, print -1.

Input

The first line contains an integer NN. (1≤N≤10001 \leq N \leq 1000)

Each of the next NN lines contains a row of the comparison matrix AA. The ii-th line holds Ai1,Ai2,⋯ ,AiNA_{i1}, A_{i2}, \cdots, A_{iN}, separated by spaces. Every element of the matrix is −1-1, 00, or 11.

Output

If a permutation PP satisfies the comparison matrix AA, print P1,P2,⋯ ,PNP_1, P_2, \cdots, P_N separated by spaces, in order. If several permutations work, print any of them.

If no such permutation exists, print -1.

Examples1

  1. Example 1

    Input
    4
    0 1 -1 -1
    -1 0 -1 -1
    1 1 0 1
    1 1 -1 0
    
    Expected output
    3 4 1 2