#include using namespace std; int n,m,zc,len,i,k,cnt[28],p[1000100],st[1000100],e[1000100],last[1000100][28]; vector c[28]; char s[1000100]; void mov(int i) { putchar('a'+i); zc=0; for (int j=0; j0) cnt[i]++; } st[n]=len; for (i=0; i<26; i++) c[i].reserve(cnt[i]); for (i=0; i0 && cnt[i]==c[i].size()) break; if (i<26) { mov(i); continue; } for (k=i=0; i<26; i++) if (c[i].size()>c[k].size() || (c[i].size()==c[k].size() && cnt[i]