Although she is normally the serious type, when she is alone at night, in her private room in the Academy, Ellis secretly logs into her red-rated coder account on Topcoder and Codeforces. Of course, we will respect her privacy and keep her handle secret because she doesn't want people stalking her.
Ever so persistent, you somehow managed to get her contact information. However, Ellis will only talk to coders who are also good problem solvers — as such, she has presented you with a problem. The problem is as follows:
Given an array (with 1-based indexing) of length , for each of queries count the number of pairs of indices such that and and . In other words, count the number of inversions in the subarray .
Afraid of losing this once-in-a-lifetime chance of communicating with Ellis, you quickly open a text editor and start coding. Wait, you should probably read the input and output specifications first...
The first line of input will have .
The second line of input will have , each separated by a single space.
The third line of input will have .
The next lines of input will each have a pair and separated by a single space.
For each query, output the answer on its own line.
5 4 3 3 2 1 15 1 1 1 2 1 3 1 4 1 5 2 2 2 3 2 4 2 5 3 3 3 4 3 5 4 4 4 5 5 5
0 1 2 5 9 0 0 2 5 0 1 3 0 1 0