JAVA Solution
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)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int sumDistance(int[] nums, String s, int d) {\n        long out[] = new long[nums.length];\n        for(int i = 0; i < nums.length ; i++){\n            if(s.charAt(i) == \'L\'){\n                out[i] = (nums[i] -  (long)d)  ;\n            }\n            else{\n                out[i]  =(nums[i] +  (long)d);\n            }\n        }\n        Arrays.sort(out);\n        // System.out.println(Arrays.toString(out));\n        int ans = 0;\n        int full_ans = 0;\n        for(int i = 1; i < nums.length ; i++){\n            ans = (int)(((out[i] - out[i-1]) * (long)i + ans ) % (long)(1e9 + 7));\n            full_ans = (int)((full_ans + (long)ans )% (long)(1e9 + 7));\n        }\n        return full_ans;\n    }\n}\n```
['Java']