#K95607. House Robber II

    ID: 38901 Type: Default 1000ms 256MiB

House Robber II

House Robber II

You are given a list of non-negative integers representing the amount of money of each house arranged in a circle. Due to an alarm system, if two adjacent houses are robbed, the police will be alerted. Note that since the houses are arranged in a circle, the first house is the neighbor of the last one.

Your task is to determine the maximum amount of money you can rob without alerting the police.

More formally, if \(nums = [a_1, a_2, \dots, a_n]\) where \(n \ge 0\), find the maximum sum you can obtain subject to the constraint that you cannot select two adjacent elements, and you cannot pick both \(a_1\) and \(a_n\) at the same time. The answer for an empty list is defined to be 0.

inputFormat

The input is given via standard input (stdin) and consists of two lines.

  • The first line contains a single integer \(n\) (\(n \ge 0\)), denoting the number of houses.
  • If \(n > 0\), the second line contains \(n\) space-separated integers representing the amount of money in each house.

outputFormat

Output a single integer representing the maximum amount of money that can be robbed without alerting the police. The output should be written to standard output (stdout).

## sample
3
2 3 2
3