{"problem":{"name":"Min Diff Sum","description":{"content":"$N$ people, numbered $1,2,\\ldots ,N$, are going to stand on the number line. Let's denote by $x_i$ the coordinate the Person $i$ stands at. Then, $x_i$ should be an integer satisfying $L_i \\leq x_i \\l","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"arc147_c"},"statements":[{"statement_type":"Markdown","content":"$N$ people, numbered $1,2,\\ldots ,N$, are going to stand on the number line. Let's denote by $x_i$ the coordinate the Person $i$ stands at. Then, $x_i$ should be an integer satisfying $L_i \\leq x_i \\leq R_i$. Multiple people can occupy the same coordinate.\nWe define the **dissatisfaction level** as the following formula:\n\n> $\\displaystyle\\sum_{i=1}^{N-1}\\sum_{j=i+1}^{N}|x_j-x_i|$\n\nFind the minimum possible value of the dissatisfaction level.\n\n## Constraints\n\n*   $2 \\leq N \\leq 3 \\times 10^5$\n*   $1 \\leq L_i \\leq R_i \\leq 10^7 \\,(1 \\leq i \\leq N)$\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$\n$L_1$ $R_1$\n$L_2$ $R_2$\n$\\vdots$\n$L_N$ $R_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"arc147_c","tags":[],"sample_group":[["3\n1 3\n2 4\n5 6","4\n\nIf we let $x_1=3,x_2=4,x_3=5$, we get the dissatisfaction level of $4$. We cannot make it $3$ or less, so the answer is $4$."],["3\n1 1\n1 1\n1 1","0"],["6\n1 5\n2 4\n1 1\n4 4\n3 6\n3 3","15"]],"created_at":"2026-03-03 11:01:13"}}