#include using namespace std; int main(void) { cin.tie(0); ios::sync_with_stdio(false); string res,s; vector v; int n; priority_queue , pair>, vector, pair>>, greater, pair>>> pque; cin >> n; for (int i = 0; i < n; i++) { cin >> s; v.push_back(s); } for (int i = 0; i < n; i++) { pque.push(make_pair(make_pair(v[i][0],0), make_pair(i, 0))); } while (!pque.empty()) { char ch = pque.top().first.first; int num = pque.top().first.second; int now = pque.top().second.first; int idx = pque.top().second.second; pque.pop(); res += ch; if (idx + 1 < v[now].length()) { pque.push(make_pair(make_pair(v[now][idx + 1],idx+1), make_pair(now, idx + 1))); } } cout << res << '\n'; return 0; }