{"raw_statement":[{"iden":"problem statement","content":"We have a _pancake tower_ which is a pile of $N$ pancakes. Initially, the $i$\\-th pancake from the top $(1 \\leq i \\leq N)$ has a size of $A_i$. Takahashi, a chef, can do the following operation at most once.\n\n*   Choose integers $l$ and $r$ $(1 \\leq l \\lt r \\leq N)$ and turn the $l$\\-th through $r$\\-th pancakes upside down, reversing the order.\n\nFind the minimum possible **ugliness** of the tower after the operation is done (or not), defined below:\n\n> the ugliness is the sum of the differences of the sizes of adjacent pancakes;  \n> that is, the value $|A^{\\prime}_1 - A^{\\prime}_2| + |A^{\\prime}_2 - A^{\\prime}_3| + \\cdots + |A^{\\prime}_{N-1} - A^{\\prime}_N|$, where $A^{\\prime}_i$ is the size of the $i$\\-th pancake from the top."},{"iden":"constraints","content":"*   $2 \\leq N \\leq 300000$\n*   $1 \\leq A_i \\leq 10^9$\n*   All values in input are integers."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$\n$A_1$ $A_2$ $\\cdots$ $A_N$"},{"iden":"sample input 1","content":"5\n7 14 12 2 6"},{"iden":"sample output 1","content":"17\n\nIf we do the operation choosing $l = 2$ and $r = 5$, the pancakes will have the sizes of $7, 6, 2, 12, 14$ from top to bottom.\nThe ugliness here is $|7-6| + |6-2| + |2-12| + |12-14| = 1 + 4 + 10 + 2 = 17$. This is the minimum value possible; there is no way to achieve less ugliness."},{"iden":"sample input 2","content":"3\n111 119 999"},{"iden":"sample output 2","content":"888\n\nIn this sample, not doing the operation minimizes the ugliness.\nIn that case, the pancakes will have the sizes of $111, 119, 999$ from top to bottom, for the ugliness of $|111-119| + |119-999| = 8 + 880 = 888$."},{"iden":"sample input 3","content":"6\n12 15 3 4 15 7"},{"iden":"sample output 3","content":"19\n\nIf we do the operation choosing $l = 3$ and $r = 5$, the pancakes will have the sizes of $12, 15, 15, 4, 3, 7$ from top to bottom.\nThe ugliness here is $|12-15| + |15-15| + |15-4| + |4-3| + |3-7| = 3 + 0 + 11 + 1 + 4 = 19$, which is the minimum value possible."},{"iden":"sample input 4","content":"7\n100 800 500 400 900 300 700"},{"iden":"sample output 4","content":"1800\n\nIf we do the operation choosing $l = 2$ and $r = 4$, the pancakes will have the sizes of $100, 400, 500, 800, 900, 300, 700$ from top to bottom, for the ugliness of $1800$."},{"iden":"sample input 5","content":"10\n535907999 716568837 128214817 851750025 584243029 933841386 159109756 502477913 784673597 603329725"},{"iden":"sample output 5","content":"2576376600"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}