[Python3] Clean and Clear - Two heaps
\nclass Solution:\n    def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:\n        buy, sell, MOD = [], [], 10**9 + 7\n        \n        def pr
```\nclass Solution:\n    def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:\n        buy, sell, MOD = [], [], 10**9 + 7\n        \n        def process_buy(buy_price, buy_amount):\n            while buy_amount > 0:\n                if not sell:\n                    break\n                sell_price, sell_amount = heapq.heappop(sell)\n                if sell_price > buy_price:\n                    heapq.heappush(sell, (sell_price, sell_amount))\n                    break\n                \n                if sell_amount - buy_amount > 0:\n                    heapq.heappush(sell, (sell_price, sell_amount - buy_amount))\n                buy_amount -= sell_amount\n            if buy_amount > 0:\n                heapq.heappush(buy, (-buy_price, buy_amount))\n            \n        def process_sell(sell_price, sell_amount):\n            while sell_amount > 0:\n                if not buy:\n                    break\n                buy_price, buy_amount = heapq.heappop(buy)\n                buy_price *= -1 # min heap only in Python\n                if sell_price > buy_price:\n                    heapq.heappush(buy, (-buy_price, buy_amount))\n                    break\n                \n                if buy_amount - sell_amount > 0:\n                    heapq.heappush(buy, (-buy_price, buy_amount - sell_amount))\n                sell_amount -= buy_amount\n            if sell_amount > 0:\n                heapq.heappush(sell, (sell_price, sell_amount))\n    \n        for price, amount, order_type in orders:\n            if order_type == 0:\n                process_buy(price, amount)\n            else:\n                process_sell(price, amount)\n\n        return (sum([x[1] for x in buy]) + sum([x[1] for x in sell])) % MOD\n```
[]