#include <iostream>
#include <fstream>
#include <stdint.h>
const int32_t MAX_N = 100;
const int32_t MAX_DIST = 1000000000;
int32_t dists[MAX_N][MAX_N];
int32_t min(int32_t x, int32_t y) {
return (x < y) ? x : y;
}
int main() {
std::ifstream fin("royfloyd.in");
std::ofstream fout("royfloyd.out");
int32_t n;
fin >> n;
for(int32_t i = 0; i != n; ++i) {
for(int32_t j = 0; j != n; ++j)
fin >> dists[i][j];
}
for(int32_t i = 0; i != n; ++i) {
for(int32_t j = 0; j != n; ++j) {
if(i != j && !dists[i][j])
dists[i][j] = MAX_DIST;
}
}
for(int32_t k = 0; k != n; ++k) {
for(int32_t i = 0; i != n; ++i) {
for(int32_t j = 0; j != n; ++j)
dists[i][j] = min(dists[i][j], dists[i][k] + dists[k][j]);
}
}
for(int32_t i = 0; i != n; ++i) {
for(int32_t j = 0; j != n; ++j) {
if(dists[i][j] >= MAX_DIST)
dists[i][j] = 0;
}
}
for(int32_t i = 0; i != n; ++i) {
for(int32_t j = 0; j != n; ++j)
fout << dists[i][j] << ' ';
fout << '\n';
}
fin.close();
fout.close();
return 0;
}