There is a row of
apartment buildings in a Westwood that have been abandoned
after finals week. The greedy landlords want to start
demolishing apartments and rebuilding newer ones to make more
money. To destroy the old apartments, two bulldozers approach
the buildings from either ends of the street. It only takes the
bulldozers one hour to destroy each building, so after the
first hour, the two buildings on the two ends of the row will
be destroyed. The robber takes one hour to get into an
apartment building, loot it, and get out, so if the robber
started at time at
one of the endmost houses, he’d be able to successfully rob the
house before getting demolished by the bulldozers. So even if a
bulldozer was right next to an apartment building, the robber
would have enough time to loot it and get out.
The bulldozers work their way closer to the center, as they
destroy an apartment building on either side of the street (a
total of houses) every
hour. When there are an odd number of houses, the last
remaining house is destroyed by one of the bulldozers in the
last hour. The robber can only realistically move to the
adjacent building once it has robbed one, so he cannot decide
to jump multiple buildings over at any point in time. Each
apartment building has a value associated with it as in the
amount that the robber can steal from the building.
What is the maximum amount that the robber can loot from the
row of apartment buildings given that he can keep robbing them
until all of the buildings have been bulldozed?
Input
The first line of input contains a single integer
such that . The second
line of input contains a row of space-separated integers
such that where is the value associated with the house in the row of
houses.
Output
Print a single integer that represents the maximum amount of
money that the robber can steal from the row of houses before
the two bulldozers run over the entire row of houses.
Sample Explanation
Consider the example with houses having values , , , , , and . We will use zero based indexing
in this example. The maximum that the robber can loot from this
row of buildings is .
In the first hour, the robber loots the house at index
thus gaining a value
of . He hops to the
next house, i.e. house at index before the bulldozers destroy
houses at index and
index . He then loots
the house at index and
gains , after which the
robbers destroy houses at index and . The robber then hops to the next
house at index which
he loots and then gets out just in time before the bulldozers
destroy the houses at index and . In this way, the robber gains a
total value of .
Sample Input 1 |
Sample Output 1 |
6
6 4 1 12 7 10
|
29
|
Sample Input 2 |
Sample Output 2 |
8
1 1 100 100 100 1 1 1
|
301
|