#P8053. Destroy the Death Star

    ID: 21237 Type: Default 1000ms 256MiB

Destroy the Death Star

Destroy the Death Star

You have infiltrated the Death Star by any means necessary. To trigger its self-destruct sequence, you need an array \(a\) of length \(n\). Although you do not know the array beforehand, your old friend Darth Vader has provided you with an \(n \times n\) matrix \(b\). In this matrix, for every \(i, j\) (with \(i \neq j\)), the element is defined as

[ b_{i,j} = a_i \operatorname{&} a_j ]

(where \(\operatorname{\&}\) denotes the bitwise AND operation). Unfortunately, the elements on the main diagonal, which should have been \(a_i \operatorname{\&} a_i = a_i\), have been destroyed by a lightsaber and are currently shown as 0. Your task is to recover any valid array \(a\) such that, for all \(i \neq j\), the equation \(b_{i,j} = a_i \operatorname{\&} a_j\) holds.

Hint: A valid approach is to set

[ a_i = \bigvee_{\substack{1 \le j \le n \ j \neq i}} b_{i,j} ]

where (\bigvee) denotes the bitwise OR operation.

inputFormat

The first line contains an integer \(n\) representing the size of the array and matrix.

The following \(n\) lines each contain \(n\) integers. The \(j\)-th integer in the \(i\)-th line is \(b_{i,j}\) (with the diagonal elements given as 0).

outputFormat

Output \(n\) integers on one line separated by a single space — a valid array \(a\) that satisfies \(b_{i,j} = a_i \operatorname{\&} a_j\) for all \(i \neq j\).

sample

2
0 2
2 0
2 2