#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},dy[]={0,-1,0,1}; int N; char ifcase(vector &s, int j) { char c = 'z' + 1; for (int i = 0; i < N; ++i) { if (s[i].size() == 0) continue; if (i == j) { if (s[i].size() == 1) continue; c = min(c, s[i][1]); } else { c = min(c, s[i][0]); } } return c; } int main(int argc, char const *argv[]) { cin >> N; std::vector s; for (int i = 0; i < N; ++i) { string tmp; cin >> tmp; s.push_back(tmp); } sort(s.begin(), s.end()); reverse(s.begin(), s.end()); bool flag = true; string T; while(flag) { flag = false; char c = 'z' + 1; char t = 'z' + 1; int ci = 0; for (int i = 0; i < N; ++i) { if (s[i].size() == 0) continue; c = min(c, s[i][0]); } for (int i = 0; i < N; ++i) { if (s[i].size() == 0) continue; if (c == s[i][0]) { if (t > ifcase(s, i)) { ci = i; t = ifcase(s, i); flag = true; } } } if (flag) { s[ci] = s[ci].substr(1); //cout << "debug" << s[ci] << endl; T += c; } } for (int i = 0; i < N; ++i) { if (s[i].size() == 0) continue; T += s[i][0]; } cout << T << endl; return 0; }