[Python3] Simple Solution with Priority Queue (100 % Time & Space Efficiency)
\nclass Solution:\n    def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:\n        buy, sell = [], []\n        \n        for order in orders:\n
```\nclass Solution:\n    def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:\n        buy, sell = [], []\n        \n        for order in orders:\n            if order[2] == 0:\n                while len(sell) > 0:\n                    if 0 >= len(sell) or 0 == order[1]: break\n\n                    se = heapq.heappop(sell)\n                    if order[0] >= se[0]:\n                        t = min(order[1], se[1])\n                        order[1] -= t\n                        se[1] -= t\n                        \n                        if se[1] != 0:\n                            heapq.heappush(sell, se)\n                            break\n                    else:\n                        heapq.heappush(sell, se)\n                        break\n                \n                if order[1] != 0:\n                    order[0] = -order[0]\n                    heapq.heappush(buy, order)\n                \n            else:\n                while len(buy) > 0:\n                    if 0 >= len(buy) or 0 == order[1]: break\n                    \n                    bu = heapq.heappop(buy)\n                    if order[0] <= (bu[0] * -1):\n                        t = min(order[1], bu[1])\n                        order[1] -= t\n                        bu[1] -= t\n                        \n                        if bu[1] != 0:\n                            heapq.heappush(buy, bu)\n                            break\n                    else:\n                        heapq.heappush(buy, bu)\n                        break\n                \n                if order[1] != 0:\n                    heapq.heappush(sell, order)\n\n\n        x = 0        \n        for b in buy:\n            x += b[1]\n            x %= (1000000000 + 7)\n            \n        for s in sell:\n            x += s[1]\n            x %= (1000000000 + 7)\n        \n        return x\n```
[]