def max_rectangle_area(histogram):
 stack = []
 top = (lambda : stack[(-1)])
 max_area = 0
 pos = 0
 for (pos, height) in enumerate(histogram):
  start = pos
  while True:
   if ((not stack) or (height > top()[1])):
    stack.append((start, height))
   elif (stack and (height < top()[1])):
    max_area = max(max_area, (top()[1] * (pos - top()[0])))
    (start, _) = stack.pop()
    continue
   break
 pos += 1
 for (start, height) in stack:
  max_area = max(max_area, (height * (pos - start)))
 return max_area

def max_rectangle_area ( histogram ) : stack = [ ] top = ( lambda : stack [ ( - 1 ) ] ) max_area = 0 pos = 0 for ( pos , height ) in enumerate ( histogram ) : start = pos while True : if ( ( not stack ) or ( height > top ( ) [ 1 ] ) ) : stack . append ( ( start , height ) ) elif ( stack and ( height < top ( ) [ 1 ] ) ) : max_area = max ( max_area , ( top ( ) [ 1 ] * ( pos - top ( ) [ 0 ] ) ) ) ( start , _ ) = stack . pop ( ) continue break pos += 1 for ( start , height ) in stack : max_area = max ( max_area , ( height * ( pos - start ) ) ) return max_area
find the area of the largest rectangle that fits entirely under the histogram .