#include <iostream>
using namespace std;
const int MAX_SIZE = 5;
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];
}
for (int k = 2; k <= line; ++k) {
if (mt[line][0] < mt[k - 1][0]) {
for (int col = 0; col <= size; ++col) {
int aux = mt[k - 1][col];
mt[k - 1][col] = mt[line][col];
mt[line][col] = aux;
}
}
}
}
for (int line = 1; line <= size; ++line) {
for (int col = 1; col <= size; ++col) {
cout << mt[line][col] << " ";
}
cout << "\n";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1BWF9TSVpFID0gNTsKCmludCBtYWluKCkgewogICAgaW50IHNpemUsIG10W01BWF9TSVpFICsgMV1bTUFYX1NJWkUgKyAxXTsKICAgIGNpbiA+PiBzaXplOwogICAgZm9yIChpbnQgbGluZSA9IDE7IGxpbmUgPD0gc2l6ZTsgKytsaW5lKSB7CiAgICAgICAgbXRbbGluZV1bMF0gPSAwOwogICAgICAgIGZvciAoaW50IGNvbCA9IDE7IGNvbCA8PSBzaXplOyArK2NvbCkgewogICAgICAgICAgICBjaW4gPj4gbXRbbGluZV1bY29sXTsKICAgICAgICAgICAgbXRbbGluZV1bMF0gKz0gbXRbbGluZV1bY29sXTsKICAgICAgICB9CiAgICAgICAgZm9yIChpbnQgayA9IDI7IGsgPD0gbGluZTsgKytrKSB7CiAgICAgICAgICAgIGlmIChtdFtsaW5lXVswXSA8IG10W2sgLSAxXVswXSkgewogICAgICAgICAgICAgICAgZm9yIChpbnQgY29sID0gMDsgY29sIDw9IHNpemU7ICsrY29sKSB7CiAgICAgICAgICAgICAgICAgICAgaW50IGF1eCA9IG10W2sgLSAxXVtjb2xdOwogICAgICAgICAgICAgICAgICAgIG10W2sgLSAxXVtjb2xdID0gbXRbbGluZV1bY29sXTsKICAgICAgICAgICAgICAgICAgICBtdFtsaW5lXVtjb2xdID0gYXV4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgZm9yIChpbnQgbGluZSA9IDE7IGxpbmUgPD0gc2l6ZTsgKytsaW5lKSB7CiAgICAgICAgZm9yIChpbnQgY29sID0gMTsgY29sIDw9IHNpemU7ICsrY29sKSB7CiAgICAgICAgICAgIGNvdXQgPDwgbXRbbGluZV1bY29sXSA8PCAiICI7CiAgICAgICAgfQogICAgICAgIGNvdXQgPDwgIlxuIjsKICAgIH0KICAgIHJldHVybiAwOwp9