#include <iostream>
using namespace std;
const int MAX_SIZE = 5;
const int MAX_VALUE = 10;
int sumFreq[MAX_SIZE * MAX_VALUE + 1];
int main() {
int size, mt[MAX_SIZE + 1][MAX_SIZE + 1];
cin >> size;
for (int line = 1; line <= size; ++line) {
mt[line][0] = 0;
for (int col = 1; col <= size; ++col) {
cin >> mt[line][col];
mt[line][0] += mt[line][col];
}
++sumFreq[mt[line][0]];
}
int ascendingSums[MAX_SIZE + 1], nextLinePos = 0;
for (int i = 0; i <= size * MAX_VALUE; ++i) {
if (sumFreq[i] == 1) {
ascendingSums[++nextLinePos] = i;
}
}
for (int i = 1; i <= nextLinePos; ++i) {
for (int line = i; line <= size; ++line) {
if (ascendingSums[i] == mt[line][0]) {
if (line != i) {
for (int col = 0; col <= size; ++col) {
int aux = mt[i][col];
mt[i][col] = mt[line][col];
mt[line][col] = aux;
}
}
for (int col = 1; col <= size; ++col) {
cout << mt[i][col] << " ";
}
line = size + 1;
cout << "\n";
}
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1BWF9TSVpFID0gNTsKY29uc3QgaW50IE1BWF9WQUxVRSA9IDEwOwppbnQgc3VtRnJlcVtNQVhfU0laRSAqIE1BWF9WQUxVRSArIDFdOwoKaW50IG1haW4oKSB7CiAgICBpbnQgc2l6ZSwgbXRbTUFYX1NJWkUgKyAxXVtNQVhfU0laRSArIDFdOwogICAgY2luID4+IHNpemU7CiAgICBmb3IgKGludCBsaW5lID0gMTsgbGluZSA8PSBzaXplOyArK2xpbmUpIHsKICAgICAgICBtdFtsaW5lXVswXSA9IDA7CiAgICAgICAgZm9yIChpbnQgY29sID0gMTsgY29sIDw9IHNpemU7ICsrY29sKSB7CiAgICAgICAgICAgIGNpbiA+PiBtdFtsaW5lXVtjb2xdOwogICAgICAgICAgICBtdFtsaW5lXVswXSArPSBtdFtsaW5lXVtjb2xdOwogICAgICAgIH0KICAgICAgICArK3N1bUZyZXFbbXRbbGluZV1bMF1dOwogICAgfQogICAgaW50IGFzY2VuZGluZ1N1bXNbTUFYX1NJWkUgKyAxXSwgbmV4dExpbmVQb3MgPSAwOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPD0gc2l6ZSAqIE1BWF9WQUxVRTsgKytpKSB7CiAgICAgICAgaWYgKHN1bUZyZXFbaV0gPT0gMSkgewogICAgICAgICAgICBhc2NlbmRpbmdTdW1zWysrbmV4dExpbmVQb3NdID0gaTsKICAgICAgICB9CiAgICB9CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuZXh0TGluZVBvczsgKytpKSB7CiAgICAgICAgZm9yIChpbnQgbGluZSA9IGk7IGxpbmUgPD0gc2l6ZTsgKytsaW5lKSB7CiAgICAgICAgICAgIGlmIChhc2NlbmRpbmdTdW1zW2ldID09IG10W2xpbmVdWzBdKSB7CiAgICAgICAgICAgICAgICBpZiAobGluZSAhPSBpKSB7CiAgICAgICAgICAgICAgICAgICAgZm9yIChpbnQgY29sID0gMDsgY29sIDw9IHNpemU7ICsrY29sKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGludCBhdXggPSBtdFtpXVtjb2xdOwogICAgICAgICAgICAgICAgICAgICAgICBtdFtpXVtjb2xdID0gbXRbbGluZV1bY29sXTsKICAgICAgICAgICAgICAgICAgICAgICAgbXRbbGluZV1bY29sXSA9IGF1eDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmb3IgKGludCBjb2wgPSAxOyBjb2wgPD0gc2l6ZTsgKytjb2wpIHsKICAgICAgICAgICAgICAgICAgICBjb3V0IDw8IG10W2ldW2NvbF0gPDwgIiAiOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgbGluZSA9IHNpemUgKyAxOwogICAgICAgICAgICAgICAgY291dCA8PCAiXG4iOwogICAgICAgICAgICB9IAogICAgICAgIH0KICAgIH0KICAgIHJldHVybiAwOwp9