Farmer John Solves 3SUM
Farmer John is convinced that he has made a groundbreaking discovery in algorithm design: he claims to have developed a nearly linear algorithm for the well-known 3SUM problem, which is widely believed to require at least quadratic time. One formulation of the 3SUM problem is as follows: given an array of integers , count the number of unordered triplets with distinct indices such that .
To test Farmer John's algorithm, Bessie has prepared an array of integers. She will make queries, each specifying a pair of indices . For each query, Farmer John must solve the 3SUM problem on the subarray .
Farmer John asks for your help to pass Bessie's test.
Input
The first line contains two integers and . The second line contains the elements of the array . Each of the following lines contains two integers and , representing a query.
It is guaranteed that for every element of the array , the condition holds.
Output
Print lines. The -th line should contain a single integer — the answer to the -th query.
Examples
For the first query, the possible triplets are: and .