Codeforces Round 276 (Div. 1)
D
Kindergarten
Codeforces
2400
原题
← CE →
翻译中…

In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should be a nonempty segment of consecutive children of a line. A group's sociability is the maximum difference of charisma of two children in the group (in particular, if the group consists of one child, its sociability equals a zero).

翻译中…

The teacher wants to divide the children into some number of groups in such way that the total sociability of the groups is maximum. Help him find this value.

翻译中…

Input

翻译中…

The first line contains integer $*n*$ — the number of children in the line ($1 ≤ *n* ≤ 10^{6}$).

翻译中…

The second line contains $*n*$ integers $*a*_{*i*}$ — the charisma of the $*i*$-th child ($- 10^{9} ≤ *a*_{*i*} ≤ 10^{9}$).

翻译中…

Output

翻译中…

Print the maximum possible total sociability of all groups.

翻译中…

Note

翻译中…

In the first test sample one of the possible variants of an division is following: the first three children form a group with sociability 2, and the two remaining children form a group with sociability 1.

翻译中…

In the second test sample any division leads to the same result, the sociability will be equal to 0 in each group.

翻译中…

样例

Input #1
5
1 2 3 1 2
Output #1
3
InputCopy OutputCopy
Input #2
3
3 3 3
Output #2
0
InputCopy OutputCopy
题目信息
题号
484D
时间限制
2 s
内存限制
256 MB
标签
数据结构
动态规划
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。