#include <iostream>
using namespace std;
const int MAX_SIZE = 5;
int main() {
int size, mt[MAX_SIZE + 1][MAX_SIZE + 1];
cin >> size;
int lineSum[MAX_SIZE + 1];
for (int line = 1; line <= size; ++line) {
lineSum[line] = 0;
for (int col = 1; col <= size; ++col) {
cin >> mt[line][col];
lineSum[line] += mt[line][col];
}
for (int k = 2; k <= line; ++k) {
if (lineSum[line] < lineSum[k - 1]) {
int aux1 = lineSum[k - 1];
lineSum[k - 1] = lineSum[line];
lineSum[line] = aux1;
for (int col = 1; col <= size; ++col) {
int aux2 = mt[k - 1][col];
mt[k - 1][col] = mt[line][col];
mt[line][col] = aux2;
}
}
}
}
for (int line = 1; line <= size; ++line) {
for (int col = 1; col <= size; ++col) {
cout << mt[line][col] << " ";
}
cout << "\n";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1BWF9TSVpFID0gNTsKCmludCBtYWluKCkgewogICAgaW50IHNpemUsIG10W01BWF9TSVpFICsgMV1bTUFYX1NJWkUgKyAxXTsKICAgIGNpbiA+PiBzaXplOwogICAgaW50IGxpbmVTdW1bTUFYX1NJWkUgKyAxXTsKICAgIGZvciAoaW50IGxpbmUgPSAxOyBsaW5lIDw9IHNpemU7ICsrbGluZSkgewogICAgICAgIGxpbmVTdW1bbGluZV0gPSAwOwogICAgICAgIGZvciAoaW50IGNvbCA9IDE7IGNvbCA8PSBzaXplOyArK2NvbCkgewogICAgICAgICAgICBjaW4gPj4gbXRbbGluZV1bY29sXTsKICAgICAgICAgICAgbGluZVN1bVtsaW5lXSArPSBtdFtsaW5lXVtjb2xdOwogICAgICAgIH0KICAgICAgICBmb3IgKGludCBrID0gMjsgayA8PSBsaW5lOyArK2spIHsKICAgICAgICAgICAgaWYgKGxpbmVTdW1bbGluZV0gPCBsaW5lU3VtW2sgLSAxXSkgewogICAgICAgICAgICAgICAgaW50IGF1eDEgPSBsaW5lU3VtW2sgLSAxXTsKICAgICAgICAgICAgICAgIGxpbmVTdW1bayAtIDFdID0gbGluZVN1bVtsaW5lXTsKICAgICAgICAgICAgICAgIGxpbmVTdW1bbGluZV0gPSBhdXgxOwogICAgICAgICAgICAgICAgZm9yIChpbnQgY29sID0gMTsgY29sIDw9IHNpemU7ICsrY29sKSB7CiAgICAgICAgICAgICAgICAgICAgaW50IGF1eDIgPSBtdFtrIC0gMV1bY29sXTsKICAgICAgICAgICAgICAgICAgICBtdFtrIC0gMV1bY29sXSA9IG10W2xpbmVdW2NvbF07CiAgICAgICAgICAgICAgICAgICAgbXRbbGluZV1bY29sXSA9IGF1eDI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBmb3IgKGludCBsaW5lID0gMTsgbGluZSA8PSBzaXplOyArK2xpbmUpIHsKICAgICAgICBmb3IgKGludCBjb2wgPSAxOyBjb2wgPD0gc2l6ZTsgKytjb2wpIHsKICAgICAgICAgICAgY291dCA8PCBtdFtsaW5lXVtjb2xdIDw8ICIgIjsKICAgICAgICB9CiAgICAgICAgY291dCA8PCAiXG4iOwogICAgfQogICAgcmV0dXJuIDA7Cn0=