Maximal Area
InterviewTime limit2sMemory limit256 MB
Given N column heights, find the area of the largest rectangle formed by whole unit squares.
Problem

Building a hotel near the sea coast is profitable. That is why International Ocean Investment bought a piece of land on the Black Sea coast, similar to the one in the figure, and wants to build a hotel that is as large as possible. For several reasons the base of the hotel has to be a rectangle, so the company wants the rectangle of maximal area that can be drawn on the land.
The terrain is split into columns of equal squares (white in the figure). The columns are numbered from left to right, and the rectangle has to be made of a whole number of these squares. For each column the number of whole squares in that column was counted. Write a program that finds the area of the largest rectangle that can be made of those squares.
Input
The first line contains a positive integer ().
The second line contains integers , where is the number of squares in column and .
Output
Print the maximal area that was found. The value can exceed the range of a 32-bit signed integer.