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

~/algor $ cat problems/minmax-30-maksimumning-k-chi-uchrashi

K-th occurrence of the maximum

Easy 1000 ms 128 MB 28%
Share

Positive integers $N$, $K$ and $N$ integers are given. Among the elements equal to the largest value, find the position (indexed from $1$) of the $K$-th one counting from the left. If the largest value occurs fewer than $K$ times, print $0$.

Finding the position of the K-th element equal to the largest value

Input

The first line contains two positive integers: $N$ and $K$. The next line contains $N$ integers $A_{i}$.

Output

One integer — the position or $0$.

Note

$1 \le K \le N \le 1000$
$-10^{9} \le A_{i} \le 10^{9}$

Examples

Input #1
7 2
4 9 1 9 3 9 2
Output #1
4
Input #2
4 3
5 8 8 1
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.