/*
https://infoarena.ro/problema/royfloyd
*/
#include <fstream>
#include <vector>
using namespace std;
const int INF = 1e6;
int main()
{
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
int n;
in >> n;
vector <vector <int>> d(n + 1, vector <int>(n + 1, INF));
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
int cost;
in >> cost;
if (i == j || cost != 0)
{
d[i][j] = cost;
}
}
}
in.close();
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] + d[k][j] < d[i][j])
{
d[i][j] = d[i][k] + d[k][j];
}
}
}
}
for (int i =1; i <= n; i++)
{
for (int j =1; j <= n; j++)
{
out << d[i][j] << " ";
}
out << "\n";
}
out.close();
return 0;
}