#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; vector s; bool getNext(int k, int i, tuple& x) { int n = s[k].size(); if(i == n) return false; int j = i; int len = 0; while(j < n && s[k][j] == s[k][i]){ ++ j; ++ len; } if(j == n) x = make_tuple(s[k][i], '~', len, '~', k, j); else x = make_tuple(s[k][i], max(s[k][i], s[k][j]), len, s[k][j], k, j); return true; } int main() { int n; cin >> n; s.resize(n); for(int i=0; i> s[i]; set > select; for(int i=0; i x; getNext(i, 0, x); select.insert(x); } string ans; while(!select.empty()){ auto x = *select.begin(); select.erase(select.begin()); ans += string(get<2>(x), get<0>(x)); if(getNext(get<4>(x), get<5>(x), x)) select.insert(x); } cout << ans << endl; return 0; }