#include <fstream>
using namespace std;
int dist[1005][1005];
int main()
{
ifstream cin("royfloyd.in");
ofstream cin("royfloyd.out");
int n,a;
cin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
cin>>a;
if(i!=j)
{
if(a==0)
dist[i][j]=10e6;
else
dist[i][j]=a;
}
}
for(int k=1;k<=n;k++)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
dist[i][j]=min(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]==10e6)
cout<<0<<" ";
else
cout<<dist[i][j]<<" ";
}
cout<<'\n';
}
return 0;
}