#include <iostream>
#include <vector>
#include <utility>
using namespace std;
int main(){
int n;
cin >> n;
if (n < 3) {
cout << "0" << endl
return 0;
}
vector<int> nums(n);
vector<pair<int, int>> best(n);
cin >> nums[0];
cin >> nums[1];
best[2] = {nums[1], nums[1]};
cin >> nums[2];
int maxim = nums[1];
for (int i = 3; i < n; ++i) {
cin >> nums[i];
int add = max(best[i-3].first, best[i-3].second);
best[i] = {nums[i-1] + add, maxim};
maxim = best[i].first > maxim ? best[i].first : maxim;
}
cout << maxim << endl;
return 0;
}