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

#FT0000053. Luân phiên tổ chức đại hội tưới tiêu (Irrigation)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Luân phiên tổ chức đại hội tưới tiêu (Irrigation)

Irrigation

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are mm cities numbered 11 through mm. The host cities of the first nn years are given and were chosen arbitrarily. Starting with year n+1n+1, the host city is always the one that has hosted the fewest previous years. If several cities tie, the smallest city index is chosen.

Answer qq independent questions asking which city hosts year k>nk>n. Asked years may be extremely large and must not be simulated one by one.

Input

  • Line 1: integers n,m,qn,m,q: initial years, cities, query count.
  • Line 2: exactly nn host-city indices a1,…,ana_1,\ldots,a_n.
  • Next qq lines: one queried year kik_i per line.

Output

Print qq lines; line ii gives the host city in year kik_i.

Subtasks

Subtask 1 (20 points):

  • 1≤n,m,q≤201\le n,m,q\le 20; 1≤ai≤m1\le a_i\le m for all ii; n+1≤ki≤1018n+1\le k_i\le10^{18} for every query.

Subtask 2 (30 points):

  • 1≤n,m,q≤20001\le n,m,q\le 2000; 1≤ai≤m1\le a_i\le m for all ii; n+1≤ki≤1018n+1\le k_i\le10^{18} for every query.

Subtask 3 (50 points):

  • 1≤n,m,q≤5000001\le n,m,q\le 500000; 1≤ai≤m1\le a_i\le m for all ii; n+1≤ki≤1018n+1\le k_i\le10^{18} for every query.

Examples

Examples 1

Input

6 4 10
3 1 1 1 2 2
7
8
9
10
11
12
13
14
15
16

Output

4
3
4
2
3
4
1
2
3
4

Explanation

After six years, host counts of cities 1,2,3,41,2,3,4 are 3,2,1,03,2,1,0. Years 7–9 choose cities 4,3,44,3,4. Years 10–12 choose 2,3,42,3,4 to equalize all counts at 3. Subsequent years cycle through 1,2,3,41,2,3,4, producing the remaining answers.

Examples 2

Input

1 3 5
2
2
3
4
5
1000000000000000000

Output

1
3
1
2
1

Explanation

City 2 starts with one event while the other two have none. Years 2 and 3 choose 1 and 3. Starting in year 4 all counts are equal and hosts repeat as 1,2,3; year 101810^{18} has offset divisible by three from year 4, so its host is 1.