LogiQuest

77. Find a Peak Element

MediumBinary Search

Adjacent elements are different. A peak is an element strictly greater than its neighbours (outside the array counts as −∞). Print the index of the first peak (0-based).

Input format

Line 1: n Line 2: n integers

Output format

The index of the first peak.

Example 1

Input

4
1 2 3 1

Output

2

Example 2

Input

7
1 2 1 3 5 6 4

Output

1

Constraints

1 ≤ n ≤ 10⁵

Read input from standard input and print the answer to standard output. Your code is judged against 6 test cases, most of them hidden.

Loading the MyLoginn IDE…