788A.md (1559B)
1 Source: https://codeforces.com/problemset/problem/788/A 2 3 A. Functions again 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function *f*, which is defined as follows: 22 23  24 25 In the above formula, 1 ≤ *l* < *r* ≤ *n* must hold, where *n* is the size of the Main Uzhlyandian Array *a*, and |*x*| means absolute value of *x*. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of *f* among all possible values of *l* and *r* for the given array *a*. 26 27 Input 28 29 The first line contains single integer *n* (2 ≤ *n* ≤ 105) — the size of the array *a*. 30 31 The second line contains *n* integers *a*1, *a*2, ..., *a**n* (-109 ≤ *a**i* ≤ 109) — the array elements. 32 33 Output 34 35 Print the only integer — the maximum value of *f*. 36 37 Examples 38 39 Input 40 41 ``` 42 5 43 1 4 2 3 1 44 ``` 45 46 Output 47 48 ``` 49 3 50 ``` 51 52 Input 53 54 ``` 55 4 56 1 5 4 7 57 ``` 58 59 Output 60 61 ``` 62 6 63 ``` 64 65 Note 66 67 In the first sample case, the optimal value of *f* is reached on intervals [1, 2] and [2, 5]. 68 69 In the second case maximal value of *f* is reachable only on the whole array.