#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 9999999;
const int kmax = 105;
class Task {
public:
void solve() {
read_input();
get_result();
print_output();
}
private:
int n;
int mat[kmax][kmax];
void read_input() {
ifstream fin("royfloyd.in");
fin >> n;
int x;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
fin >> x;
if (i != j && x == 0) {
mat[i][j] = inf;
}
else {
mat[i][j] = x;
}
}
}
fin.close();
}
void get_result() {
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
}
}
}
}
void print_output() {
ofstream fout("royfloyd.out");
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
fout << mat[i][j] << ' ';
}
fout << '\n';
}
fout.close();
}
};
int main() {
Task *task = new Task();
task->solve();
delete task;
return 0;
}