#include using namespace std; const int MAX_N = 1e6 + 10; vector vs; char ans[MAX_N]; int at = 0; vector ap['z' - 'a' + 1]; int bsearch(int c, int st) { vector &v = ap[c]; size_t i, step; for(step = 1; step < v.size(); step *= 2); for(i = 0; step; step /= 2) { if(i + step < v.size() && v[i + step] <= st) i += step; } i++; if(i >= v.size()) return -1; return v[i]; } int included(const string &s); void include(const string &s) { int st = included(s); if(st == -1) return; for(size_t i = st; i < s.length(); ++i) { const char c = s[i]; ap[(int)c].push_back(at); ans[at] = c; at++; } } int included(const string &s) { int lo = 0; for(size_t j = 0; j < s.length(); ++j) { const char i = s[j]; int next = bsearch(i, lo); if(next == -1) return j; lo = next + 1; } return -1; } int main() { string s; while(cin >> s) { vs.push_back(s); } sort(vs.begin(), vs.end(), [](const string &s, const string &t) { return s.length() > t.length(); }); for(const auto &i: vs) { include(i); } cout << ans << "\n"; return 0; }