# #{4,5,4,7,5} output 4*5=20

# def heightof(hist):
#     stack=[]
#     max_area=0
#     index=0

#     while index < len(hist):
#         if len(stack)==0 or (hist[stack[-1]] <= hist[index]):
#             stack.append(index)
#             index+=1
#         else:
#             top_ofstack=stack.pop()

#             area=(hist[top_ofstack]*(index - stack[-1] -1)if stack else index)

#             max_area=max(area,max_area)    
#     while stack:
#         top_ofstack=stack.pop()        

#         area=(hist[top_ofstack]*(index - stack[-1] - 1)if stack else index)
#         max_area=max(area,max_area)
#         return max_area
# #driver code
# hist=[6, 2, 5, 4, 5, 1, 12]

# print(heightof(hist))

def area(hist):
    index=0
    max_area=0
    stack=[]

    while index < len(hist):
        if len(stack) == 0 or (hist[stack[-1]] <= hist[index]):
            stack.append(index)
            index+=1
        else:
            top=stack.pop()
            area=hist[top]*(index-stack[-1]-1)if stack else index

            max_area=max(area,max_area)
    while stack:
        top=stack.pop()
        area=hist[top]*(index-stack[-1]-1)if stack else index  
        max_area=max(area,max_area) 
        return max_area



#driver code

hist=[2,3,4,5,2]
print(area(hist))