Smart Beaver recently get interested new word game the point follow count number distinct good substring string s to determine stre good game use rule overall n rule each rule describe group plr p string l r lr integer well string t complie rule plr number occurrence string t string p lie l r inclusive for example string ab complies rule ab 1 2 aab 0 1 comply rule cd 1 2 abab 0 1A substring sl r 1lrs string ss1s2 ss s length s string slsl1 srconsider number occurrence string t string p number pair integer lr 1lrp pl rtwell string t good complie n rule Smart Beaver ask help write program calculate number distinct good substring string s two substring sx y sz w cosidere distinct iff sx ysz w