//P1012
#include <iostream>
#include <string>
using namespace std;
bool cmp(string, string);
void sort(string*, int);
int main() {
int n;
cin >> n;
string* p = new string [n];
for (int i = 0; i < n; ++i)
cin >> p[i];
sort(p, n);
for (int i = 0; i < n; ++i)
cout << p[i];
delete [] p;
return 0;
}
bool cmp(string a, string b) { // 1: a > b 0: a < b
int max = a.size() > b.size() ? a.size() : b.size();
int a1, b1;
for (int i = 0; i < max; ++i) {
if (a.size() <= i)
a1 = a[a.size()-1];
else
a1 = a[i];
if (b.size() <= i)
b1 = b[b.size()-1];
else
b1 = b[i];
if (a1 != b1)
return a1 > b1;
else continue;
}
return 1;
}
void sort(string* ps, int n) {
for (int i = 0; i < n-1; ++i)
for (int j = n-1; j > i; --j)
if (cmp(ps[j], ps[j-1])) {
string t = ps[j];
ps[j] = ps[j-1];
ps[j-1] = t;
}
}
https://www.luogu.org/problemnew/show/P1012