#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define fst first #define scd second #define PB push_back #define MP make_pair #define rep(i,x) for(int i=0;i<(x);++i) #define rep1(i,x) for(int i=1;i<=(x);++i) #define rrep(i,x) for(int i=(x)-1;i>=0;--i) #define rrep1(i,x) for(int i=(x);i>=1;--i) #define int long long #define FOR(i,a,x) for(int i=(a);i<(x);++i) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define omajinai ios::sync_with_stdio(false);cin.tie(0) typedef long long ll; typedef vector vi; typedef pair pii; typedef vector vpii; templateT& max(T&a,T&b){if(a>=b)return a;return b;} templateT& min(T&a,T&b){if(abool chmax(T&a,T b){if(abool chmin(T&a,T b){if(a>b){a=b;return true;}return false;} templateT get(){T a;cin>>a;return a;} templateT rev(T a){reverse(all(a));return a;} templateistream&operator>>(istream&is,vector&vec){rep(i,vec.size())is>>vec[i];return is;} templatevector&sort(vector&a){sort(all(a));return a;} const int inf = 1e9; const ll linf = 3e18; const double eps = 1e-9; bool my_compare(string a, string b) { if (a == "") return false; if (b == "") return true; rep(i, min(a.size(), b.size())) { int aidx = a.size() - i - 1, bidx = b.size() - i - 1; if (a[aidx] == b[bidx]) continue; return a[aidx] < b[bidx]; } return a.size() >= b.size(); } signed main() { int N; cin >> N; vector S(N); int sum = 0; rep(i, N) cin >> S[i], reverse(all(S[i])), sum += S[i].size(); string T = ""; while (sum--) { sort(all(S), my_compare); T += S.front().back(); S.front().pop_back(); } cout << T << endl; }