#include #include struct T{ int next[27]; int last_i; }; T mem[50000]; int counter; char res[512]; char tmp[512]; int len_res; int count; void built_trie(char *c) { int index=0; while(*c) { if (mem[index].next[*c-'a']==-1) { mem[index].next[*c-'a']=counter; for(int j=0; j<27; j++) mem[counter].next[j]=-1; counter++; } index=mem[index].next[*c-'a']; mem[index].last_i=1; c++; } } void track(char *c, int last) { int index=0; while(*c) { if (mem[index].next[*c-'a']==-1|| last>mem[mem[index].next[*c-'a']].last_i) return; index=mem[index].next[*c-'a']; mem[index].last_i=last+1; c++; } } void rekur(int index, int depth) { for(int i=0; i<27; i++) { if (mem[index].next[i]==-1 || mem[mem[index].next[i]].last_ilen_res) { tmp[depth+1]=0; strcpy(res, tmp); len_res=depth+1; } rekur(mem[index].next[i], depth+1); } } int main() { while(scanf("%d", &count),count) { for(int j=0; j<27; j++) mem[0].next[j]=-1; counter=1; char in[256]; scanf("%s", in); int len=strlen(in); for(int j=0; j