{"problem":{"name":"I. Inverted Signs","description":{"content":"Arya lives in a magical world. You can view it as a number line.  There are N citizens in total. The i-th citizen have his own house in position i with height Hi, Noted that Hi could be non positive,","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10152I"},"statements":[{"statement_type":"Markdown","content":"Arya lives in a magical world. You can view it as a number line. \n\nThere are N citizens in total. The i-th citizen have his own house in position i with height Hi, Noted that Hi could be non positive, which means their house is actually built beneath the horizon.\n\nArya is the hand of the king and she thinks that the buildings are a bit out of order. She denote the chaos index of the world as .\n\nNoted that hi could be equal to zero as the world is magical.\n\nShe feels that the current chaos index of the world is too high. So she designs to change the world a bit by using her super power.\n\nShe could flip a continuous sequence of building, i.e., she could choose two arbitrary integer L and R, where 1 ≤ L ≤ R ≤ N, and invert the signs of Hi for all L ≤ i ≤ R (positive to negative and vice versa).\n\nAs Arya is weak, she would only do this operation exactly once. Arya wants to minimize the chaos index after the operation. Being a good guy, help Arya to find the lowest possible chaos index after exactly flipping one continuous sequence of building.\n\nThe first line contains an integer N. (1 ≤ N ≤ 106)\n\nThe second line consist of N integers, the i-th integer is Hi. ( - 109 ≤ Hi ≤ 109)\n\nOutput consist only one integer in a single line, the lowest possible chaos index after exactly flipping one continuous sequence of building.\n\nIn the first sample, Arya should flip house 2 to 3, so that the heights become 1, 2, 3, 4 and the chaos index would be |2 - 1| + |3 - 2| + |4 - 3| = 3.\n\n|x - y| is the absolute difference between x and y.\n\n## Input\n\nThe first line contains an integer N. (1 ≤ N ≤ 106)The second line consist of N integers, the i-th integer is Hi. ( - 109 ≤ Hi ≤ 109)\n\n## Output\n\nOutput consist only one integer in a single line, the lowest possible chaos index after exactly flipping one continuous sequence of building.\n\n[samples]\n\n## Note\n\nIn the first sample, Arya should flip house 2 to 3, so that the heights become 1, 2, 3, 4 and the chaos index would be |2 - 1| + |3 - 2| + |4 - 3| = 3.|x - y| is the absolute difference between x and y.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ N \\in \\mathbb{Z}^+ $ be the number of buildings.  \nLet $ H = (h_1, h_2, \\dots, h_N) $ be the sequence of building heights, where $ h_i \\in \\mathbb{Z} $.  \n\nThe **chaos index** is defined as:  \n$$\nC(H) = \\sum_{i=1}^{N-1} |h_{i+1} - h_i|\n$$\n\nA **flip operation** on interval $[L, R]$ (with $1 \\leq L \\leq R \\leq N$) transforms $ H $ into $ H' $, where:  \n$$\nh'_i = \n\\begin{cases}\n-h_i & \\text{if } L \\leq i \\leq R \\\\\nh_i & \\text{otherwise}\n\\end{cases}\n$$\n\n**Constraints**  \n1. $ 1 \\leq N \\leq 10^6 $  \n2. $ -10^9 \\leq h_i \\leq 10^9 $ for all $ i \\in \\{1, \\dots, N\\} $  \n3. Exactly one flip operation must be performed on some contiguous interval $[L, R]$.\n\n**Objective**  \nFind the minimum possible chaos index after exactly one flip:  \n$$\n\\min_{1 \\leq L \\leq R \\leq N} C(H')\n$$","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10152I","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}