#include
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;
}