#include<bits/stdc++.h> using namespace std; int main() { int t; while(cin>>t) { int m=0,n; string s[t],a[t]; for(int i=0;i<t;i++) { cin>>s[i]; } if(t==2&&(s[0][0]=='-'&&s[1][0]==s[0][0])) { sort(s,s+t); cout<<s[1]<<endl; cout<<s[0]<<endl; continue; } sort(s,s+t); for(int i=t-1;i>=0;i--) { for(int j=t-1;j>=0;j--) { if((s[i][0]=='-'&&s[i][0]==s[j][0])&&s[i].length()<s[j].length()) { string p=s[i]; s[i]=s[j]; s[j]=p; //cout<<s[i]<<" "<<s[j]<<endl; continue; } else if((s[i][0]=='-'&&s[i][0]==s[j][0])&&s[i].length()>s[j].length()) continue; if(s[i][0]!='-'&&s[j][0]=='-') { string p=s[i]; s[i]=s[j]; s[j]=p; //cout<<s[i]<<" "<<s[j]<<endl; continue; } else if(s[i][0]=='-'&&s[j][0]!='-') continue; if(s[i].length()>s[j].length()) { string p=s[i]; s[i]=s[j]; s[j]=p; //cout<<s[i]<<" "<<s[j]<<endl; continue; } if(s[i].length()==s[j].length()) { //printf("1111\n"); for(int l=0;l<s[i].length();l++) { // printf("%c %c\n",s[i][0],s[j][0]); if(s[i][l]<s[j][l]&&(s[i][0]=='-'&&s[j][0]=='-')) { // printf("sa\n"); string p=s[i]; s[i]=s[j]; s[j]=p; //rintf("break\n"); break; } if(s[i][l]>s[j][l]) { string p=s[i]; s[i]=s[j]; s[j]=p; //rintf("break\n"); break; } else if(s[i][l]<s[j][l]) break; } } } } for(int i=0;i<t;i++) cout<<s[i]<<endl; } }