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

#BS0000095. Vị trí đỉnh của dãy hình núi (Peak Index in a Mountain Array)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Vị trí đỉnh của dãy hình núi (Peak Index in a Mountain Array)

Peak Index in a Mountain Array

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

A mountain array strictly increases to a unique interior peak index pp, then strictly decreases. Return the zero-based peak index.

Input

The first line contains nn; the second contains the nn mountain-array values.

Output

Print the peak index pp.

Subtasks

  • Subtask 1 (20 points): 3≤n≤203\le n\le 20; 0≤ai≤1060\le a_i\le10^6; the sequence strictly rises to an interior peak and strictly falls afterward.
  • Subtask 2 (30 points): 3≤n≤20003\le n\le 2000; 0≤ai≤1060\le a_i\le10^6; the sequence strictly rises to an interior peak and strictly falls afterward.
  • Subtask 3 (50 points): 3≤n≤1000003\le n\le 100000; 0≤ai≤1060\le a_i\le10^6; the sequence strictly rises to an interior peak and strictly falls afterward.

Examples

Input

4
0 10 5 2

Output

1

Explanation

The sequence rises from 00 to 1010 and then falls through 5,25,2. The peak 1010 is at index 11.