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:0(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: 0(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int sumDistance(vector<int>& nums, string s, int d) {\n       int mod = 1e9 + 7;\n       // first we will ignore the collision \n       // we will just substract and add the positions\n       // That\'s how we will not need to convert and remind the positions of the robots\n\n          for (long long i=0;i<nums.size();i++)\n          {\n              // if direction is left, then it will be moved to left after d seconds\n              if (s[i] == \'L\')\n                 nums[i] -= d;\n\n              // if direction is right then just add the d seconds in current position\n              if (s[i] ==\'R\')\n                  nums[i] += d;   \n          } \n\n          // now we need to add the differences between all pairs\n          // first we will sort all the position to find the sum in 0(n);\n          sort(nums.begin(),nums.end());\n\n          // now we will add the presum in the vector named as presum\n          vector<long long>presum(nums.begin(),nums.end());\n          for (long long i=1;i<presum.size();i++)\n          {\n              presum[i] += presum[i-1];\n              presum[i] %= mod;\n          }\n          \n          long long ans = 0;\n          // here we have just optimized the equation as\n          // as for every i \n          // we will do \n          // (nums[i] - nums[0]) +(nums[i] - nums[1]) + (nums[i] - nums[2]) + ---\n          // (nums[i] - nums[i-1])\n\n          // So above equation will be equivalent to \n          // i*nums[i]- (nums[0] + nums[1] + nums[2] + --- nums[i-1])\n          // i*nums[i] - (prefix sum till i-1) \n\n\n          for (long long i=1;i<nums.size();i++)\n          {\n              ans += i * nums[i] - presum[i - 1];\n              ans %= mod; \n          }\n          return ans;\n    }\n};\n```
['C++']