#include <iostream>
#include <fstream>
#define nmax 105
#define inf 100000
using namespace std;
int n, best[nmax][nmax];
int main() {
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
f>>n;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++) {
f>>best[i][j];
if(best[i][j] == 0) best[i][j] = inf;
}
for(int k=1; k<=n; k++)
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
best[i][j] = min(best[i][j], best[i][k] + best[k][j]);
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) g<<(best[i][j]==inf || i==j? 0:best[i][j])<<" ";
g<<"\n";
}
return 0;
}