#include <iostream>
using namespace std;
const int MAX_SIZE = 5;
int main() {
/*
Algoritm realizat pentru dimensiuni mari ale matricei
*/
int size, mt[MAX_SIZE + 1][MAX_SIZE + 1];
cin >> size;
int ascendingSums[MAX_SIZE + 1];
for (int line = 1; line <= size; ++line) {
mt[line][0] = 0;
ascendingSums[line] = 0;
for (int col = 1; col <= size; ++col) {
cin >> mt[line][col];
mt[line][0] += mt[line][col];
ascendingSums[line] += mt[line][col];
}
for (int k = 2; k <= line; ++k) {
if (ascendingSums[line] < ascendingSums[k - 1]) {
int aux = ascendingSums[k - 1];
ascendingSums[k - 1] = ascendingSums[line];
ascendingSums[line] = aux;
}
}
}
for (int i = 1; i <= size; ++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;
}