#include <iostream>
using namespace std;
void houseRobbery(int houseCount, unsigned long *maxSum, unsigned long *initialHouses) {
/*
A function that, through dynamic programming, calculates the maximum production of houses not standing nearby.
The function does not return anything, since it modifies arrays through pointers
*/
// Initial state values for the first two houses
maxSum[0] = initialHouses[0];
maxSum[1] = max(initialHouses[0], initialHouses[1]);
// Since by condition it is given that we cannot rob two houses in a row,
// then we will take the maximum house of two: maxSum[i - 1] and maxSum[i - 2] + initialHouses[house]
// (where initialHouses[house] is the amount of money in the i-th house)
for (int house = 2; house < houseCount; house += 1) {
maxSum[house] = max(maxSum[house - 1], maxSum[house - 2] + initialHouses[house]);
}
}
int main() {
int houseCount;
cin >> houseCount;
// Initialize the arrays not containing negative values
unsigned long initialHouses[houseCount], maxSum[houseCount];
// Filling the initial array of houses with user input
for (int element = 0; element < houseCount; element += 1) {
cin >> initialHouses[element];
}
// Calling the function
houseRobbery(houseCount, maxSum, initialHouses);
cout << maxSum[houseCount - 1];
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgogCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAKdm9pZCBob3VzZVJvYmJlcnkoaW50IGhvdXNlQ291bnQsIHVuc2lnbmVkIGxvbmcgKm1heFN1bSwgdW5zaWduZWQgbG9uZyAqaW5pdGlhbEhvdXNlcykgewoJLyoKCUEgZnVuY3Rpb24gdGhhdCwgdGhyb3VnaCBkeW5hbWljIHByb2dyYW1taW5nLCBjYWxjdWxhdGVzIHRoZSBtYXhpbXVtIHByb2R1Y3Rpb24gb2YgaG91c2VzIG5vdCBzdGFuZGluZyBuZWFyYnkuCglUaGUgZnVuY3Rpb24gZG9lcyBub3QgcmV0dXJuIGFueXRoaW5nLCBzaW5jZSBpdCBtb2RpZmllcyBhcnJheXMgdGhyb3VnaCBwb2ludGVycwoJKi8KCQoJLy8gSW5pdGlhbCBzdGF0ZSB2YWx1ZXMgZm9yIHRoZSBmaXJzdCB0d28gaG91c2VzCgltYXhTdW1bMF0gPSBpbml0aWF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