This problem is a Mooshak version of a UVA and SPOJ problem.


[PC016] Frequent Values

You are given a sequence of \(n\) integers \(a_1, a_2 , \ldots , a_n\) in non-decreasing order. In addition to that, you are given several queries consisting of indices \(i\) and \(j\). For each query, determine the most frequent value among the integers \(a_i, ..., a_j\).

Input

The first input line contains two inters integer \(n\) and \(q\), respectively the amount of numbers and and queries.

The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\): the sequence of integers.

The next \(q\) lines describe the queries: each contains two integers \(i \, j\) describing the query range.

Output

\(q\) lines, each with one integer: the number of occurrences of the most frequent value within the given range.

Constraints

Example Input Example Output
10 3
-1 -1 1 1 1 1 3 10 10 10
2 3
1 10
5 10
1
4
3

Competitive Programming (CC3032) 2025/2026
DCC/FCUP - University of Porto