Python [max/min heap]
Buy orders are ranked from largest to smallest in price.\nSell orders are ranked from smallest to largest in price.\nWe add the orders in the order they arrive,
Buy orders are ranked from largest to smallest in price.\nSell orders are ranked from smallest to largest in price.\nWe add the orders in the order they arrive,\nwhen there is a match in prices we do the transaction.\n\n```python\nclass Solution:\n    def getNumberOfBacklogOrders(self, orders):\n        maxhp = []\n        minhp = []\n        for x,y,z in orders:\n            if z==0: #buy\n                heapq.heappush(maxhp, (-x, y))\n            else: #sell\n                heapq.heappush(minhp, (x, y))\n            \n            #if there is match, do the transaction\n            while maxhp and minhp and -maxhp[0][0] >= minhp[0][0]:\n                xbuy, ybuy = heapq.heappop(maxhp)\n                xsell, ysell = heapq.heappop(minhp)\n                if ybuy > ysell:\n                    heapq.heappush(maxhp, (xbuy, ybuy-ysell))\n                elif ybuy < ysell:\n                    heapq.heappush(minhp, (xsell, ysell-ybuy))\n        \n        ans = sum(y for _,y in maxhp) + sum(y for _,y in minhp)\n        ans = ans % (10**9 + 7)\n        return ans\n```
[]