429. House Robber II

0

Medium

As a professional robber, you are planning to rob houses along a street. Each house has a certain amount of money stashed. The houses are arranged in a circle, meaning the first house is adjacent to the last one. However, there is a security system that will alert the police if two adjacent houses are broken into on the same night. Given an integer array nums representing the amount of money in each house, your task is to determine the maximum amount of money you can rob tonight without triggering the security system.

Input Format

The first line of input contains an integer N, representing the size of the array. The second line contains N space-separated integers, describing the money in each house.

Output Format

Print the maximum amount of money you can rob tonight without alerting the police.

Example

Input

3 2 3 2

Output

3

Constraints

1 <= N <= 100
0 <= nums[i] <= 1000
Loading...

View Submissions

Console