Curious subsequences

In this problem, we will say that a (sub)sequence of integer numbers is
curious if it does not have two consecutive numbers whose sum is even.
Given a sequence of n integer numbers, what is the maximum sum of
elements of all its curious subsequences?

For instance, for 8 10 101 100 120 the maximum sum is 231, corresponding
to 10 101 120.

Input

Input consists of several cases, each one with n followed by n integer
numbers between −10⁹ and 10⁹. Assume 1 ≤ n ≤ 10⁷.

Output

Print the maximum possible sum for every case.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T11:56:24.260Z

© Jutge.org, 2006–2026.
https://jutge.org
