Counting Haybales

Given N distinct haybale positions and Q interval queries, count how many positions fall inside each inclusive range [A, B].

Medium4SortingBinary searchArrayPrefix sumInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Farmer John placed his NN haybales (1N1000001 \le N \le 100\,000) at various points along the one-dimensional road that runs across his farm. To confirm that the spacing is right, he needs answers to QQ queries (1Q1000001 \le Q \le 100\,000). Each query asks how many haybales lie within a given interval of the road.

Input

The first line contains NN and QQ.

The second line contains NN distinct integers, each in the range 00 to 10000000001\,000\,000\,000. A haybale sits at each of those positions.

Each of the next QQ lines contains two integers AA and BB (0AB10000000000 \le A \le B \le 1\,000\,000\,000), asking for the number of haybales whose position is between AA and BB, inclusive.

Output

Print QQ lines. For each query, in input order, print the number of haybales in its interval on its own line.