eolymp
bolt
Try our new interface for solving problems
Problems

Absurdistan Roads

Absurdistan Roads

The people of Absurdistan discovered how to build roads only last year. After the discovery, every city decided to build their own road connecting their city with another city. Each newly built road can be used in both directions.

Absurdistan is full of surprising coincidences. It took all n cities precisely one year to build their roads. And even more surprisingly, in the end it was possible to travel from every city to every other city using the newly built roads.

You bought a tourist guide which does not have a map of the country with the new roads. It only contains a huge table with the shortest distances between all pairs of cities using the newly built roads. You would like to know between which pairs of cities there are roads and how long they are, because you want to reconstruct the map of the n newly built roads from the table of shortest distances.

Input

For each test case:

  • A line containing an integer n (2n2000) - the number of cities and roads.

  • n lines with n numbers each. The j-th number of the i-th line is the shortest distance from city i to city j. All distances between two distinct cities will be positive and at most 106. The distance from i to i will always be 0 and the distance from i to j will be the same as the distance from j to i.

Output

For each test case print n lines with three integers a b c denoting that there is a road between cities a and b (1a, bn) of length c (1c106), where ab. If there are multiple solutions, you can print any one and you can print the roads in any order. At least one solution is guaranteed to exist.

Print a blank line between every two test cases.

Time limit 1 second
Memory limit 128 MiB
Input example #1
4
0 1 2 1
1 0 2 1
2 2 0 1
1 1 1 0
4
0 1 1 1
1 0 2 2
1 2 0 2
1 2 2 0
3
0 4 1
4 0 3
1 3 0
Output example #1
2 1 1
4 1 1
4 2 1
4 3 1

2 1 1
3 1 1
4 1 1
2 1 1

3 1 1
2 1 4
3 2 3
Source 2013 ACM North Western European Regional Contest (NWERC), November 24, Problem A