Frequent values - 2#4081

Frequent values - 2

2 seconds
128 megabytes
Easy

You are given a sequence of integers a_1, a_2, \ldots, a_n in non-decreasing order. You are also given several queries, each consisting of two indices and j~(1 \le i \le j \le n). For each query, determine how many times the most frequent value occurs among the integers a_i, \ldots, a_j.

Input

Consists of several test cases. Each test case starts with a line containing two integers and q~(1 \le n, q \le 5 \cdot 10^5). The next line contains integers a_1, \ldots, a_n~(-5 \cdot 10^5 \le a_i \le 5 \cdot 10^5). It is guaranteed that a_i \le a_{i+1} for each i \in \{1, \ldots, n - 1\}. Each of the next lines contains one query consisting of two integers and j~(1 \le i \le j \le n) — the boundaries of the query range.

The last test case is followed by a line containing a single .

Output

For each query, print one line containing a single integer — the number of occurrences of the most frequent value in the given range.

Examples

Example 1

Loading
Loading