Curious Queries

0

0 votes
Problem

You are given a string s of length n.You are also given q queries of the form L R . For each query you have to find out the number of distinct strings that can be formed using the characters sL,sL+1,.......,s.

Since the answer can be very large print the answer modulo 109 +7.

NOTE : All permutations of a string are considered same. For example : {"abc","acb","bac","bca","cab",cba"} all are considered same.

 

INPUT FORMAT

First line contains the length of the string n.

Second line contains the string s.

Third line contains the number of queries q.

Next q lines denote the queries ,each query containing two space separarted integers L and R.

OUTPUT FORMAT

For each query print the answer in a separate line.

CONSTRAINTS

 1n105

 1q105

1L,Rn

String contains only lowercase english alphabets.

 

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For the first query possible strings are a,b,c,aa,ab,ac,bc,abc,aab,aac,aabc.

For the second query possible strings are b,c,bc.

Editor Image

?