[python] sorted list
\nfrom sortedcontainers import SortedList\nclass Solution:\n    def resultArray(self, nums: List[int]) -> List[int]:\n        s1=SortedList([nums[0]])\n        
```\nfrom sortedcontainers import SortedList\nclass Solution:\n    def resultArray(self, nums: List[int]) -> List[int]:\n        s1=SortedList([nums[0]])\n        s2=SortedList([nums[1]])\n        k1=[nums[0]]\n        k2=[nums[1]]\n        def gc(sl,k,n):\n            return len(k)-sl.bisect_right(n)\n        \n        for i in range(2,len(nums)):\n            a=gc(s1,k1,nums[i])\n            b=gc(s2,k2,nums[i])\n            if a>b:\n                s1.add(nums[i])\n                k1.append(nums[i])\n            elif a<b:\n                s2.add(nums[i])\n                k2.append(nums[i])\n            else:\n                if len(s1)<=len(s2):\n                    s1.add(nums[i])\n                    k1.append(nums[i])\n                elif len(s1)>len(s2):\n                    s2.add(nums[i])\n                    k2.append(nums[i])\n        return k1+k2\n        \n```
[]