avoid collision || consider crossing || easy to understand || must see
Code\n\nclass Solution {\npublic:\n    const int mod = 1e9+7;\n    int sumDistance(vector<int>& nums, string s, int d) {\n        vector<long long>result;\n    
# Code\n```\nclass Solution {\npublic:\n    const int mod = 1e9+7;\n    int sumDistance(vector<int>& nums, string s, int d) {\n        vector<long long>result;\n        for(int i = 0 ; i < nums.size() ; i++){\n              long long int currPos = nums[i];\n              char dir     = s[i];\n              \n              if(dir == \'R\'){\n                  currPos = 0LL + currPos + d;\n              }else if(dir == \'L\'){\n                   currPos = 0LL + currPos - d;\n              }\n              result.push_back(currPos);\n        }\n        vector<long long>prefix;\n        sort(result.begin(),result.end());\n        for(int i = 0 ; i < result.size() ; i++){\n              if(prefix.size() == 0) prefix.push_back(result[i]);\n              else{\n                 long long int temp = 0LL + prefix.back() + result[i];\n                 prefix.push_back(temp);\n              }\n        }\n        int sum = 0;\n        for(int i = prefix.size()-1; i >= 0 ; i--){\n             if(i == 0) continue;\n\n             long long int temp = (0LL + ((1LL*i) * result[i]) - prefix[i - 1])%mod;\n             sum = (0LL + sum + temp)%mod;\n        }\n        return sum;\n    }\n};\n```
['Array', 'Brainteaser', 'Sorting', 'Prefix Sum', 'C++']