Monotonic Stack Python Problem Solve