#include <iostream>
#include <fstream>
#include <vector>
#define minim(a, b) ((a) < (b) ? (a) : (b))
using namespace std;
vector < vector < int > > mat(101);
int n;
void citire()
{
ifstream in("royfloyd.in");
in>>n;
int x;
for(int i = 0 ; i<n ; i++)
{
// mat[i].reseve(n);
for(int j = 0 ; j<n; j++)
{
in>>x;
mat[i].push_back(x);
}
}
in.close();
}
void afisare()
{
ofstream out("royfloyd.out");
for(int i = 0 ; i < n ;i++)
{
for(int j = 0 ; j < n ; j++)
out<<mat[i][j]<<" ";
out<<'\n';
}
}
int main()
{
citire();
for(int k = 1 ; k <= n ;k++)
for(int i = 1 ; i<= n ;i++)
for(int j = 1 ; j <= n ;j++)
mat[i-1][j-1] = minim(mat[i-1][k-1] + mat[k-1][j-1] , mat[i-1][j-1]);
afisare();
return 0;
}