#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
const int INF = 1e9;
int dist[105][105];
int main() {
int n;
if (!(fin >> n)) return 0;
// citesc matricea si transform valorilor 0 (fara muchie) in INF
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
fin >> dist[i][j];
if (i != j && dist[i][j] == 0) {
dist[i][j] = INF;
}
}
}
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] < INF && dist[k][j] < INF) {
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
}
// afis matricea (0 daca nu exista drum)
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (dist[i][j] == INF) {
fout << 0 << " ";
} else {
fout << dist[i][j] << " ";
}
}
fout << "\n";
}
return 0;
}