Problems > Loot on a Ring Road

Loot on a Ring Road

Difficulty: 1600 3000 ms 128 MB

dp

The same no-two-adjacent looting, but the houses form a circle — the first and last house are adjacent too.

Input: the first line has N; the second line has the N loot values.

Output: the maximum loot on the circular street.

Constraints:

  • 1 ≤ N ≤ 105
  • 0 ≤ ai ≤ 104

Sample Tests

Input 1
4
2 3 2 3
Output 1
6
Input 2
1
5
Output 2
5

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.