cswork / OAOpen practice workspace

Capital OneOA #7

Largest Square in Skyscraper Outline

Estimated MediumJudge-ready

Topics (AI-labelled)Stacks & HeapsBinary Search

A row of adjacent skyscrapers each has width 1, with heights given by the array cityLine. Find the area of the largest square that lies entirely within the outline of the buildings.

Input

The first line contains n (1≤n≤200000), and the second line contains n non-negative integers h_i (0≤h_i≤10^9). These input ranges are site supplements; the original problem listed no constraints.

Output

Output the maximum area of a square that fits.

Example 1

Input:

5
1 2 3 2 1

Output:

4

Example 2

Input:

3
4 3 4

Output:

9

Example 3

Input:

5
0 0 5 5 5

Output:

9

Editorial

Loading solution…