문제
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
A non-decreasing subsequence of
SCORING:
Test cases 2-3 satisfy
N\le 1000 .Test cases 4-6 satisfy
K\le 5. Test cases 7-9 satisfy
Q\le 10^5. Test cases 10-12 satisfy no additional constraints.
입력
The first line contains two space-separated integers
The second line contains
The third line contains a single integer
The next
출력
For each query
예제1
5 2
1 2 1 1 2
3
2 3
4 5
1 5
3
4
20
For the first query, the non-decreasing subsequences are
For the second query, the non-decreasing subsequences are