LogiQuest

225. House Robber

MediumDynamic Programming

Houses in a row hold some money. You cannot rob two adjacent houses. Print the maximum amount you can rob.

Input format

Line 1: n Line 2: n non-negative integers

Output format

The maximum amount.

Example 1

Input

4
1 2 3 1

Output

4

Example 2

Input

5
2 7 9 3 1

Output

12

Constraints

1 ≤ n ≤ 10⁵

Read input from standard input and print the answer to standard output. Your code is judged against 6 test cases, most of them hidden.

Loading the MyLoginn IDE…