#include #include using namespace std; int CalcMaxValue(int n, int index, int* values, int* memo) { if (index >= n) return 0; if (memo[index] == 0) { memo[index] = max( values[index] + CalcMaxValue(n, index + 2, values, memo), CalcMaxValue(n, index + 1, values, memo)); } return memo[index]; } int main() { int n; cin >> n; int memo[1000]; int values[1000]; for (int i = 0; i < n; i++) { cin >> values[i]; memo[i] = 0; } cout << CalcMaxValue(n, 0, values, memo) << endl; return 0; }