#include #define rep(i,a,b) for(int i=int(a);i b.size())return a[i-1] < a[i]; else return b[i-1] < b[i]; } main(){ int N; cin >> N; //priority_queue, comp() > que; //priority_queue, greater > que; priority_queue, function > que( [](string a, string b){ //cout << a << " " << b << " " << a.size() << " " << b.size()<< endl; int i; for(i = 0;i < min(a.size(), b.size()); i++){ if(a[i] != b[i])return a[i] > b[i]; } if(a.size() > b.size())return a[i-1] <= a[i]; else return b[i-1] <= b[i]; } ); rep(i,0,N){ string s; cin >> s; que.push(s); } string ans; while(!que.empty()){ auto str = que.top(); //cout << "top:" << str << endl; que.pop(); ans.push_back(str[0]); if(str.size() != 1)que.push(str.substr(1)); } cout << ans << endl; }