PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CC0000011. Chú voi và tần suất bằng giá trị (Little Elephant and Array)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Chú voi và tần suất bằng giá trị (Little Elephant and Array)

Little Elephant and Array

Source: Codeforces Version: Phuoc Hung OJ Extended

Problem Statement

For a query range [l,r][l,r], call an integer value xx good if its frequency in that range is exactly xx. For each query, count how many different values are good. For example, a value of 33 that appears exactly three times contributes one.

Input

The first line contains N,QN,Q. The second line has NN positive integers aia_i. The next QQ lines contain l,rl,r.

Output

Print QQ lines, one answer per query in the original order.

Subtasks

  • Subtask 1 (20 points): 1≤N≤301\le N\le 30; 1≤Q≤301\le Q\le 30; 1≤ai≤10000000001\le a_i\le 1000000000; 1≤l≤r≤N1\le l\le r\le N.
  • Subtask 2 (30 points): 1≤N≤22001\le N\le 2200; 1≤Q≤22001\le Q\le 2200; 1≤ai≤10000000001\le a_i\le 1000000000; 1≤l≤r≤N1\le l\le r\le N.
  • Subtask 3 (50 points): 1≤N≤1000001\le N\le 100000; 1≤Q≤1000001\le Q\le 100000; 1≤ai≤10000000001\le a_i\le 1000000000; 1≤l≤r≤N1\le l\le r\le N.

Examples

Input

7 2
3 1 2 2 3 3 7
1 7
3 4

Output

3
1

Explanation

In [1,7][1,7], value 11 occurs once, value 22 twice, and value 33 three times, so there are 33 good values.