gusfield's z-algorithm