bisect_right, less mem, beats 95% both
Intuition\n Describe your first thoughts on how to solve this problem. \nSortedList.bisect_right\n\n# Approach\n Describe your approach to solving the problem. 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSortedList.bisect_right\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nUse as less memory as we can\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nfrom sortedcontainers import SortedList as sl\nclass Solution:\n    def resultArray(self, nums: List[int]) -> List[int]:\n        slA = sl([nums[0]])\n        slB = sl([nums[1]])\n        B = [nums[1]]\n        pos = 1\n        for val in nums[2:]:\n            sgA = len(slA) - slA.bisect_right(val)\n            sgB = len(slB) - slB.bisect_right(val)\n            if sgA > sgB or sgA == sgB and len(slA) <= len(slB):\n                # A.append(val)\n                nums[pos] = val\n                pos += 1\n                slA.add(val)\n            else:\n                B.append(val)\n                slB.add(val)\n        del slA, slB\n        res = nums[:pos]\n        res.extend(B)\n        return res\n\n```
['Python3']