#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int dp[105][105];
int main(){
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
int n;
cin >> n;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
cin >> dp[i][j];
if(dp[i][j] == 0 && i != j) dp[i][j] = inf;
}
}
for(int k = 1; k <= n; k++){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
}
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(dp[i][j] == inf || i == j) cout << 0 << " ";
else cout << dp[i][j] << " ";
}
cout << '\n';
}
return 0;
}