#분할과 정복쓰지않고 처음부터 끝까지 쭉 가면서 완전탐색
import sys
input=sys.stdin.readline
n=int(input())
graph=[]
result=0
cursor=0
a=0
for _ in range(n):
    graph.append(int(input()))
graph.append(0)
stack=[(0,graph[0])]
print(stack)
print(stack[-1][1])
for i in range(1,n+1):
  cursor=i
  while stack and stack[-1][1]>graph[i]:
      cursor,temp=stack.pop()
      result=max(result,temp*(i-cursor))
  stack.append((cursor,graph[i]))
  
print(result)