Java Simple and easy solution, using Priority Queue, T O(n Log(n)), S O(n) clean code with comments
PLEASE UPVOTE IF YOU LIKE THIS SOLUTION\n\n\n\n\nclass Solution {\n    \n    PriorityQueue<Order> buyBackLog;\n    PriorityQueue<Order> sellBackLog;\n    \n    
**PLEASE UPVOTE IF YOU LIKE THIS SOLUTION**\n\n\n\n```\nclass Solution {\n    \n    PriorityQueue<Order> buyBackLog;\n    PriorityQueue<Order> sellBackLog;\n    \n    static int MOD = 1_000_000_007;\n    \n    \n    public int getNumberOfBacklogOrders(int[][] orders) {\n        \n        //max heap, heapify on price\n        buyBackLog = new PriorityQueue<Order>((a, b) -> (b.price - a.price));\n        //min heap, heapify on price\n        sellBackLog = new PriorityQueue<Order>((a, b) -> (a.price - b.price));\n        \n        \n        //handle all order\n        for(int[] order : orders){\n            int price     = order[0];\n            int quantity  = order[1];\n            int orderType = order[2];\n            \n            if(orderType == 0){\n                //buy order \n                handleBuyOrder(new Order(price, quantity));\n                \n            }else if(orderType == 1){ \n                //sell order\n                handleSellOrder(new Order(price, quantity));\n            }\n        }\n        \n        long counts = 0L;\n        \n        //count buy backlog\n        while(!buyBackLog.isEmpty()){\n            counts += buyBackLog.remove().quantity; \n            counts %= MOD;\n        }\n        \n        //count sell backlog\n        while(!sellBackLog.isEmpty()){\n            counts += sellBackLog.remove().quantity; \n            counts %= MOD;\n        }\n        \n        \n        return (int) (counts % MOD);\n    }\n    \n    \n    \n    \n    private void handleBuyOrder(Order buyOrder){\n        //just add buyorder, if there is no sell back log\n        if(sellBackLog.isEmpty()){\n            buyBackLog.add(buyOrder);\n            return;\n        }\n        \n        \n        while(!sellBackLog.isEmpty() && buyOrder.price >= sellBackLog.peek().price && buyOrder.quantity > 0){\n            //selloder with minumum price\n            Order sellOrder = sellBackLog.remove();\n            \n            if(buyOrder.quantity >= sellOrder.quantity){\n                buyOrder.quantity -= sellOrder.quantity;\n                sellOrder.quantity = 0;\n            } else {\n                //decrement sell order, add remaining sellorder\n                sellOrder.quantity -= buyOrder.quantity;\n                sellBackLog.add(sellOrder);\n                \n                buyOrder.quantity = 0;\n            }\n        }\n        \n        //add reaming buyorder\n        if(buyOrder.quantity > 0){\n            buyBackLog.add(buyOrder);\n        }\n    }\n    \n    \n    private void handleSellOrder(Order sellOrder){\n        //just add sell order, if there is no buy backlog\n        if(buyBackLog.isEmpty()){\n            sellBackLog.add(sellOrder);\n            return;\n        }\n        \n        \n        while(!buyBackLog.isEmpty() && buyBackLog.peek().price >= sellOrder.price && sellOrder.quantity > 0){\n            //buy order with maximum price\n            Order buyOrder = buyBackLog.remove();\n            \n            if(sellOrder.quantity >= buyOrder.quantity){\n                sellOrder.quantity -= buyOrder.quantity;\n                buyOrder.quantity = 0;\n                \n            }else{\n                //decrement buy order quantity, add remaining buyorder\n                buyOrder.quantity -= sellOrder.quantity;\n                buyBackLog.add(buyOrder);\n                \n                sellOrder.quantity = 0;\n            }\n        }\n        \n        //add remaining sell order\n        if(sellOrder.quantity > 0){\n            sellBackLog.add(sellOrder);\n        }\n    }\n}\n\nclass Order{\n    int price;\n    int quantity;\n    \n    public Order(int price, int quantity){\n        this.price = price;\n        this.quantity = quantity;\n    }\n}\n```
['Heap (Priority Queue)', 'Java']