#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long int ll;
typedef pair<int, int> P;

const ll INF = -1e18;
int n;
vector<ll> a(202020);
vector<vector<ll>> dp(3, vector<ll>(202020, INF));

int main()
{
    cin >> n;
    rep(i, n) cin >> a[i];
    if(n % 2 == 0)
    {

        cout << endl;
        //return 0;
    }

    rep(i, 3) dp[i][i] = a[i];
    for(int i = 0; i < n; i++)
    {
        dp[0][i + 2] = max(dp[0][i + 2], dp[0][i] + a[i + 2]);
        dp[1][i + 3] = max(dp[1][i + 3], dp[0][i] + a[i + 3]);
        dp[2][i + 4] = max(dp[2][i + 4], dp[0][i] + a[i + 4]);

        dp[1][i + 2] = max(dp[1][i + 2], dp[1][i] + a[i + 2]);
        dp[2][i + 3] = max(dp[2][i + 3], dp[1][i] + a[i + 3]);

        dp[2][i + 2] = max(dp[2][i + 2], dp[2][i] + a[i + 2]);
    }

    rep(i, 3) { rep(j, n) cout << dp[i][j] << " "; cout << endl;}
    
    ll res = 0;
    rep(i, 3)
    {
        res = max(res, dp[i][n - 1]);
    }
    cout << res << endl;

    
    return 0;
}