#include <fstream>
#include <vector>
#include <stack>
#include <queue>
#include <climits>
#define NMAX 103
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n;
long long int dist[NMAX][NMAX];
int main()
{
fin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
int cost;
fin >> cost;
if (cost == 0)
{
//nu pot ajunge pornind din nodul i in j
dist[i][j] = INT_MAX;
}
else {
dist[i][j] = cost;
}
}
dist[i][i] = 0;
}
//calculez distantele folosindu-ma de un nod auxiliar
//ideea e urmatoarea daca costul de la nod1->nod2 e mai mare decat daca am trece prin aux(nod1->aux + aux->nod2) modific
//practic merg pe autostrazi(drumurile cu costuri minime) ca sa ajung la orase
for(int aux = 1; aux <= n; aux++)
{
//nod1 si nod2 sunt practic capetele
for (int nod1 = 1; nod1 <= n; nod1++)
{
for (int nod2 = 1; nod2 <= n; nod2++)
{
if (dist[nod1][nod2] > dist[nod1][aux] + dist[aux][nod2])
{
dist[nod1][nod2] = dist[nod1][aux] + dist[aux][nod2];
}
}
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (i == j)
{
fout << "0 ";
}
else {
if (dist[i][j] == INT_MAX)
{
fout << "0 ";
}
else {
fout << dist[i][j]<<" ";
}
}
}
fout << "\n";
}
return 0;
}