package main import . "fmt" import . "os" import bf "bufio" func main() { rd := bf.NewReader(Stdin) var n, a int Fscan(rd, &n, &a) plus, minus := -a, 0 hasMinus := false for i := 1; i < n; i++ { Fscan(rd, &a) if hasMinus { plus, minus = max(plus, minus-a, -a), max(minus, plus+a) } else { plus, minus = max(plus, -a), plus+a hasMinus = true } } if hasMinus { Println(max(plus, minus)) } else { Println(plus) } }