Skip to content
UPEEC

Non-Adjacent Maximum Sum

Medium#dynamic-programming· solved by 0 · time limit 2.0 s

Pick some elements so that no two picked elements are next to each other, maximising their sum. All values are non-negative.

Input

nn, then nn integers.

Output

The maximum sum.

Constraints

1≤n≤1051 \le n \le 10^5, 0≤ai≤1040 \le a_i \le 10^4

Sample 1

Input

4
1 2 3 1

Output

4

Sample 2

Input

5
2 7 9 3 1

Output

12

Sign in or join free to run and submit your solution.