#include<iostream>
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
const int MAX = 100;
int dist[MAX +1][MAX +1];
int main(){
int n;
fin>> n;
for(int i = 1; i<=n; i++){
for(int j=1;j<=n;j++){
fin>>dist[i][j];
if(i != j && dist[i][j] == 0){
dist[i][j] = 1e9;
}
}
}
for(int k = 1;k<= n;k++){
for(int i =1;i<= n;i++){
for(int j =1;j<= n;j++){
if(dist[i][j]> dist[i][k] + dist[k][j]){
dist[i][j] = dist[i][k] + dist[k][j];
}
}
}
}
for(int i = 1; i<=n; i++){
for(int j=1;j<=n;j++){
if(dist[i][j] == 1e9) fout << 0 << " ";
else fout << dist[i][j] << " ";
}
fout << "\n";
}
}