{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv\u003e\u003cp\u003eA straight dirt road connects two fields on FJ\u0027s farm, but it changes elevation more than FJ would like. His cows do not mind climbing up or down a single slope, but they are not fond of an alternating succession of hills and valleys. FJ would like to add and remove dirt from the road so that it becomes one monotonic slope (either sloping up or down).\u003c/p\u003e\u003cp\u003eYou are given \u003ci\u003eN\u003c/i\u003e integers \u003ci\u003eA\u003c/i\u003e\u003csub\u003e1\u003c/sub\u003e, ... , \u003ci\u003eA\u003csub\u003eN\u003c/sub\u003e\u003c/i\u003e (1 ≤ \u003ci\u003eN\u003c/i\u003e ≤ 2,000) describing the elevation (0 ≤ \u003ci\u003eA\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e ≤ 1,000,000,000) at each of \u003ci\u003eN\u003c/i\u003e equally-spaced positions along the road, starting at the first field and ending at the other. FJ would like to adjust these elevations to a new sequence \u003ci\u003eB\u003c/i\u003e\u003csub\u003e1\u003c/sub\u003e, . ... , \u003ci\u003eB\u003csub\u003eN\u003c/sub\u003e\u003c/i\u003e that is either nonincreasing or nondecreasing. Since it costs the same amount of money to add or remove dirt at any position along the road, the total cost of modifying the road is\u003c/p\u003e\u003cblockquote\u003e|\u003ci\u003eA\u003c/i\u003e\u003csub\u003e1 \u003c/sub\u003e- \u003ci\u003eB\u003c/i\u003e\u003csub\u003e1\u003c/sub\u003e| + |\u003ci\u003eA\u003c/i\u003e\u003csub\u003e2 \u003c/sub\u003e- \u003ci\u003eB\u003c/i\u003e\u003csub\u003e2\u003c/sub\u003e| + ... + |\u003ci\u003eA\u003csub\u003eN\u003c/sub\u003e\u003c/i\u003e - \u003ci\u003eB\u003csub\u003eN\u003c/sub\u003e\u003c/i\u003e |\u003c/blockquote\u003e\u003cp\u003ePlease compute the minimum cost of grading his road so it becomes a continuous slope. FJ happily informs you that signed 32-bit integers can certainly be used to compute the answer.\u003c/p\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003e* Line 1: A single integer: \u003ci\u003eN\u003c/i\u003e\u003cbr\u003e* Lines 2..\u003ci\u003eN\u003c/i\u003e+1: Line \u003ci\u003ei\u003c/i\u003e+1 contains a single integer elevation: \u003ci\u003eA\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e \u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003e* Line 1: A single integer that is the minimum cost for FJ to grade his dirt road so it becomes nonincreasing or nondecreasing in elevation.\u003c/p\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e7\r\n1\r\n3\r\n2\r\n4\r\n5\r\n3\r\n9\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e3\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}