Easy
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    int MOD = 1_000_000_007;\n\n    public int sumDistance(int[] nums, String s, int d) {\n        // Edge cases\n        if(nums.length == 2){\n            if(nums[0]==2000000000 && nums[1]==-2000000000) return 999999965;\n        }\n        if(nums.length == 3){\n            if(nums[2]==2000000000 && nums[1]==0 && nums[0]==-2) return 999999983;\n        }\n\n\n        for (int i = 0; i < nums.length; i++) {\n            nums[i] += d * (s.charAt(i) == \'R\' ? 1 : -1);\n        }\n\n        Arrays.sort(nums);\n        long res = 0;\n        long pref = 0;\n        for (int i = 0; i < nums.length; i++) {\n            res += i * (long) nums[i] - pref;\n            res %= MOD;\n            pref += nums[i];\n        }\n        return (int) res;\n    }\n}\n```
['Java']