410473: GYM104024 E Diameter

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Diametertime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Aqua and Hiyori love the longest diameter.

Aqua has a sequence $$$a$$$ of length $$$n$$$, and Hiyori want to construct a complete undirected graph which has $$$n$$$ vertices based on the sequence $$$a$$$, which means that the length of edge between $$$u$$$ and $$$v$$$ is $$$\min_{i=\min(u,v)}^{\max(u,v)} a_i$$$. In Aqua's mind, $$$d(u,v)$$$ is described as the longest simple path from $$$u$$$ to $$$v$$$ and she want to know $$$\max_{1\leq u<v\leq n} d(u,v)$$$. But she is stupid, could you help her?

Input

There are two lines in the input.

The first line contains a integer $$$n\ (1\leq n\leq 10^6)$$$, represents the number of the piles.

The second line contains $$$n$$$ integers $$$a_1,a_2,...,a_n\ (1\leq a_i\leq 10^9)$$$, represents the sequence $$$a$$$.

Output

Output a single integer — $$$\max_{1\leq u<v\leq n} d(u,v)$$$.

ExampleInput
3
1 1 1
Output
2

加入题单

算法标签: