Tyger is at an ice cream shop where $$$n$$$ flavors are laid out in a row. Each flavor has a unique integer price from $$$1$$$ to $$$n$$$, inclusive.
Tyger samples the flavors over $$$n$$$ days using the following process:
The first line contains two integers $$$n$$$ and $$$q$$$ $$$(1 \leq n, q \leq 10^5)$$$, representing the number of flavors and the number of questions.
The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, the costs of the flavors. It is guaranteed that $$$a$$$ is a permutation of length $$$n$$$.
The next $$$q$$$ lines each contain two integers $$$p$$$ and $$$k$$$ $$$(1 \leq p \leq n, 1 \leq k \leq n)$$$, representing Cody's questions.
For each of Cody's questions, output a single integer: the number of possible first-day choices that would result in Tyger trying flavor $$$p$$$ on day $$$k$$$.
In tests worth $$$20$$$ points, it is guaranteed that $$$n \leq 1000$$$.
7 3 4 2 6 3 7 1 5 3 1 2 3 5 4
1 1 0
For the first question, Tyger can only start with flavor $$$3$$$ on the first day. For the second question, Tyger can only start with flavor $$$4$$$ on the first day, trying flavor $$$3$$$ on the second day and flavor $$$2$$$ on the third. For the third question, it's impossible no matter which flavor Tyger starts with.
Credit: Mishazher