#include <fstream>
#include <limits>
#define MAX_N 105
int dist[MAX_N][MAX_N];
int main() {
std::ifstream fin("royfloyd.in");
std::ofstream fout("royfloyd.out");
int n;
fin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
fin >> dist[i][j];
if (dist[i][j] == 0 && i != j) {
dist[i][j] = std::numeric_limits<int>::max();
}
}
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (
dist[i][k] != std::numeric_limits<int>::max() &&
dist[k][j] != std::numeric_limits<int>::max() &&
dist[i][k] + dist[k][j] < dist[i][j]
) {
dist[i][j] = dist[i][k] + dist[k][j];
}
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (dist[i][j] == std::numeric_limits<int>::max()) {
fout << 0;
} else {
fout << dist[i][j];
}
if (j < n) {
fout << " ";
}
}
fout << "\n";
}
return 0;
}