#GYM104758D. Determine Pool Area

Determine Pool Area

本题没有可用的提交语言。

Description

Given an array of integers, your task is to find the largest pool. In this context, a pool is a contiguous subarray $(l, r)$ such that the minimum between indices $l$ and $r$ is greater than all elements within the subarray $(l, r)$.

The area of the pool is calculated assuming it's filled with water, where $L$ and $R$ are the pool's ends, and the pool's height is equal to the value of the minimum between $L$ and $R$. However, the area of the pool is affected by the numbers in the middle of the subarray. As you move from the ends toward the center of the subarray, the value of the minimum decreases, reducing the pool's area. Additionally, any excess water beyond the pool's edges spills over.

Write a program to find the largest pool in the array and determine its area, considering the decrease in area as you approach the center of the subarray and the spillover of water beyond the edges.

Example of a pool.

The first line contains an integer $N$ $(1 \leq N \leq 10^6)$, the length of the array.

The second line contains $N$ integers separated by spaces, representing the array of integers $A$ $(1 \leq A_i \leq 10^6)$.

An integer, the area of the largest pool in the array, taking into account spillover. If no pool is found, the output should be 0.

Input

The first line contains an integer $N$ $(1 \leq N \leq 10^6)$, the length of the array.

The second line contains $N$ integers separated by spaces, representing the array of integers $A$ $(1 \leq A_i \leq 10^6)$.

Output

An integer, the area of the largest pool in the array, taking into account spillover. If no pool is found, the output should be 0.

4
10 2 3 8
5
1 4 10 4 1
9
5 1 2 1 5 1 2 1 5
11
0
11