All tasks
Mediumsearcharrays

Binary Search

Time limit 2 s · Memory 64 MB

Statement

The first line contains n, the second line contains n integers sorted in non-decreasing order. The third line contains q, the number of queries; each of the next q lines contains one integer x. For each query print on its own line the 1-based index of the first occurrence of x in the array, or -1 if it is absent.

Constraints

1 ≤ n, q ≤ 10^5 -10^9 ≤ a_i, x ≤ 10^9

Examples

Input 1
5
1 3 5 7 9
3
5
1
4
Output 1
3
1
-1
Input 2
6
2 2 2 5 8 8
3
2
8
7
Output 2
1
5
-1
Solve this task to unlock the editorial.

AI tutor

Stuck? Get a nudge — the tutor explains the idea, it never hands you the solution.