#include <bits/stdc++.h>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
const int NMAX=1e2+8;
int n;
int dist[NMAX][NMAX];
int main() {
ios_base::sync_with_stdio(false);
fin.tie(nullptr);
fout.tie(nullptr);
fin >> n;
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
fin >> dist[i][j];
}
}
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]==0 || dist[k][j]==0) {
continue;
}
dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
}
}
}
for(int i=1; i<=n; i++,fout << "\n") {
for(int j=1; j<=n; j++) {
if(i==j) {
fout << 0 << " ";
}
else {
fout << dist[i][j] << " ";
}
}
}
return 0;
}