Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/qidiruv-burilgan-massiv

Search in a rotated array

Medium 1000 ms 128 MB 51%
Share

An array of distinct integers sorted in increasing order was cut at one place into two parts, and the parts were swapped (for example, 3 6 9 12 15 18 22 became 15 18 22 3 6 9 12; the array may also be left uncut). This array $a$ and $q$ queries are given. Each query gives an integer $x$: at which position of the array is it? If it is not in the array, print $-1$.

An array of two increasing parts: the cell with the searched number is highlighted

Input

The first line contains two positive integers: $n$ and $q$.
The second line contains $n$ integers $a_{i}$.
Each of the next $q$ lines contains one integer $x$.

Output

For each query on a separate line: the position number or $-1$.

Note

$1 \le n, q \le 10^{5}$
$-10^{9} \le a_{i}, x \le 10^{9}$
all $a_{i}$ are distinct

Examples

Input #1
7 3
15 18 22 3 6 9 12
6
22
10
Output #1
5
3
-1
Input #2
1 2
4
4
7
Output #2
1
-1

Sign in to submit a solution

Signing up is free and takes a minute.