Sum of a Sequence

Interview

Time limit1sMemory limit256 MB

Summary
Given an N by N table holding Ai+Aj for every pair of distinct indices and 0 on the diagonal, recover the original positive sequence A.
Level

Medium5 of 10

Topics
Math, Array, Implementation, Brute force
Solved
No attempts yet

Problem

There is a sequence of positive integers A=(A1,A2,…,AN)A = (A_1, A_2, \dots, A_N) of length NN. You are given a table SS that collects the sum of every pair of distinct elements of the sequence. That is, S(i,j)=Ai+AjS(i, j) = A_i + A_j when i≠ji \neq j, and S(i,j)=0S(i, j) = 0 when i=ji = j.

Given the table SS, write a program that reconstructs the original sequence AA.

Input

The first line contains the length of the sequence NN. (2≤N≤10002 \le N \le 1000)

Each of the next NN lines contains NN integers. The jj-th integer on the ii-th line is S(i,j)S(i, j), where S(i,j)=Ai+AjS(i, j) = A_i + A_j when i≠ji \neq j and S(i,j)=0S(i, j) = 0 when i=ji = j. Every element of the sequence is a positive integer not greater than 10510^5.

The sequence AA corresponding to the given table SS is always unique.

Output

Print the elements of the sequence AA in order on the first line, separated by spaces.

Examples2

  1. Example 1

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

    Input
    4
    0 3 6 7
    3 0 5 6
    6 5 0 9
    7 6 9 0
    
    Expected output
    2 1 4 5