Recently Colin learned how the string hashing algorithm works. Generally speaking, it is to convert a string into an integer.
The good and widely used way to define the hash of a string

of length

(indexed from

) is
where

and

are some chosen, positive numbers. It is called a polynomial rolling hash function.
But Colin doesn't understand how to choose appropriate

and

, so he often encounters hashing collision problems. Consider two substrings

of the string

such that

but
%3Dhash(s_2))
holds, then we say that there is a hashing collision betweem

and

.
Now given a string

of length

, and two integers

and

chosen by Colin. He wants to know how many ways are there to choose integers

satisfying

, and there is a hashing collision between
![s[l_1,r_1]](https://www.nowcoder.com/equation?tex=s%5Bl_1%2Cr_1%5D)
and
![s[l_2,r_2]](https://www.nowcoder.com/equation?tex=s%5Bl_2%2Cr_2%5D)
.