Company: Nutanix
Difficulty: hard
# Terminators There are `N` robots in a row. Robot `i` has integer value `A[i]`. While more than one robot remains, choose two adjacent robots. If a robot of value `x` terminates its neighbor of value `y`, the neighbor disappears and the surviving robot's value becomes `x - y`. At every step either member of the chosen adjacent pair may be the survivor. Find the maximum possible value of the final robot. ## Input Format - The first line contains `N`. - The second line contains `N` space-separated integers. ## Output Format Print the maximum possible final value. ## Constraints - `1 <= N <= 500000` - `-1000000000 <= A[i] <= 1000000000` - Use 64-bit arithmetic. ## Example Input: 4 2 1 2 1 Output: 4 ## Notes - The order of the surviving robots never changes. - For `N = 1`, no operation is performed and the answer is `A[1]`.