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

#PS0000289. Tổng lớn nhất tại vị trí chẵn (Maximum Sum on Even Positions)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tổng lớn nhất tại vị trí chẵn (Maximum Sum on Even Positions)

Maximum Sum on Even Positions

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given a positive integer array indexed from zero, reverse at most one contiguous subarray, or leave it unchanged. Maximize the sum of elements at even indices.

Input

First line: nn. Second line: nn integers a0,…,an−1a_0,\ldots,a_{n-1}. Each input contains one test case.

Output

Print the maximum attainable sum.

Subtasks

  • Subtask 1 (20 points): 1≤n≤2000001\le n\le200000, 1≤ai≤1091\le a_i\le10^9. Additionally: n≤30n\le30.
  • Subtask 2 (30 points): 1≤n≤2000001\le n\le200000, 1≤ai≤1091\le a_i\le10^9. Additionally: all elements are equal.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le200000, 1≤ai≤1091\le a_i\le10^9.

Example 1

Input

8
1 7 3 4 7 6 2 9

Output

26

Explanation

Reverse indices [0,7] to obtain [9, 2, 6, 7, 4, 3, 7, 1]. The even-index sum is 9+6+4+7 = 26.

Example 2

Input

5
1 2 1 2 1

Output

5

Explanation

Reverse indices [0,3] to obtain [2, 1, 2, 1, 1]. The even-index sum is 2+2+1 = 5.

Example 3

Input

10
7 8 4 5 7 6 8 9 7 3

Output

37

Explanation

Reverse indices [1,2] to obtain [7, 4, 8, 5, 7, 6, 8, 9, 7, 3]. The even-index sum is 7+8+7+8+7 = 37.

Example 4

Input

4
3 1 2 1

Output

5

Explanation

Reverse indices [0,0] to obtain [3, 1, 2, 1]. The even-index sum is 3+2 = 5.