#include using namespace std; #define DEBUG 0 #define debug(...) if(DEBUG)fprintf(stderr, __VA_ARGS__); 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) { c -= 'a'; 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) { debug("Trying to include %s\n", s.c_str()); int st = included(s); if(st == -1) return; debug("including just %s\n", s.c_str() + st); for(size_t i = st; i < s.length(); ++i) { const char c = s[i]; ap[(int)c - 'a'].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; }