has recently become obsessed with strings and poses the following question
Given a string of length and queries, output how many permutations there are of the substring between index and (inclusive)
Can you help
answer his question?Input Specification
The first line will contain two integers length of the string, and the number of queries.
The next line will contain a single string of length .
The next lines will contain two integers and indicating the range of the th query.
Output Specification
Output lines, each containing the number of possible string permutations using the characters between and where represents the th query.
Subtasks
Subtask 1 [2/12]:
Subtask 2 [5/12]:
Subtask 3 [5/12]:
- No further constraints
Sample Input 1
6 3
BANANA
3 5
1 4
2 6
Sample Output 1
3
12
10
Explanation for Sample Input 1
There are 3 total permutations of the string between 3
and 5
: ANN
, NAN
, NNA
.
There are 12 total permutations of the string between 1
and 4
: BAAN
, BANA
, BNAA
, ABAN
, ABNA
, NBAA
, AABN
, ANBA
, NABA
, AANB
, ANAB
, NAAB
.
There are 10 total permutations of the string between 2
and 6
: AAANN
, AANAN
, AANNA
, ANAAN
, ANANA
, ANNAA
, NAAAN
, NAANA
, NANAA
, NNAAA
.
Sample Input 2
12 1
ABCDEFGHIJKL
1 12
Sample Output 2
79001572
Explanation for Sample Output 2
Make sure to output the number of permutations .
Comments