python3 Solution
\n\nclass Solution:\n    def sumDistance(self, nums: List[int], s: str, d: int) -> int:\n        n = len(nums)\n        mod=10**9+7\n        for i in range(n):\
\n```\nclass Solution:\n    def sumDistance(self, nums: List[int], s: str, d: int) -> int:\n        n = len(nums)\n        mod=10**9+7\n        for i in range(n):\n            if s[i] == \'L\':\n                nums[i] -= d\n            else: \n                nums[i] += d\n        \n        nums.sort()\n\n        pre = nums.copy()\n        for i in range(1, n):\n            pre[i] += pre[i - 1]\n            pre[i] %= mod\n\n        ans = 0\n        for i in range(1, n):\n\n            ans += i * nums[i] - pre[i - 1]\n            ans %= mod\n        return ans\n```
['Python', 'Python3']