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 (2 ≤ n ≤ 2000) - 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
10^6
. 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 (1 ≤ a, b ≤ n) of length c (1 ≤ c ≤ 10^6
), where a ≠ b. 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.