#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
ifstream fcin("royfloyd.in");
ofstream fcout("royfloyd.out");
const int INF = 1e9;
int main()
{
int n;
fcin >> n;
vector<vector<int>> dist(n, vector<int>(n));
for (int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
{
fcin >> dist[i][j];
if (i != j && dist[i][j] == 0)
dist[i][j] = INF;
}
for (int k = 0; k < n; k++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (dist[i][k] < INF && dist[k][j] < INF)
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
if (dist[i][j] == INF)
fcout << 0 << " ";
else
fcout << dist[i][j] << " ";
fcout << endl;
}
}