#include #include #define MAX_K 63 #define HLEN ((1<<19)-1) struct h_p { long long i; char l[26]; }; struct h_p hash[1<<19]; int k; long long cas=1; char now[26]; int last[MAX_K]; int last_len; int now_len; int hf() { int out=165; int i; for (i=0;i<26;i++) out=(out+now[i]*991)&HLEN; return out; } int hf2() { int out=179; int i; for (i=0;i<26;i++) out=(out+now[i]*113)&HLEN; return out; } int is_in_hash() { int h=hf(); int hadd=-1; int ret=0; while (hash[h].i==cas) { if (!memcmp(hash[h].l,now,26)) { ret=1; break; } if (hadd==-1) hadd=hf2(); h=(h+hadd)&HLEN; } return ret; } void add_to_hash() { int h=hf(); int hadd=-1; while (hash[h].i==cas) { if (hadd==-1) hadd=hf2(); h=(h+hadd)&HLEN; } hash[h].i=cas; memcpy(hash[h].l,now,26); } int main(void) { int i,c; int count; int res; while (scanf("%d",&k),k) { while (c=getchar(),c!='\n') {} now_len=0; last_len=0; count=0; res=-1; for (i=0;i<26;i++) now[i]=1; while (c=getchar(),c!='\n') { count++; if (!isalpha(c)) continue; c=tolower(c)-'a'; if (now_len