Python Sorted List solution
\nfrom sortedcontainers import SortedList\nclass Solution:\n    def resultArray(self, nums: List[int]) -> List[int]:\n        arr1=[nums[0]]\n        arr2=[nums
```\nfrom sortedcontainers import SortedList\nclass Solution:\n    def resultArray(self, nums: List[int]) -> List[int]:\n        arr1=[nums[0]]\n        arr2=[nums[1]]\n        sarr1,sarr2=SortedList(),SortedList()\n        sarr1.add(nums[0])\n        sarr2.add(nums[1])\n        for i in range(2,len(nums)):\n            i1,i2=sarr1.bisect(nums[i]),sarr2.bisect(nums[i])\n            f1,f2=len(arr1)-i1,len(arr2)-i2\n            if f1>f2:\n                arr1.append(nums[i])\n                sarr1.add(nums[i])\n            elif f1<f2:\n                arr2.append(nums[i])\n                sarr2.add(nums[i])\n            else:\n                if len(arr2)<len(arr1):\n                    arr2.append(nums[i])\n                    sarr2.add(nums[i])\n                else:\n                     arr1.append(nums[i])\n                     sarr1.add(nums[i])\n        return arr1+arr2\n                \n                    \n                    \n                    \n        \n        \n```
['Binary Tree', 'Python']