PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000099. Tìm một đỉnh của dãy (Find Peak Element)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tìm một đỉnh của dãy (Find Peak Element)

Find Peak Element

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

A peak element is strictly greater than its immediate neighbors. Outside the array, values are conceptually −∞-\infty. Find the zero-based index of any peak in an array with unequal adjacent elements.

Input

The first line contains nn; the next line contains its nn integers.

Output

Print any zero-based peak index ii. Any valid peak is accepted.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; −231≤ai≤231−1-2^{31}\le a_i\le 2^{31}-1; adjacent elements are unequal.
  • Subtask 2 (30 points): 1≤n≤2001\le n\le 200; −231≤ai≤231−1-2^{31}\le a_i\le 2^{31}-1; adjacent elements are unequal.
  • Subtask 3 (50 points): 1≤n≤10001\le n\le 1000; −231≤ai≤231−1-2^{31}\le a_i\le 2^{31}-1; adjacent elements are unequal.

Examples

Input

4
1 2 3 1

Output

2

Explanation

Index 22 has value 33, larger than its neighbors 22 and 11; therefore index 22 is a valid peak.