Array Simulation + Sort + Suffix. Time: O(nlogn), Space: O(n)
class Solution(object):\n    def sumDistance(self, nums, s, d):\n        """\n        :type nums: List[int]\n        :type s: str\n        :type d: int\n       
class Solution(object):\n    def sumDistance(self, nums, s, d):\n        """\n        :type nums: List[int]\n        :type s: str\n        :type d: int\n        :rtype: int\n        """\n        \n        \n        pos = []\n        \n        n = len(nums)\n        \n        for i in range(n):\n            if s[i] == \'R\':\n                pos.append(nums[i] + d)\n            else:\n                pos.append(nums[i] - d)\n        \n        pos.sort()\n        \n        #print pos\n        res = 0\n        cur = 0\n        \n        for i in range(n-2,-1,-1):\n            cur = cur + (pos[i+1] - pos[i])*(n-1-i)\n            res += cur\n        \n        #print res\n        return res%(10**9 + 7)
[]