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

~/algor $ cat problems/qidiruv-sonning-orinlari

Positions in a sorted array

Easy 1000 ms 128 MB 25%
Share

$n$ integers sorted in non-decreasing order, $a_{1} \le a_{2} \le \dots \le a_{n}$, and $q$ queries are given. Each query gives an integer $x$: at which positions does $x$ occur in the array for the first and for the last time? Positions are numbered from $1$.

Cells of the sorted array: the block of cells equal to the given number, its first and last positions highlighted

Input

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

Output

$q$ lines: for each query two numbers separated by a space — the first and the last position, or $-1$ if $x$ is not in the array.

Note

$1 \le n, q \le 10^{5}$
$-10^{9} \le a_{i}, x \le 10^{9}$
$a_{1} \le a_{2} \le \dots \le a_{n}$

Examples

Input #1
7 3
1 2 2 2 5 7 7
2
7
4
Output #1
2 4
6 7
-1
Input #2
1 2
5
5
6
Output #2
1 1
-1

Sign in to submit a solution

Signing up is free and takes a minute.