Monotonic Stack Implementation Using Python