def restore_sequence(n: int, matrix: List[List[int]]) -> List[int]:
    """
    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.
    
    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:  the "bitwise AND" of numbers a_{i} and a_{j} (that is, b_{ij} = a_{i} & a_{j}), if i ≠ j;  -1, if i = j.
    
    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.
    
    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 10^9.
    
    
    -----Input-----
    
    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} ≤ 10^9, b_{ij} = b_{ji}.
    
    
    -----Output-----
    
    Print n non-negative integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9) — the sequence that Polycarpus wiped off the board. Separate the numbers by whitespaces.
    
    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.
    
    
    -----Examples-----
    Input
    1
    -1
    
    Output
    0
    Input
    3
    -1 18 0
    18 -1 0
    0 0 -1
    
    Output
    18 18 0
    Input
    4
    -1 128 128 128
    128 -1 148 160
    128 148 -1 128
    128 160 128 -1
    
    Output
    128 180 148 160
    
    
    -----Note-----
    
    If you do not know what is the "bitwise AND" operation please read: http://en.wikipedia.org/wiki/Bitwise_operation.
    """


# Tests

def check(candidate):
    assert restore_sequence(1, [[-1]]) == [0]
    assert restore_sequence(3, [[-1, 18, 0], [18, -1, 0], [0, 0, -1]]) == [18, 18, 0]
    assert restore_sequence(4, [[-1, 128, 128, 128], [128, -1, 148, 160], [128, 148, -1, 128], [128, 160, 128, -1]]) == [128, 180, 148, 160]
    assert restore_sequence(5, [[-1, 0, 0, 0, 0], [0, -1, 1, 0, 0], [0, 1, -1, 0, 0], [0, 0, 0, -1, 0], [0, 0, 0, 0, -1]]) == [0, 1, 1, 0, 0]
    assert restore_sequence(6, [[-1, 1835024, 1966227, 34816, 68550800, 34832], [1835024, -1, 18632728, 306185992, 324272924, 289412624], [1966227, 18632728, -1, 40, 555155640, 16846864], [34816, 306185992, 40, -1, 306185000, 272666176], [68550800, 324272924, 555155640, 306185000, -1, 289481232], [34832, 289412624, 16846864, 272666176, 289481232, -1]]) == [69109907, 324818716, 555700411, 306220904, 928457660, 289521232]
    assert restore_sequence(7, [[-1, 1000000000, 999999488, 999999488, 1000000000, 1000000000, 999999488], [1000000000, -1, 999999488, 999999488, 1000000000, 1000000000, 999999488], [999999488, 999999488, -1, 999999999, 999999488, 999999488, 999999999], [999999488, 999999488, 999999999, -1, 999999488, 999999488, 999999999], [1000000000, 1000000000, 999999488, 999999488, -1, 1000000000, 999999488], [1000000000, 1000000000, 999999488, 999999488, 1000000000, -1, 999999488], [999999488, 999999488, 999999999, 999999999, 999999488, 999999488, -1]]) == [1000000000, 1000000000, 999999999, 999999999, 1000000000, 1000000000, 999999999]
    assert restore_sequence(8, [[-1, 56086, 2560, 35584, 6402, 18688, 22530, 256], [56086, -1, 2697, 35592, 6410, 18696, 22667, 257], [2560, 2697, -1, 10824, 10280, 10248, 10377, 8193], [35584, 35592, 10824, -1, 76040, 76040, 10248, 73984], [6402, 6410, 10280, 76040, -1, 76040, 14346, 73984], [18688, 18696, 10248, 76040, 76040, -1, 26632, 73984], [22530, 22667, 10377, 10248, 14346, 26632, -1, 9217], [256, 257, 8193, 73984, 73984, 73984, 9217, -1]]) == [56086, 56223, 10985, 109384, 80170, 92424, 31883, 75009]
    assert restore_sequence(9, [[-1, 0, 0, 2, 0, 2, 10, 2, 0], [0, -1, 17, 16, 16, 17, 0, 17, 16], [0, 17, -1, 16, 16, 17, 0, 17, 16], [2, 16, 16, -1, 16, 18, 2, 18, 16], [0, 16, 16, 16, -1, 16, 0, 16, 16], [2, 17, 17, 18, 16, -1, 2, 19, 16], [10, 0, 0, 2, 0, 2, -1, 2, 0], [2, 17, 17, 18, 16, 19, 2, -1, 16], [0, 16, 16, 16, 16, 16, 0, 16, -1]]) == [10, 17, 17, 18, 16, 19, 10, 19, 16]
    assert restore_sequence(10, [[-1, 16, 16, 0, 0, 0, 0, 16, 16, 16], [16, -1, 16, 3, 3, 2, 0, 17, 18, 16], [16, 16, -1, 0, 0, 0, 0, 16, 16, 16], [0, 3, 0, -1, 15, 10, 12, 1, 2, 0], [0, 3, 0, 15, -1, 10, 12, 1, 2, 0], [0, 2, 0, 10, 10, -1, 8, 0, 2, 0], [0, 0, 0, 12, 12, 8, -1, 0, 0, 0], [16, 17, 16, 1, 1, 0, 0, -1, 16, 16], [16, 18, 16, 2, 2, 2, 0, 16, -1, 16], [16, 16, 16, 0, 0, 0, 0, 16, 16, -1]]) == [16, 19, 16, 15, 15, 10, 12, 17, 18, 16]
    assert restore_sequence(2, [[-1, 0], [0, -1]]) == [0, 0]
check(restore_sequence)