C++ Solution
Code\n\nclass Solution {\npublic:\n    int sumDistance(vector<int>& arr, string s, int d) {\n        int n = arr.size();\n        vector<long long> nums(n,0);\n
# Code\n```\nclass Solution {\npublic:\n    int sumDistance(vector<int>& arr, string s, int d) {\n        int n = arr.size();\n        vector<long long> nums(n,0);\n        int mod = 1e9 + 7;\n        for(int i = 0;i < nums.size();i++) {\n            if(s[i] == \'L\')\n                nums[i] = arr[i]*1LL - d;\n            else\n                nums[i] = arr[i]*1LL + d;\n        }\n        sort(nums.begin(),nums.end());\n\n        long long ans = 0;\n        long long sum = 0;\n        for(int i = 0;i < nums.size();i++) {\n            ans = (ans + (nums[i]*i)%mod - sum) % mod;\n            sum = (sum + nums[i])%mod;\n        }\n        return (ans + mod)%mod;\n    }\n};\n```
['Array', 'Brainteaser', 'Sorting', 'Prefix Sum']