O(n log n) simple sort and count
Key observation is that you might as well assume the robots keep moving in the direction they started in, as you don\'t care if they rebound off each other beca
Key observation is that you might as well assume the robots keep moving in the direction they started in, as you don\'t care if they rebound off each other because we don\'t care which is which. \n\nSo, simply find the place where each finishes, then sort that as that lets us count in order without worrying about absolute value. \n\nKeep S as a prefix sum as you go through the sorted array. \n\n```\nclass Solution:\n    def sumDistance(self, nums: List[int], s: str, d: int) -> int:\n        nums = sorted([n+d if s[i]==\'R\' else n-d for i,n in enumerate(nums)])\n        \n        ret = 0\n        S = 0\n        \n        for i,n in enumerate(nums):\n            ret += i*n - S\n            S += n\n        \n        return ret % (10**9+7)\n   ```
['Python3']