I, Robot | O(N log(N)) Easy to understand | C++
Intuition\nThe most tricky part is to understand that bouncing robots are the same as non-bouncing robots.\n\nThe second part is to calculate the prefix sum to 
# Intuition\nThe most tricky part is to understand that bouncing robots are the same as non-bouncing robots.\n\nThe second part is to calculate the prefix sum to quickly calculate the distance sum.\n\n# Approach\nApply distances to each robot. Sort $$nums$$ as it does not matter which robot is where, we only need their positions. Use prefix sum to calculate the result;\n```\n   [x0, x1, x2, x3, x4, x5] | N = 6\n   |x1 - x0| + |x2 - x0| + |x3 - x0| + |x4 - x0| + |x5 - x0|\n   since x0 < x1 < x2  < x3  < x4 < x5\n   (x1 - x0) + (x2 - x0) + (x3 - x0) + (x4 - x0) + (x5 - x0)\n   ---------------\n   (x1) + (x2) + (x3) + (x4) + (x5) - (N-1) * x0\n          (x2) + (x3) + (x4) + (x5) - (N-2) * x1\n                 (x3) + (x4) + (x5) - (N-3) * x2\n                        (x4) + (x5) - (N-4) * x3\n                               (x5) - (N-5) * x4\n```\n# Complexity\n- Time complexity: $$O(N*log(N))$$ where N is the number of robots. Sorting is the "longest" part of the algorithm\n\n- Space complexity: $$O(N)$$ where N is the number of robots. \n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n#define MOD 1000000007\n\nclass Solution {\n\npublic:\n    int sumDistance(vector<int>& nums, string s, int d) \n    {\n        const int N = nums.size();\n        unsigned int result = 0;\n        unsigned int t = 0;\n\n        for(int i=0; i < N; i++)\n        {\n            if(s[i] == \'R\')\n                nums[i] += d;\n            else // s[i] == \'L\'\n                nums[i] -= d;\n        }\n\n        // O(N*log(N))\n        sort(nums.begin(), nums.end());\n\n        vector<long> pref(nums.size(), 0);  // O(N)\n        for(int i=0; i < N; i++)\n        {\n            pref[i] = nums[i];\n        }\n        for(int i=N-1-1; i >= 0; i--)\n        {\n            pref[i] = (pref[i] + pref[i+1]);\n        }\n\n        for(int i=0; i < N-1; i++)\n        {\n            t = ( pref[i+1] - ( (N-1-i) * (long)nums[i]) ) % MOD;\n            result = (t+result) % MOD;\n        }\n\n        return result;\n    }\n\n};\n\n// 0->-2 1->0 2->2\n//\n//  0    1   2\n//  L    L   R\n// [-2   0   2]\n// [-1  -1   1]\n// [-2   0   0]\n// [-3  -1   1] -sort-> [-3, -1, 1]\n\n//d: (-3, -1) (-3, 1) (-1, 1) = 8\n\n//   R   L   L\n// [-2   0   2]\n// go through\n// [1   -3  -1] -sort-> [-3, -1, 1]\n////////\n//d: (-3, -1) (-3, 1) (-1, 1) = 8\n\n// x0 < x1 < x2  < x3  < x4 < x5 | N = 6\n// |x1 - x0| + |x2 - x0| + |x3 - x0| + |x4 - x0| + |x5 - x0|\n// since x0 < x1 < x2  < x3  < x4 < x5\n// (x1 - x0) + (x2 - x0) + (x3 - x0) + (x4 - x0) + (x5 - x0)\n// (x1) + (x2) + (x3) + (x4) + (x5) - (N-1) * x0\n//        (x2) + (x3) + (x4) + (x5) - (N-2) * x1\n//               (x3) + (x4) + (x5) - (N-3) * x2\n//                      (x4) + (x5) - (N-4) * x3\n//                             (x5) - (N-5) * x4\n\n\n```
['C++']