CF BUDDY
← Problems·

1372D · Omkar and Circle

2100 · brute force, dp, games

Problem: Danny, the local Math Maniac, is fascinated by circles, Omkar's most recent creation. Help him solve this circle problem!

You are given nn nonnegative integers a1,a2,,ana_1, a_2, \dots, a_n arranged in a circle, where nn must be odd (ie. n1n-1 is divisible by 22). Formally, for all ii such that 2in2 \leq i \leq n, the elements ai1a_{i - 1} and aia_i are considered to be adjacent, and ana_n and a1a_1 are also considered to be adjacent. In one operation, you pick a number on the circle, replace it with the sum of the two elements adjacent to it, and then delete the two adjacent elements from the circle. This is repeated until only one number remains in the circle, which we call the circular value.

Help Danny find the maximum possible circular value after some sequences of operations.

Input Format: The first line contains one odd integer nn (1n<21051 \leq n < 2 \cdot 10^5, nn is odd)  — the initial size of the circle.

The second line contains nn integers a1,a2,,ana_{1},a_{2},\dots,a_{n} (0ai1090 \leq a_{i} \leq 10^9)  — the initial numbers in the circle.

Output Format: Output the maximum possible circular value after applying some sequence of operations to the given circle.

Note: For the first test case, here's how a circular value of 1717 is obtained:

Pick the number at index 33. The sum of adjacent elements equals 1717. Delete 77 and 1010 from the circle and replace 22 with 1717.

Note that the answer may not fit in a 3232-bit integer.

Sample Cases

Case 1

Input

3
7 10 2

Output

17

Case 2

Input

1
4

Output

4

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback