#include <bits/stdc++.h>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n, costs[101][101], d[101][101];
const int inf = 1e9;
int main() {
fin >> n;
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= n; j ++){
fin >> costs[i][j];
d[i][j] = costs[i][j] > 0 ? costs[i][j] : inf;
if(i == j) d[i][j] = 0;
}
for(int k = 1; k <= n; k ++) {
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= n; j ++) {
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
for(int i = 1; i <= n; i ++, fout << '\n')
for(int j = 1; j <= n; j ++)
if (d[i][j] == inf) fout << "0 ";
else fout << d[i][j] << ' ';
return 0;
}