#include <fstream>
using namespace std;
const int INF = 999999999;
int main(){
ifstream reader("royfloyd.in");
ofstream writer("royfloyd.out");
int n;
reader>>n;
int dist[101][101];
for(int i=0; i<n; i++)
for(int j=0; j<n; j++){
reader>>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)
if(dist[i][j] > dist[i][k] + dist[k][j])
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)
writer<<0;
else
writer<<dist[i][j]<<" ";
}
writer<<endl;
}
return 0;
}