cswork / OAOpen practice workspace

CiscoOA #30

Maximum Chocolates from Jars (LeetCode 198)

Estimated MediumJudge-ready

Topics (AI-labelled)DP Basics

Each jar holds a non-negative integer number of chocolates. Take some jars from a row of jars, without taking two adjacent jars, and find the maximum number of chocolates. You may take no jars at all.

Input

First n is given, then n non-negative counts. The original bound 1≤n≤1000 is kept. The original upper bound on values is missing; this site adds 0..10^9 and does not adopt the unsourced cap of 10000 from the catalog.

Output

Output a single integer, the answer.

Example 1

Input:

4
5 1 1 5

Output:

10

Example 2

Input:

1
1

Output:

1

Example 3

Input:

3
0 0 0

Output:

0

Example notes

The outputs of the three public examples are, in order: 10; 1; 0. Verified by independent enumeration or direct simulation.

Editorial

Loading solution…