#include <bits/stdc++.h>
using namespace std;
// clang-format off
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { T value; is >> value; v.push_back(value); return is; }
#define preamble ios::sync_with_stdio(0); cin.tie(0); dbg("INIT");
// clang-format on
#ifdef DO_DBG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<bool> vb;
typedef set<ll> si;
typedef pair<ll, ll> pi;
typedef vector<pair<ll, ll>> vpi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
const int MAX_N = 1e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;
#define loop(n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sq(x) ((x) * (x))
vector<ull> x;
int n;
vector<ull> ready;
vector<ull> memo;
// we solve this with dynamic programming:
// the parameter i is the index of the middle card to be picked.
// we go from left to right, so 0 to... n-2, the second last card
ull dp(int i) {
// can't pick past the second last card
if (i > n - 2)
return 0;
// use memoization
if (ready[i])
return memo[i];
// if we pick the card at x[i], we can move to the subproblem of
// whether we pick the next possible card at [i+3].
// if we don't pick it, we can move to the subproblem of where we pick the
// card at [i+1]
auto score1 = dp(i + 3) + x[i];
auto score2 = dp(i + 1);
auto res = max(score1, score2);
ready[i] = true;
memo[i] = res;
return res;
}
int main() {
preamble;
cin >> n;
dbg(n);
loop(n) cin >> x;
dbg(n, x);
// if there's less than 3 cards on the table we can't pick anything
if (n < 3) {
cout << 0 << "\n";
return 0;
}
ready.resize(n - 1);
memo.resize(n - 1);
cout << dp(1) << "\n";
}