#arc147c. [arc147_c]Min Diff Sum
[arc147_c]Min Diff Sum
Problem Statement
people, numbered , are going to stand on the number line. Let's denote by the coordinate the Person stands at. Then, should be an integer satisfying . Multiple people can occupy the same coordinate.
We define the dissatisfaction level as the following formula:
$\\displaystyle\\sum_{i=1}^{N-1}\\sum_{j=i+1}^{N}|x_j-x_i|$
Find the minimum possible value of the dissatisfaction level.
Constraints
- $1 \\leq L_i \\leq R_i \\leq 10^7 \\,(1 \\leq i \\leq N)$
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3
1 3
2 4
5 6
Sample Output 1
4
If we let , we get the dissatisfaction level of . We cannot make it or less, so the answer is .
Sample Input 2
3
1 1
1 1
1 1
Sample Output 2
0
Sample Input 3
6
1 5
2 4
1 1
4 4
3 6
3 3
Sample Output 3
15