private void add(char c){
            c-=minChar;
            int current = N++;
            length[current] = length[last]+1;
            link[current] = nil;
            for(; last!=-1 && to[c][last]==nil; last = link[last]) to[c][last] = current;
            if(last!=-1){
                int p = to[c][last];
                if(length[p]==length[last]+1) link[current] = p; else{
                    int q = N++;
                    length[q] = length[last]+1;
                    link[q] = link[p];
                    for(char x=minChar; x<=maxChar; ++x) to[x-minChar][q] = to[x-minChar][p];
                    for(; last!=-1 && to[c][last]==p; last = link[last]) to[c][last] = q;
                    link[current] = link[p] = q;
                }
            }
            last = current;
        }