C++||Most Easy Solution Using Simple Logic+Prefix Sum
\ntypedef long long ll;\nll mod=1e9+7;\nclass Solution {\npublic:\n    int sumDistance(vector<int>& nums, string s, int d) {\n        ll n=s.size();\n        fo
```\ntypedef long long ll;\nll mod=1e9+7;\nclass Solution {\npublic:\n    int sumDistance(vector<int>& nums, string s, int d) {\n        ll n=s.size();\n        for(int i=0;i<n;i++)\n        {\n            if(s[i]==\'R\')\n                nums[i]+=d;\n            else\n                nums[i]-=d;\n        }\n        vector<ll> pref(n,0);\n        sort(nums.begin(),nums.end());\n        pref[0]=nums[0];\n        pref[n-1]=nums[n-1];\n        for(int i=1;i<n;i++)\n            pref[i]=pref[i-1]+nums[i];\n        ll ans=0;\n        ll cnt=1;\n        for(int i=1;i<n;i++)\n        {\n            ans=(ans+(cnt*nums[i])-pref[i-1]);\n            ans=ans%mod;\n            cnt++;\n        } \n        return ans%mod;\n    }\n};\n```
[]