SDE Path

House Robber Problem

Medium

House Robber Problem

Given house values arranged in a circle, maximize loot without robbing two adjacent houses.

Input format

The first line contains N. The second line contains N amounts (houses in a CIRCLE, 0–100).

Output format

Print maximum loot without robbing adjacent houses.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
4
1 2 3 1
Expected output
4
Example 2
Input
3
2 3 2
Expected output
3