[Java] Just ignore the collision
Intuition\n Describe your first thoughts on how to solve this problem. \nWe can ignore the collision, since all robots are same, we can\'t distinct each other. 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe can ignore the collision, since all robots are same, we can\'t distinct each other. **The robots just keep walking with collision.**\n\nSimilar problem: https://leetcode.com/problems/last-moment-before-all-ants-fall-out-of-a-plank/\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSort the final position of all robots and use prefix sum to save time.\n\n**The position is sorted($p_{i-1} <= p_{i}$), so we can use prefix sum.**\n\n$d = |p_i - p_0| + |p_i - p_1| +...+ |p_i - p_{i-1}|$\n$= (p_i - p_0) + (p_i - p_1) +...+ (p_i - p_{i-1})$\n$= i*p_i - (p_0 + p_1+...+p_{i-1})$\n$= i*p_i - \\sum_{j=0}^{i-1}p_j$\n\n# Complexity\n- Time complexity: $$O(N*logN)$$\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\n# Code\n```\nclass Solution {\n  public int sumDistance(int[] nums, String s, int d) {\n    final int modulo = (int) 1e9 + 7;\n    final int n = nums.length;\n    long[] position = new long[n];\n    for (int i = 0; i < n; i++) {\n      position[i] = (s.charAt(i) == \'L\' ? -1L : 1L) * d + nums[i];\n    }\n\n    Arrays.sort(position);\n    long distance = 0;\n    long prefix = 0;\n    for (int i = 0; i < n; i++) {\n      distance = (distance + (i * position[i] - prefix)) % modulo;\n      prefix += position[i];\n    }\n\n    return (int) distance;\n  }\n}\n\n```
['Math', 'Prefix Sum', 'Java']