#SGM0000008. Giá trị xuất hiện nhiều nhất (Frequent Values)
Giá trị xuất hiện nhiều nhất (Frequent Values)
Frequent Values
Source: UVa
Version: Phuoc Hung OJ Extended
You are given a non-decreasing sequence . Each of the queries gives two indices with .
For every query, determine the largest frequency of any value among .
The original UVa task contains multiple test cases terminated by a line containing 0. This Phuoc Hung OJ version contains one test case per input file.
Input
The first line contains .
The second line contains the non-decreasing sequence .
Each of the next lines contains .
Output
For every query, print the maximum frequency in the requested range.
Subtasks
- Subtask 1 — 20%: , .
- Subtask 2 — 30%: , .
- Subtask 3 — 50%: , .
Examples
Input
10 3
-1 -1 1 1 1 1 3 10 10 10
2 3
1 10
5 10
Output
1
4
3
Explanation
The sample follows the operations exactly; each printed line corresponds to a query that requires output.