#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int n; cin >> n; vector s(n); for (int i = 0; i < n; i++) { cin >> s[i]; reverse(s[i].begin(), s[i].end()); } string ans = ""; while (true) { bool non_empty = false; int mi_idx = -1; for (int i = 0; i < n; i++) { if (!s[i].empty()) { if (!non_empty || s[i].back() < s[mi_idx].back()) { mi_idx = i; } non_empty = true; } } if (!non_empty) { break; } ans += s[mi_idx].back(); s[mi_idx].pop_back(); } cout << ans << endl; }