A sorted sequence of $n$ integers (duplicates allowed) is given. For each of $k$ queries $a$, $b$, print how many elements lie in $[a, b]$ (inclusive).
Input
Line 1: $n$. Line 2: $n$ sorted integers. Line 3: $k$. Next $k$ lines: $a$ $b$.
Output
Print the count for each query, one per line.
Example 1
Input
5 1 2 3 4 5 3 1 2 2 4 5 6
Output
2 3 1
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.