PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000180. Tổng lẻ lớn nhất (Odd Sum)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tổng lẻ lớn nhất (Odd Sum)

Odd Sum

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given nn integers a1,a2,…,ana_1,a_2,\ldots,a_n, possibly positive or negative. You may choose a subsequence, obtained by deleting some elements while preserving the order of those retained. The sum of the chosen numbers must be odd. It is guaranteed that at least one valid subsequence exists. Find the maximum possible odd sum.

Input

Line 1 contains the integer nn, the sequence length.

Line 2 contains exactly nn integers a1,a2,…,ana_1,a_2,\ldots,a_n in their original order. At least one element is odd.

Output

Print one integer: the largest odd sum of a valid subsequence.

Subtasks

  • Subtask 1 (20 points): 1≤n≤121\le n\le 12; −104≤ai≤104-10^4\le a_i\le10^4 for every 1≤i≤n1\le i\le n; at least one aia_i is odd.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; −104≤ai≤104-10^4\le a_i\le10^4 for every 1≤i≤n1\le i\le n; at least one aia_i is odd.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; −104≤ai≤104-10^4\le a_i\le10^4 for every 1≤i≤n1\le i\le n; at least one aia_i is odd.

Examples

Example 1

Input

4
-2 2 -3 1

Output

3

Explanation

The sequence is −2,2,−3,1-2,2,-3,1. Selecting 22 and 11 gives the odd sum 33. All other elements are negative, so including them cannot improve this sum. The sum of all positive elements is already 33.

Example 2

Input

3
2 -5 -3

Output

-1

Explanation

The only positive element contributes 22, which is even. Adding −3-3 gives −1-1, whereas adding −5-5 gives −3-3. The former is the larger odd sum, and no other choice can improve it.