CF982D.Shark

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and long movements between locations.

Max is a young biologist. For nn days he watched a specific shark, and now he knows the distance the shark traveled in each of the days. All the distances are distinct. Max wants to know now how many locations the shark visited. He assumed there is such an integer kk that if the shark in some day traveled the distance strictly less than kk , then it didn't change the location; otherwise, if in one day the shark traveled the distance greater than or equal to kk ; then it was changing a location in that day. Note that it is possible that the shark changed a location for several consecutive days, in each of them the shark traveled the distance at least kk .

The shark never returned to the same location after it has moved from it. Thus, in the sequence of nn days we can find consecutive nonempty segments when the shark traveled the distance less than kk in each of the days: each such segment corresponds to one location. Max wants to choose such kk that the lengths of all such segments are equal.

Find such integer kk , that the number of locations is as large as possible. If there are several such kk , print the smallest one.

输入格式

The first line contains a single integer nn ( 1n1051 \leq n \leq 10^5 ) — the number of days.

The second line contains nn distinct positive integers a1,a2,,ana_1, a_2, \ldots, a_n ( 1ai1091 \leq a_i \leq 10^9 ) — the distance traveled in each of the day.

输出格式

Print a single integer kk , such that

  1. the shark was in each location the same number of days,
  2. the number of locations is maximum possible satisfying the first condition,
  3. kk is smallest possible satisfying the first and second conditions.

输入输出样例

  • 输入#1

    8
    1 2 7 3 4 8 5 6
    

    输出#1

    7
  • 输入#2

    6
    25 1 2 3 14 36
    

    输出#2

    2

说明/提示

In the first example the shark travels inside a location on days 11 and 22 (first location), then on 44 -th and 55 -th days (second location), then on 77 -th and 88 -th days (third location). There are three locations in total.

In the second example the shark only moves inside a location on the 22 -nd day, so there is only one location.

首页