Non-Decreasing Subsequences
문제
Bessie was recently taking a USACO contest and encountered the following problem. Of course, Bessie knows how to solve it. But do you?
Consider a sequence of length consisting solely of integers in the range You are given () queries of the form For each query, compute the number of non-decreasing subsequences of mod .
A non-decreasing subsequence of is a collection of indices such that and Make sure to consider the empty subsequence!
입력
The first line contains two space-separated integers and .
The second line contains space-separated integers .
The third line contains a single integer
The next lines each contain two space-separated integers and
출력
For each query you should print the number of non-decreasing subsequences of mod on a new line.
힌트
For the first query, the non-decreasing subsequences are and is not a non-decreasing subsequence because
For the second query, the non-decreasing subsequences are , , , and .
예제
예제 1
5 2 1 2 1 1 2 3 2 3 4 5 1 5
3 4 20