Java O(nlogn) + Sorting + Prefix Sum
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 
# 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)$$ -->\nO(nlogn)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n# Code\n```\nclass Solution {\n    private static final int MOD = 1000000007;\n    public int sumDistance(int[] nums, String s, int d) {\n        for(int i=0;i<nums.length;i++) {\n            if(s.charAt(i)==\'L\') {\n                nums[i] -= d;\n            } else {\n                nums[i] += d;\n            }\n        }\n        Arrays.sort(nums);\n        \n        int totalDistance = 0, prev = 0;\n        for(int i=1;i<nums.length;i++) {\n            long dist = (long)nums[i] - nums[i-1];\n            dist = (dist * i) % MOD;\n            int distance = (((int)dist) + prev) % MOD;\n            totalDistance = (totalDistance +  distance) % MOD;\n            prev = distance;\n        }\n        return totalDistance;\n    }\n}\n```
['Java']