{"raw_statement":[{"iden":"problem statement","content":"You are given an integer sequence $A=(A_1,A_2,\\dots,A_N)$ of length $N$.\nYou can rearrange $A$ freely. Find the maximum value that $\\sum_{i=1}^{N-1} ((A_{i+1} - A_i) \\bmod K)$ can take after rearranging.\nHere, $x \\bmod K$ denotes the integer $y$ such that $0 \\le y < K$ and $x - y$ is a multiple of $K$. For example, $-3 \\bmod 8 = 5$, and $9 \\bmod 6 = 3$."},{"iden":"constraints","content":"*   $2 \\le N \\le 2 \\times 10^5$\n*   $1 \\le K \\le 10^9$\n*   $0 \\le A_i < K$"},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$ $K$\n$A_1$ $A_2$ $\\dots$ $A_N$"},{"iden":"sample input 1","content":"3 4\n0 1 2"},{"iden":"sample output 1","content":"6\n\nOne optimal solution is to rearrange $A$ into $(2,1,0)$ to achieve $(1 - 2) \\bmod 4 + (0 - 1) \\bmod 4 = 3 + 3 = 6$."},{"iden":"sample input 2","content":"7 123\n11 34 56 0 32 100 78"},{"iden":"sample output 2","content":"638"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}