#include <bits/stdc++.h>using namespace std;
int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; while(cin >> n){ vector<string> pos[110], neg[110]; for(int i = 0; i<n; i++){ string num; cin >> num; if(num[0] == '-') neg[num.length()].push_back(num); else pos[num.length()].push_back(num); } for(int i = 1; i<=100; i++){ if(!pos[i].empty()) sort(pos[i].begin(), pos[i].end()); if(!neg[i].empty()) sort(neg[i].begin(), neg[i].end()); } for(int i = 100; 0<i; i--) if(!neg[i].empty()) for(int k = neg[i].size()-1; 0<=k; k--) cout << neg[i][k] << endl; for(int i = 1; i<=100; i++) if(!pos[i].empty()) for(int k = 0; k<pos[i].size(); k++) cout << pos[i][k] << endl; }
return 0;}