#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define mp make_pair #define pb push_back #define all(x) (x).begin(),(x).end() #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector vb; typedef vector vi; typedef vector vvb; typedef vector vvi; typedef pair pii; const int INF=1<<29; const double EPS=1e-9; const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1}; int main() { int N; cin >> N; std::vector v; int maxsize = 0; int sum = 0; for (int i = 0; i < N; i++) { string temp; cin >> temp; int n = temp.size(); sum += n; maxsize = max(maxsize, n); v.push_back(temp); } for (int i = 0; i < N; i++) { string add(maxsize - v[i].size() + 1, 'z' + 1); v[i] += add; } string ans = ""; for (int i = 0; i < sum; i++) { char minc = 'z' + 1; int mincj; int maxsize = 0; for (int j = 0; j < N; j++) { if (v[j][0] < minc || (v[j][0] == minc && v[j].size() > maxsize)) { minc = v[j][0]; mincj = j; maxsize = v[j].size(); } } ans += v[mincj][0]; v[mincj] = v[mincj].substr(1, v[mincj].size() - 1); } cout << ans << endl; return 0; }