AkunaCapital receives a stream of integer observations from a market-data feed. Implement process_operations(operations) to insert observations and answer statistical queries without recomputing over all prior values.
Each operation is one of:
["insert", x], add integer x to the stream.["mean"], return the arithmetic mean as a float.["median"], return the median. For an even number of observations, return the average of the two middle values.["mode"], return the value with the highest frequency. If several values tie, return the smallest value.["stats"], return an object containing mean, median, and mode.Return a list containing one result for every query operation, in order. Insert operations produce no result. All query operations occur after at least one insertion.
def process_operations(operations):