Hamiltonian path

Print the lexicographically smallest path that visits every vertex once following directed edges, or -1 when it does not exist.

Hard8GraphGreedyTopological sortNo attempts yetTime limit1sMemory limit512 MB

Problem

A directed graph GG has NN vertices and N(N1)/2N(N-1)/2 edges. The vertices are numbered from 00 to N1N-1. For any two different vertices ii and jj, exactly one of the edge from ii to jj and the edge from jj to ii is present. Ignoring the directions, GG is a complete graph.

XX is the adjacency matrix of GG. When Xi,jX_{i,j} is +, the edge from ii to jj exists, and when it is -, that edge does not exist. Xi,iX_{i,i} is always ..

A Hamiltonian path of GG is a path of length NN that visits every vertex exactly once. GG can have many Hamiltonian paths, so find the one whose sequence of visited vertex numbers comes first in lexicographic order. Sequence aa comes before sequence bb when aa holds the smaller value at the first position where the two sequences differ.

Input

The first line contains the number of vertices NN. Each of the next NN lines contains one row of the adjacency matrix XX. The jj-th character of the ii-th of those lines is Xi,jX_{i,j}, and both lines and characters are numbered from 00.

Output

If GG has a Hamiltonian path, print the vertices of the lexicographically first Hamiltonian path in order on one line, separated by single spaces. Otherwise print 1-1.

Constraints

  • 2N1002 \le N \le 100