#include<fstream>
using namespace std;
ifstream cin("floyd.in");
ofstream cout("floyd.out");
const int NMAX = 100;
int dist[NMAX + 1][NMAX + 1];
int main() {
int n;
cin >> n;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
cin >> dist[i][j];
if(i != j && dist[i][j] == 0) {
dist[i][j] = 1e9;
}
}
}
for(int k = 1; k <= n; k++) {
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if(dist[i][j] > dist[i][k] + dist[k][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] == 1e9) {
cout << "0 ";
} else {
cout << dist[i][j] << " ";
}
}
cout << "\n";
}
}