#include <bits/stdc++.h>
using namespace std;
const int NMAX=100;
const int INF=1e9;
int n;
int d[NMAX+1][NMAX+1];
int main() {
freopen("royfloyd.in","r",stdin);
freopen("royfloyd.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n;
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j){
int x;
cin>>x;
if(i==j) d[i][j]=0;
else if(x==0) d[i][j]=INF;
else d[i][j]=x;
}
}
for(int k=1;k<=n;++k){
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j){
if(d[i][k]<INF && d[k][j]<INF && d[i][j]>d[i][k]+d[k][j]){
d[i][j]=d[i][k]+d[k][j];
}
}
}
}
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j){
if(d[i][j]==INF) cout<<0<<" ";
else cout<<d[i][j]<<" ";
}
cout<<"\n";
}
}