#P5990. Maximum Even Sum

    ID: 19215 Type: Default 1000ms 256MiB

Maximum Even Sum

Maximum Even Sum

You are given n integers. Your task is to select a subset of these numbers (possibly empty) such that the sum is even, and the sum is maximized.

Note that the sum of an empty subset is 0, which is considered even.

Formally, let \( S \) be the set of selected numbers. You need to maximize:

$$\max\left\{\sum_{x\in S} x : \sum_{x\in S} x \equiv 0 \pmod{2} \right\}$$

inputFormat

The first line contains an integer n (1 ≤ n ≤ 105), the number of elements.

The second line contains n space-separated integers, each in the range \(-10^9\) to \(10^9\).

outputFormat

Output a single integer denoting the maximum even sum obtainable by selecting a subset of the given numbers.

sample

3
4 3 2
6