//
// Created by Bianca Grava on 23/11/2026.
//
#include<iostream>
#include<vector>
#include<fstream>
#include<climits>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
int main() {
int n;
in>>n;
vector<vector<int>> graph(n+1, vector<int>(n+1));
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++) {
in>>graph[i][j];
if (i!=j&&graph[i][j]==0)
graph[i][j]=INT_MAX;
}
for (int k=1;k<=n;k++)
for (int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if (graph[i][j]>graph[i][k]+graph[k][j])
graph[i][j]=graph[i][k]+graph[k][j];
for (int i=1;i<=n;i++,out<<endl)
for(int j=1;j<=n;j++)
if(graph[i][j]==INT_MAX&&i!=j)
out<<0<<" ";
else
out<<graph[i][j]<<" ";
return 0;
}