Java + No need to consider collision
Intuition\nWhen two robots collide with each other, we can just swap them and then it seems that they just go through each other. So we don\'t need to consider 
# Intuition\nWhen two robots collide with each other, we can just swap them and then it seems that they just go through each other. So we don\'t need to consider collision.\n\n# Approach\n* Get the positions of robots without considering collisions after `d` seconds\n* Sort the positions array to make the sum of pairs of distance easier.\n\n# Complexity\n- Time complexity:\n`O(nlogn)` where `n` is length of `nums`\n\n- Space complexity:\n`O(n)` for the `long` positions array\n\n# Code\n```\nclass Solution {\n    public int sumDistance(int[] nums, String s, int d) {\n        int mod = (int)(1e9 + 7);\n        int n = nums.length;\n        long[] positions = new long[n];\n        for (int i = 0; i < n; i++) {\n            if (s.charAt(i) == \'R\') {\n                positions[i] = (long)nums[i] + d;\n            } else {\n                positions[i] = (long)nums[i] - d;\n            }\n        }\n        Arrays.sort(positions);\n        long res = 0L;\n        long preSum = 0L;\n        for (int i = 1; i < n; i++) {\n            long cur = preSum + i * (positions[i] - positions[i-1]);\n            res = (res + cur) % mod;\n            preSum = cur;\n        }\n        return (int)res;\n    }\n}\n```
['Java']