C++||Easy || 100%faster
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 {\npublic:\n    int getsummation(vector<int> nums){\n               int n=nums.size();\n               int mod=1e9+7;\n       sort(nums.begin(),nums.end());\n       vector<long long >a(n,0);\n       ////// how to find the distance betweeen all pair  in linear time ////\n       for(int i=1;i<n;i++){\n\n            // curr= a[i-1]+ diff*(i-1) + diff;\n            long long curr= (a[i-1]%mod +( ( (long long )nums[i]-(long long )nums[i-1])*1LL*(i) )%mod)%mod;\n            a[i]=curr;\n       }\n     \n        int ans=0;\n       \n       for(int i=0;i<n;i++){\n           ans= (ans%mod + a[i]%mod)%mod;\n       }\n       return ans;\n    }\n    int sumDistance(vector<int>& nums, string s, int d) {\n        \n       int n=nums.size();\n       \n       \n       for(int i=0;i<n;i++){\n         if(s[i]==\'L\'){\n             nums[i]=nums[i]-d;\n         }else nums[i]=nums[i]+d;\n       }\n\n        \n       return getsummation(nums);\n\n    }\n};\n```
['C++']