Under construction

Still being built. Things may change

Death Star

Time limit1sMemory limit256 MB

Summary
Recover the lexicographically smallest sequence whose pairwise bitwise AND values match the given off-diagonal matrix.
Level

Medium4 of 10

Topics
Bit manipulation
Solved
No attempts yet

Problem

Ivan, a young Jedi, has been sent to infiltrate the Death Star and destroy it. Destroying it takes a sequence of NN non-negative integers a1,a2,…,aNa_1, a_2, \dots, a_N, and Ivan does not have that sequence. What he has is a note from his old friend Darth Vader, and the note states the condition the sequence must satisfy.

The note holds a square matrix of size NN. The value mijm_{ij} in row ii and column jj is the bitwise and of aia_i and aja_j. A lightsaber damaged the note, so the main diagonal is unreadable, and the input gives it as 0.

Several sequences can satisfy the condition, and at least one always exists. Recover the one that comes first in lexicographic order.

Input

The first line has the size of the matrix NN (1≤N≤10001 \le N \le 1000).

Each of the next NN lines has one row of the matrix: NN integers mijm_{ij} (0≤mij≤1090 \le m_{ij} \le 10^9) separated by single spaces. Every diagonal value miim_{ii} is 0, and mij=mjim_{ij} = m_{ji} holds whenever i≠ji \ne j. At least one valid sequence exists, and every element of it is at most 10910^9.

Output

Print on one line the lexicographically smallest sequence that satisfies the condition, as NN integers separated by single spaces.

Lexicographic comparison reads two sequences from the first element and takes the one with the smaller value at the first position where they differ.

Examples5

  1. Example 1

    Input
    3
    0 1 1
    1 0 1
    1 1 0
    
    Expected output
    1 1 1
    
  2. Example 2

    Input
    5
    0 0 1 1 1
    0 0 2 0 2
    1 2 0 1 3
    1 0 1 0 1
    1 2 3 1 0
    
    Expected output
    1 2 3 1 3
    
  3. Example 3

    Input
    1
    0
    
    Expected output
    0
    
  4. Example 4

    Input
    2
    0 0
    0 0
    
    Expected output
    0 0
    
  5. Example 5

    Input
    2
    0 1000000000
    1000000000 0
    
    Expected output
    1000000000 1000000000