#include<bits/stdc++.h>
#define int long long
using namespace std;
int dp[1000001],n;
signed main()
{
cin>>n;
int a[n+1];
for (int i=1;i<=n;i++)
{
cin>>a[i];
}
dp[0]=0;
dp[1]=a[1];
for (int i=2;i<=n;i++)
{
dp[i]=max(dp[i-1],max(dp[i-2]+a[i],dp[i-3]+a[i]+a[i-1]));
}
cout<<dp[n];
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBpbnQgbG9uZyBsb25nCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBkcFsxMDAwMDAxXSxuOwpzaWduZWQgbWFpbigpCnsKICAgIGNpbj4+bjsKICAgIGludCBhW24rMV07CiAgICBmb3IgKGludCBpPTE7aTw9bjtpKyspCiAgICB7CiAgICAgICAgY2luPj5hW2ldOwogICAgfQogICAgZHBbMF09MDsKICAgIGRwWzFdPWFbMV07CiAgICBmb3IgKGludCBpPTI7aTw9bjtpKyspCiAgICB7CiAgICAgICAgZHBbaV09bWF4KGRwW2ktMV0sbWF4KGRwW2ktMl0rYVtpXSxkcFtpLTNdK2FbaV0rYVtpLTFdKSk7CiAgICB9CiAgICBjb3V0PDxkcFtuXTsKfQo=