[C]
C []\r\n#define MODULO (1000000007)\r\n\r\nstatic int cmp_int_asc(const int * const p1, const int * const p2){\r\n\tif (*p1 < *p2){\r\n\t\treturn -1;\r\n\t}else
```C []\r\n#define MODULO (1000000007)\r\n\r\nstatic int cmp_int_asc(const int * const p1, const int * const p2){\r\n\tif (*p1 < *p2){\r\n\t\treturn -1;\r\n\t}else if (*p1 > *p2){\r\n\t\treturn 1;\r\n\t}else {\r\n\t\treturn 0;\r\n\t}\r\n}\r\n\r\nint sumDistance(\r\n\tint * const nums,\r\n\tconst int numsLen,\r\n\tconst char * const s,\r\n\tconst int d\r\n){\r\n\tfor (int i = 0; i < numsLen; i += 1){\r\n\t\tswitch (s[i]){\r\n\t\tcase \'L\':\r\n\t\t\tnums[i] -= d;\r\n\t\t\tbreak;\r\n\t\tcase \'R\':\r\n\t\t\tnums[i] += d;\r\n\t\t\tbreak;\r\n\t\tdefault:\r\n\t\t\tassert(0);\r\n\t\t}\r\n\t}\r\n\r\n\tqsort(nums, numsLen, sizeof (int), &cmp_int_asc);\r\n\r\n\tint totalCost = 0;\r\n\r\n\tint64_t prefixSum = 0;\r\n\tfor (int i = 1; i < numsLen; i += 1){\r\n\t\tprefixSum += ( (int64_t)nums[i] - nums[i - 1] ) * i;\r\n\t\tprefixSum %= MODULO;\r\n\r\n\t\ttotalCost += prefixSum;\r\n\t\ttotalCost %= MODULO;\r\n\t}\r\n\r\n\treturn totalCost;\r\n}\r\n```
['C']