python3 o(nlogn) maths
\n# Code\npython3 []\nclass Solution:\n    def sumDistance(self, nums: List[int], s: str, d: int) -> int:\n        for i in range(len(nums)):\n            if s[
\n# Code\n```python3 []\nclass Solution:\n    def sumDistance(self, nums: List[int], s: str, d: int) -> int:\n        for i in range(len(nums)):\n            if s[i] == \'R\':\n                nums[i]+=d\n            else:\n                nums[i]-=d\n        nums.sort()\n        temp = sum([x-nums[0] for x in nums[1:]])\n        ans = temp\n        for i in range(1,len(nums)):\n            diff = nums[i]-nums[i-1]\n            temp -= (len(nums)-i)*diff\n            ans += temp\n        return ans%1000000007\n\n```
['Python3']