the part that is too slow is building of the suffix array, need to use the ranking pair method