A rookie programmer wrote a program in C++.
for (int w = 1; w < N; w = w + 1) {
for (int u = 1; u < N; u = u + 1) {
for (int v = 1; v < N; v = v + 1) {
g[u][v] = min(g[u][v], g[u][w] + g[w][v]);
}
}
}
The programmer launched his program on a set of graphs, and after some tedious waiting finally decided to take a look at the results. Which were, of course, disappointing. You guessed right --- the programmer wanted to calculate the matrix of the shortest distances between all nodes in the graph. However, the program was flawed. The programmer can fix everything himself, but waiting for the program to recalculate the results takes too much precious time. We suggest that you write a program that takes the results of the unlucky programmer's code and returns a matrix of the shortest distances.
The first line of the input file contains a single integer N (1≤N≤2,000). The ith of the following N lines contains a sequence of N numbers, with the jth number equal to the value g\[i]\[j] after running the algorithm provided above (0≤g\[i]\[j]≤9999).
Print N lines. The ith line must contain a sequence of space-separated numbers, with the jth number equal to the length of the shortest path in the graph between the nodes i and j, or the number 9999, if there is no path between these two nodes.