#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fs first
#define sc second
#define pob pop_back
#define pub push_back
#define eps 1E-7
#define sz(a) a.size()
#define count_one __builtin_popcount;
#define count_onell __builtin_popcountll;
#define fastIO ios_base::sync_with_stdio(false)
#define PI (acos(-1.0))
#define linf (1LL<<62)//>4e18
#define inf (0x7f7f7f7f)//>2e9
#define MAXN 110
int v[MAXN][MAXN];
void read() {
#ifndef ONLINE_JUDGE
assert(freopen("royfloyd.in", "r", stdin));
assert(freopen("royfloyd.out", "w", stdout));
#endif
int n;
scanf("%d", &n);
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
scanf("%d", &v[i][j]);
for(int k = 0; k < n; ++k)
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
if(i != j && v[i][k] && v[k][j] && v[i][j] > v[i][k] + v[k][j])
v[i][j] = v[i][k] + v[k][j];
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j)
printf("%d ", v[i][j]);
printf("\n");
}
}
int main() {
read();
return 0;
}