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