cswork / OAOpen practice workspace

JPMorgan ChaseOA #25

Chess Tournament

Estimated MediumJudge-ready

Topics (AI-labelled)SimulationIn-place Arrays

Players line up in their original order. The two players at the front compare their distinct potentials; the larger one wins and stays at the front, and the loser goes to the back. The process ends as soon as someone first wins k games in a row; output the winner's potential.

Input

The first line contains n k, followed by n distinct potentials. Original bounds: N/A. This site uses 2≤n≤200000, 1≤k≤10^18, and potentials are integers in −10^9..10^9; they are not required to be a permutation of 1..n.

Output

Output a single integer answer.

Example 1

Input:

4 2
3 2 1 4

Output:

3

Example 2

Input:

4 1
-5 -2 -3 -1

Output:

-2

Example 3

Input:

5 2
1 3 2 4 5

Output:

3

Example notes

The outputs of the three public examples are, in order: 3; -2; 3. These answers have been checked by independent enumeration or direct simulation.

Editorial

Loading solution…