Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/dp-qoshni-bolmagan-uylar

Non-adjacent houses

Easy 1000 ms 128 MB 27%
Share

$n$ houses stand in a row on a street; the owner of the $i$-th house is ready to donate $a_{i}$ soums to charity. A charity picks some of the houses and collects money, but never visits both of two adjacent houses. What is the largest amount that can be collected?

A row of houses, each with an amount of money; the non-adjacent houses with the largest total are highlighted

Input

The first line contains a positive integer $n$. The second line contains $n$ space-separated integers $a_{i}$.

Output

One integer — the largest amount that can be collected.

Note

$1 \le n \le 10^{5}$
$0 \le a_{i} \le 10^{9}$

Examples

Input #1
5
2 7 9 3 1
Output #1
12
Input #2
1
0
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.