245D.md (2690B)
1 Source: https://codeforces.com/problemset/problem/245/D 2 3 D. Restoring Table 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation. 22 23 For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative integers *a*1, *a*2, ..., *a**n*. He also wrote a square matrix *b* of size *n* × *n*. The element of matrix *b* that sits in the *i*-th row in the *j*-th column (we'll denote it as *b**ij*) equals: 24 25 * the "bitwise AND" of numbers *a**i* and *a**j* (that is, *b**ij* = *a**i* & *a**j*), if *i* ≠ *j*; 26 * -1, if *i* = *j*. 27 28 Having written out matrix *b*, Polycarpus got very happy and wiped *a* off the blackboard. But the thing is, the teacher will want this sequence to check whether Polycarpus' calculations were correct. Polycarus urgently needs to restore the removed sequence of integers, or else he won't prove that he can count correctly. 29 30 Help Polycarpus, given matrix *b*, restore the sequence of numbers *a*1, *a*2, ..., *a**n*, that he has removed from the board. Polycarpus doesn't like large numbers, so any number in the restored sequence mustn't exceed 109. 31 32 Input 33 34 The first line contains a single integer *n* (1 ≤ *n* ≤ 100) — the size of square matrix *b*. Next *n* lines contain matrix *b*. The *i*-th of these lines contains *n* space-separated integers: the *j*-th number represents the element of matrix *b**ij*. It is guaranteed, that for all *i* (1 ≤ *i* ≤ *n*) the following condition fulfills: *b**ii* = -1. It is guaranteed that for all *i*, *j* (1 ≤ *i*, *j* ≤ *n*; *i* ≠ *j*) the following condition fulfills: 0 ≤ *b**ij* ≤ 109, *b**ij* = *b**ji*. 35 36 Output 37 38 Print *n* non-negative integers *a*1, *a*2, ..., *a**n* (0 ≤ *a**i* ≤ 109) — the sequence that Polycarpus wiped off the board. Separate the numbers by whitespaces. 39 40 It is guaranteed that there is sequence *a* that satisfies the problem conditions. If there are multiple such sequences, you are allowed to print any of them. 41 42 Examples 43 44 Input 45 46 ``` 47 1 48 -1 49 ``` 50 51 Output 52 53 ``` 54 0 55 ``` 56 57 Input 58 59 ``` 60 3 61 -1 18 0 62 18 -1 0 63 0 0 -1 64 ``` 65 66 Output 67 68 ``` 69 18 18 0 70 ``` 71 72 Input 73 74 ``` 75 4 76 -1 128 128 128 77 128 -1 148 160 78 128 148 -1 128 79 128 160 128 -1 80 ``` 81 82 Output 83 84 ``` 85 128 180 148 160 86 ``` 87 88 Note 89 90 If you do not know what is the "bitwise AND" operation please read: http://en.wikipedia.org/wiki/Bitwise_operation.