50ms beats 100% solve by sorting, prefix and suffix
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: $$O(nlgn)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int sumDistance(vector<int>& nums, string s, int d) {\n        vector<long long> n;\n        for(int i = 0;i < nums.size();i++){\n            if(s[i] == \'R\') n.push_back((long long)nums[i] + d);\n            else n.push_back((long long)nums[i] - d);\n        }\n\n        sort(n.begin(), n.end());\n\n        long long prefix = 0, suffix = 0, ans = 0, mod = 1e9 + 7, cnt = 0;\n        for(auto i : n) suffix += i;\n\n        for(int i = 0;i < n.size();i++){\n            ans += ((n[i] * i - prefix) + suffix - (n[i] * (n.size() - i))) / 2;\n            cnt += ((n[i] * i - prefix) + suffix - (n[i] * (n.size() - i))) % 2;\n            suffix -= n[i];\n            prefix += n[i];\n            ans %= mod;\n        } \n\n        return ans + (cnt / 2);\n    }\n};\n\nauto init = []()\n{ \n    ios::sync_with_stdio(0);\n    cin.tie(0);\n    cout.tie(0);\n    return \'c\';\n}();\n```
['Array', 'Brainteaser', 'Suffix Array', 'Sorting', 'Prefix Sum', 'C++']