#include <fstream>
using namespace std;
ifstream fin ("royfloyd.in");
ofstream fout ("royfloyd.out");
int n;
long long cost[100+5][100+5];
int main(){
fin >> n;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
fin >> cost[i][j];
if(!cost[i][j]){
cost[i][j] = 1e9;
}
}
}
for(int k = 1; k <= n; k++){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(cost[i][j] > cost[i][k] + cost[k][j] && i != j){
cost[i][j] = cost[i][k] + cost[k][j];
}
}
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(cost[i][j] == 1e9){
cost[i][j] = 0;
}
fout << cost[i][j] << ' ';
}
fout << '\n';
}
return 0;
}