1801. beginner friendly
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(nlogn)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n\n# Code\n```\nclass Solution(object):\n    def getNumberOfBacklogOrders(self, orders):\n        """\n        :type orders: List[List[int]]\n        :rtype: int\n        """\n        buy = []\n        sell = []\n        for i in orders:\n            if i[2] == 0:\n                tp = i[1]   # if buy vlaues\n                while sell:\n                    k, v = heapq.heappop(sell)\n                    if k <= i[0]: \n                        if v < tp:\n                            tp -= v\n                        else:\n                            v -= tp\n                            tp = 0\n                            # make tp = 0 to represent no current key left\n                            heapq.heappush(sell, (k, v))\n                            break\n                    else:    \n                    # if no values in sell smaller than current value\n                        heapq.heappush(sell, (k, v))\n                        heapq.heappush(buy, (-i[0], tp))\n                        # store minus i[0] as the minimum number\n                        tp = 0  \n                        # make tp = 0 to represent no current key left\n                        break\n                if tp:   # if sell is empty but still buy values   \n                    heapq.heappush(buy, (-i[0], tp))\n        \n            elif i[2] == 1:   # if sell values\n                tp = i[1]\n                while buy:\n                    k, v = heapq.heappop(buy)\n                    if -k >= i[0]: \n                        if v < tp:\n                            tp -= v\n                        else:\n                            v -= tp\n                            tp = 0\n                            heapq.heappush(buy, (k, v))\n                            break\n                    else: \n                        heapq.heappush(buy, (k, v))\n                        heapq.heappush(sell, (i[0], tp))\n                        tp = 0\n                        break\n                if tp:\n                    heapq.heappush(sell, (i[0], tp))\n        \n        ans = 0    \n        # add all left counts\n        for i in buy:\n            ans += i[1]\n        for i in sell:\n            ans += i[1]\n        return ans % (10 ** 9 + 7)\n```
['Python']