C++ 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:\n  int sumDistance(vector<int>& nums, string s, int d) {\n    constexpr int kMod = 1\'000\'000\'007;\n    const int n = nums.size();\n    int ans = 0;\n    int prefix = 0;\n    vector<int> pos;\n\n    for (int i = 0; i < nums.size(); ++i)\n      if (s[i] == \'L\')\n        pos.push_back(nums[i] - d);\n      else\n        pos.push_back(nums[i] + d);\n\n    sort(pos.begin(), pos.end());\n\n    for (int i = 0; i < n; ++i) {\n      ans = ((ans + 1LL * i * pos[i] - prefix) % kMod + kMod) % kMod;\n      prefix = ((0LL + prefix + pos[i]) % kMod + kMod) % kMod;\n    }\n\n    return ans;\n  }\n};\n\n```
['C++']