#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <set>
using namespace std;

const int maxn=1e5+22;
int data[maxn];
long long zuohui[maxn];
long long zuobuhui[maxn];
long long youhui[maxn];
long long youbuhui[maxn];
int n;
long long ans;

void display()
{
    cout<<"zuohui ";
    for(int i=1;i<=n;++i)
        cout<<zuohui[i]<<' ';
    cout<<endl;

    cout<<"zuobuhui ";
    for(int i=1;i<=n;++i)
        cout<<zuobuhui[i]<<' ';
    cout<<endl;

    cout<<"youhui ";
    for(int i=1;i<=n;++i)
        cout<<youhui[i]<<' ';
    cout<<endl;

    cout<<"youbuhui ";
    for(int i=1;i<=n;++i)
        cout<<youbuhui[i]<<' ';
    cout<<endl;
}

int main()
{
    scanf("%d", &n);
    for(int i=1;i<n;++i)
        scanf("%d", &data[i]);
    zuohui[1]=0;
    for(int i=2;i<=n;++i)
    {
        if(data[i-1]<2)
            zuohui[i]=0;
        else
        {
            int tmp;
            if(data[i-1]&1)
                tmp=data[i-1]-1;
            else
                tmp=data[i-1];
            zuohui[i]=zuohui[i-1]+tmp;

        }
    }
    zuobuhui[1]=0;
    for(int i=2;i<=n;++i)
    {
        if(data[i-1]==0)
            zuobuhui[i]=0;
        else
        {
            int tmp;
            if(data[i-1]&1)
                tmp=data[i-1];
            else
                tmp=data[i-1]-1;

            zuobuhui[i]=max(zuohui[i-1], zuobuhui[i-1])+tmp;
        }
    }

    youhui[n]=0;
    for(int i=n-1;i>=1;--i)
    {
        if(data[i]<2)
            youhui[i]=0;
        else
        {
            int tmp;
            if(data[i]&1)
                tmp=data[i]-1;
            else
                tmp=data[i];
            youhui[i]=youhui[i+1]+tmp;

        }
    }
    youbuhui[n]=0;
    for(int i=n-1;i>=1;--i)
    {
        if(data[i]==0)
            youbuhui[i]=0;
        else
        {
            int tmp;
            if(data[i]&1)
                tmp=data[i];
            else
                tmp=data[i]-1;

            youbuhui[i]=max(youhui[i+1], youbuhui[i+1])+tmp;
        }
    }

    ans=0;
    for(int i=1;i<=n;++i)
    {
        ans=max(ans, zuohui[i]+youhui[i]);
        ans=max(ans, zuohui[i]+youbuhui[i]);
        ans=max(ans, zuobuhui[i]+youhui[i]);
    }

    printf("%I64d\n", ans);

//    system("pause");
    return 0;
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<vector>
#define eps 1e-10
#define LL long long
#define LD long double
#define pi acos(-1.0)
#define inf 1LL<<60
using namespace std;
int a[100000],n;
LL dpl[100000][2],dpr[100000][2];
int main(){
    while(scanf("%d",&n)!=EOF){
        for(int i=1;i<n;i++)
            scanf("%d",&a[i]);
        dpl[0][0]=dpl[0][1]=0;
        for(int i=1;i<n;i++){
            dpl[i][1]=a[i]<=1?0:dpl[i-1][1]+a[i]/2*2;
            if(a[i]&1)
                dpl[i][0]=dpl[i-1][0]+a[i];
            else
                dpl[i][0]=max(dpl[i-1][0]+a[i]-1,dpl[i][1]);
        }
        dpr[n-1][0]=dpr[n-1][1]=0;
        for(int i=n-2;i>=0;i--){
            dpr[i][1]=a[i+1]<=1?0:dpr[i+1][1]+a[i+1]/2*2;
            if(a[i]&1)
                dpr[i][0]=dpr[i-1][0]+a[i+1];
            else
                dpr[i][0]=max(dpr[i][1],dpr[i+1][0]+a[i+1]-1);
        }
        LL ans=0;
        for(int i=0;i<n;i++)
            ans=max(ans,max(dpl[i][0],max(dpr[i][0],max(dpl[i][1]+dpr[i][0],dpr[i][1]+dpl[i][0]))));
        printf("%I64d\n",ans);
    }
    return 0;
}


#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#define pb push_back
#define SIZE 100010
using namespace std;
int n,a[SIZE];
long long dp[SIZE][2][4];
void fresh(long long &x,long long v){
    if(x<v)x=v;
}
int main(){
    int i,j,k;
    long long an=0;
    scanf("%d",&n);
    for(i=1;i<n;i++)cin>>a[i];
    memset(dp,-1,sizeof(dp));
    dp[0][0][0]=0;
    for(i=1;i<n;i++){
        fresh(dp[i][0][0],0);
        for(j=0;j<2;j++)
            for(k=0;k<3;k++){
                int flag1=(j^a[i])&1;
                if(dp[i-1][j][k]!=-1){
                    fresh(dp[i][a[i]&1][k+flag1],dp[i-1][j][k]+a[i]);
                }
                if(a[i]!=1){
                    int flag2=(j^(a[i]-1))&1;
                    if(dp[i-1][j][k]!=-1){
                        fresh(dp[i][(a[i]&1)^1][k+flag2],dp[i-1][j][k]+a[i]-1);
                    }
                }
            }
        for(j=0;j<2;j++)
            for(k=0;k<3;k++)fresh(an,dp[i][j][k]);
    }
    cout<<an<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;

#define N 100005
long long  nt[N],q[N],s[N],t,res;
int n;

int main(){

    cin>>n;
    s[0]=0;
    for(int i=1;i<n;i++)
    {
        cin>>q[i];
        s[i]=s[i-1]+q[i];
        if(q[i]%2==0) s[i]--;
    }

    t=0;
    nt[n-1]=s[n-1];

    for(int i=n-2;i>=0;i--){

        if(q[i+1]>1)
        {
            t=t+q[i+1];
            if(q[i+1]&1) t--;
        }
        else t=0;

        nt[i]=max(nt[i+1],s[i]+t);
    }

    res=nt[0];
    t=0;

    for(int i=1;i<n;i++){

        if(q[i]>1){

            t+=q[i];
            if(q[i]&1) t--;
        }
        else t=0;

        res=max(res,t+nt[i]-s[i]);
    }
    cout<<res<<endl;

}


#include <bits/stdc++.h>

#define fi(a,b,c) for(int a=b; a<=c; a++)
#define fd(a,b,c) for(int a=b; a>=c; a--)
#define fii(a,b,c) for(int a=b; a<c; a++)
#define pb push_back
#define mp make_pair
#define ft first
#define sc second
#define reset(a,b) memset(a,b, sizeof a)

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef unsigned int ui;

const int N = 100009;
const int oo = 1000;

ll sumOdd[N], Left[N], Right[N], sumEven[N], a[N], IT[N * 4];
int n;
int canGet[N];

void build(int i, int l, int r) {
    if (l > r) return ;
    if (l == r){
        IT[i] = -sumOdd[l] + Left[l];
        return ;
    }
    int mid = (l + r ) >> 1;
    build(i << 1, l, mid); build((i << 1) + 1, mid + 1, r);
    IT[i] = max(IT[i << 1], IT[(i<< 1) + 1]);
}

ll get(int i, int l, int r, int u, int v) {

    if (l > r || l > v || r < u) return 0;
    if (l >= u && r <= v) return IT[i];
    int mid = (l + r) >> 1;
    return max(get(i << 1, l, mid, u, v), get((i << 1) + 1, mid + 1, r, u, v));
}

int main() {
    //freopen("test.in", "r", stdin);

    scanf("%d", &n);
    n--;

    fi(i, 1, n) scanf("%d", &a[i]);
    canGet[0] = 1;
    fi(i, 1, n) {
        int x = a[i];
        if (a[i] % 2 == 0) x--;
        sumOdd[i] =sumOdd[i-1] + x;
        if (x == 0)
            canGet[i] = i + 1;
        else canGet[i] = canGet[i-1];
    }
    fi(i, 1, n) sumEven[i] = sumEven[i-1] + ((a[i] & 1) ? a[i] - 1 : a[i]);
    Left[0] = 1;
    fi(i, 1, n) {
        int x = a[i];
        if (a[i] & 1) x --;
        if (x == 0) Left[i] = i + 1; else Left[i] = Left[i-1];
    }
    Right[n+1] = n;
    fd(i, n, 1) {
        int x = a[i];
        if (x & 1) x--;
        if (x == 0) Right[i] = i - 1; else Right[i] = Right[i + 1];
    }
    Left[0] = Right[0] = 0;
    Left[n+1] = Right[n+1] = 0;
    fi(i, 1, n) {
        if (Left[i] > i) Left[i] = 0;
        else Left[i] = sumEven[i] - sumEven[Left[i] - 1] ;
        if (Right[i] < i) Right[i] = 0;
        else Right[i] = sumEven[Right[i]] - sumEven[i - 1];
    }

    build(1, 1, n);
    ll ans = 0;
 //   fi(i, 1, n) cout <<Left[i ]<< ' '<< Right[i] <<endl;
    fi(i, 1, n) {
        ans = max(ans, Left[i-1] + Right[i]);
        ans = max(Right[i + 1] + sumOdd[i] + max(0ll, get(1, 1, n, 1, i-1)) , ans);
    }

    printf("%I64d", ans);

}


#include <bits/stdc++.h>

#define fi(a,b,c) for(int a=b; a<=c; a++)
#define fd(a,b,c) for(int a=b; a>=c; a--)
#define fii(a,b,c) for(int a=b; a<c; a++)
#define pb push_back
#define mp make_pair
#define ft first
#define sc second
#define reset(a,b) memset(a,b, sizeof a)

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef unsigned int ui;

const int N = 100009;
const int oo = 1000;

int sumOdd[N], Left[N], Right[N], sumEven[N], a[N], IT[N * 4];
int n;
int canGet[N];

void build(int i, int l, int r) {
    if (l > r) return ;
    if (l == r){
        IT[i] = -sumOdd[l] + Left[l];
        return ;
    }
    int mid = (l + r ) >> 1;
    build(i << 1, l, mid); build((i << 1) + 1, mid + 1, r);
    IT[i] = max(IT[i << 1], IT[(i<< 1) + 1]);
}

int get(int i, int l, int r, int u, int v) {

    if (l > r || l > v || r < u) return 0;
    if (l >= u && r <= v) return IT[i];
    int mid = (l + r) >> 1;
    return max(get(i << 1, l, mid, u, v), get((i << 1) + 1, mid + 1, r, u, v));
}

int main() {
 //   freopen("test.in", "r", stdin);

    scanf("%d", &n);
    n--;

    fi(i, 1, n) scanf("%d", &a[i]);
    canGet[0] = 1;
    fi(i, 1, n) {
        int x = a[i];
        if (a[i] % 2 == 0) x--;
        sumOdd[i] =sumOdd[i-1] + x;
        if (x == 0)
            canGet[i] = i + 1;
        else canGet[i] = canGet[i-1];
    }
    fi(i, 1, n) sumEven[i] = sumEven[i-1] + (a[i] & 1) ? a[i] - 1 : a[i];
    Left[0] = 1;
    fi(i, 1, n) {
        int x = a[i];
        if (a[i] & 1) x --;
        if (x == 0) Left[i] = i + 1; else Left[i] = Left[i-1];
    }
    Right[n+1] = n;
    fd(i, n, 1) {
        int x = a[i];
        if (x & 1) x--;
        if (x == 0) Right[i] = i - 1; else Right[i] = Right[i + 1];
    }
    Left[0] = Right[0] = 0;
    Left[n+1] = Right[n+1] = 0;
    fi(i, 1, n) {
        if (Left[i] > i) Left[i] = 0;
        else Left[i] = sumEven[i] - sumEven[Left[i] - 1] ;
        if (Right[i] < i) Right[i] = 0;
        else Right[i] = sumEven[Right[i]] - sumEven[i - 1];
    }

    build(1, 1, n);
    int ans = 0;
    fi(i, 1, n) {
        ans = max(ans, Left[i-1] + Right[i]);
        ans = max(Right[i + 1] + sumOdd[i] + max(0, get(1, 1, n, 1, i-1)) , ans);
    }

    printf("%d", ans);

}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <ctime>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#ifndef LEEWINGS_DEBUG
#define LEEWINGS_DEBUG 0
#endif

#define debug(x) if (LEEWINGS_DEBUG) cerr << #x << " = " << (x) << endl

#define debug_line(a, n) do {                                                \
    if (LEEWINGS_DEBUG) {                                                             \
        cerr << #a << "[" << #n << "]:" << endl;                             \
        for (int i = 0; i < (n); i++) cerr << (a)[i] << " ";                 \
        cerr << endl;                                                        \
    }                                                                        \
} while (0)

#define debug_mat(a, n, m) do {                                              \
    if (LEEWINGS_DEBUG) {                                                             \
        cerr << #a << "[" << #n << "][" << #m "]:" << endl;                  \
        for (int i = 0; i < (n); i++) {                                      \
            for (int j = 0; j < (m); j++) cerr << (a)[i][j] << " ";          \
            cerr << endl;                                                    \
        }                                                                    \
    }                                                                        \
} while(0)

typedef pair<int, int> pii;
typedef vector<int>::const_iterator vci;
typedef map<int, int>::const_iterator mci;

const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = 1.0/0.0f;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int MOD = 1000000007;

inline int LC(int x) { return x << 1; }
inline int RC(int x) { return (x << 1) | 1; }
inline bool eq0(double x) { return fabs(x) < eps; }
inline bool eq(double x, double y) { return fabs(x - y) < eps; }
inline bool ls(double x, double y) { return x + eps < y; }
inline bool gr(double x, double y) { return x - eps > y; }
inline bool greq(double x, double y) { return x + eps >= y; }
inline bool lseq(double x, double y) { return x - eps <= y; }
inline double fmax(double x, double y) { return gr(x, y) ? x : y; }
inline double fmin(double x, double y) { return ls(x, y) ? x : y; }

template<class T> inline T sqr(T x) { return x * x; }

const int MAXN = 100010;
long long a[MAXN];
long long lr[MAXN], lnr[MAXN];
long long rr[MAXN], rnr[MAXN];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) cin >> a[i];

    for (int i = 1; i <= n; i++) {
        if (a[i - 1] > 1) {
            lr[i] = lr[i - 1] + a[i - 1];
            if (a[i - 1] & 1) lr[i]--;
        }
        if (a[i - 1] > 0) {
            lnr[i] = lnr[i - 1] + a[i - 1];
            if (!(a[i - 1] & 1)) lnr[i]--;
        }
        lnr[i] = max(lnr[i], lr[i]);
    }
    for (int i = n - 1; i >= 0; i--) {
        if (a[i] > 1) {
            rr[i] = rr[i + 1] + a[i];
            if (a[i] & 1) rr[i]--;
        }
        if (a[i] > 0) {
            rnr[i] = rnr[i + 1] + a[i];
            if (!(a[i] & 1)) rnr[i]--;
        }
        rnr[i] = max(rnr[i], rr[i]);
    }

    long long ans = 0;
    for (int i = 0; i <= n; i++) {
        ans = max(ans, lr[i] + rr[i]);
        ans = max(ans, lr[i] + rnr[i]);
        ans = max(ans, rr[i] + lnr[i]);
    }
    cout << ans << endl;

    return 0;
}


#include <iostream>
using namespace std;

#define LL long long
#define MAX 100000

LL input[MAX], A[MAX], B[MAX], C[MAX];
int n;

LL even( LL i ){
  return (i - i%2);
}
LL odd( LL i ){
  if( i%2 ) return i;
  return i-1;
}

LL max2( LL a, LL b ){
  return a>b? a : b;
}

int main(){
  cin >> n;
  for( int i=0; i<n-1; i++ ){
    cin >> input[i];
  }

  A[0] = 0;
  for( int i=1; i<n; i++ ){
    if( even(input[i-1])==0 ){
      A[i] = 0;
    }else{
      A[i] = even( input[i-1] ) + A[i-1];
    }
  }

  B[0] = 0;
  for( int i=1; i<n; i++ ){
    if( odd( input[i-1] )==0 ){
      B[i] = 0;
    }else{
      B[i] = odd( input[i-1] ) + max2( A[i-1], B[i-1] );
    }
  }

  C[0] = 0;
  for( int i=1; i<n; i++ ){
    if( even( input[i-1] )==0 ){
      C[i] = 0;
    }else{
      C[i] = even( input[i-1] ) + max2( B[i-1], C[i-1] );
    }
  }

  LL max = 0;
  for( int i=0; i<n; i++ ){
    if( A[i] > max ) max = A[i];
    if( B[i] > max ) max = B[i];
    if( C[i] > max ) max = C[i];
  }
  cout << max << endl;
}


#include <iostream>
using namespace std;

#define LL long long
#define MAX 100000

LL input[MAX], A[MAX], B[MAX], C[MAX];
int n;

LL even( LL i ){
     return (i - i%2);
}
LL odd( LL i ){
     if( i%2 ) return i;
     return i-1;
}

LL max2( LL a, LL b ){
     return a>b? a : b;
}

int main(){
     cin >> n;
     for( int i=0; i<n-1; i++ ){
	  cin >> input[i];
     }

     A[0] = 0;
     for( int i=1; i<n; i++ ){
	  if( even(input[i-1])==0 ){
	       A[i] = 0;
	  }else{
	       A[i] = even( input[i-1] ) + A[i-1];
	  }
     }

     B[0] = 0;
     for( int i=1; i<n; i++ ){
	  if( odd( input[i-1] )==0 ){
	       B[i] = 0;
	  }else{
	       B[i] = odd( input[i-1] ) + max2( A[i-1], B[i-1] );
	  }
     }

     C[0] = 0;
     for( int i=1; i<n; i++ ){
	  if( even( input[i-1] )==0 ){
	       C[i] = 0;
	  }else{
	       C[i] = even( input[i-1] ) + max2( B[i-1], C[i-1] );
	  }
     }

     LL max = 0;
     for( int i=0; i<n; i++ ){
	  if( A[i] > max ) max = A[i];
	  if( B[i] > max ) max = B[i];
	  if( C[i] > max ) max = C[i];
     }
     cout << max << endl;
}


	/*JOKER*/
#include <bits/stdc++.h>
#define maxn 100005
#define maxm 1000000007
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define TASK "bridges"

using namespace std;
int n, a[maxn], l[maxn][2], r[maxn][2], dl[maxn], dr[maxn], res ;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie();
    cout.tie();
   // freopen(TASK".inp", "r", stdin);
   // freopen(TASK".out", "w", stdout);
    cin >> n;
    for(int i = 1; i < n; i++)
        cin >> a[i];
    for(int i = 2; i <= n; i++)
    {
        if(a[i - 1] > 1)
        {
            l[i][1] = l[i-1][1] + a[i-1];
            if(a[i - 1] & 1) l[i][1]--, dl[i] = dl[i-1] + 1;
        }
        l[i][0] = l[i-1][0] + a[i-1];
        if(!(a[i -1] & 1)) l[i][0]--;
    }
    for(int i = n-1; i; i--)
    {
        if(a[i] > 1)
        {
            r[i][1] = r[i+1][1] + a[i];
            if(a[i] & 1) r[i][1]--, dr[i] = dr[i+1] + 1;
        }
        r[i][0] = r[i+1][0] + a[i];
        if(!(a[i] & 1)) r[i][0]--;
    }
    for(int i = 1; i < n; i++)
    {
        int x = l[i][1] + max(r[i][0], r[i][1] + dl[i]);
        int y = r[i][1] + max(l[i][0], l[i][1] + dr[i]);
        res = max(res, max(x,y));
    }
    cout << res;
    return 0;
}


	/*JOKER*/
#include <bits/stdc++.h>
#define maxn 100005
#define maxm 1000000007
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define TASK "bridges"

using namespace std;
long long n, a[maxn], l[maxn][2], r[maxn][2], dl[maxn], dr[maxn], res ;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie();
    cout.tie();
   // freopen(TASK".inp", "r", stdin);
   // freopen(TASK".out", "w", stdout);
    cin >> n;
    for(int i = 1; i < n; i++)
        cin >> a[i];
    for(int i = 2; i <= n; i++)
    {
        if(a[i - 1] > 1)
        {
            l[i][1] = l[i-1][1] + a[i-1];
            if(a[i - 1] & 1) l[i][1]--, dl[i] = dl[i-1] + 1;
        }
        l[i][0] = max(l[i-1][0] , l[i-1][1])+ a[i-1];
        if(!(a[i -1] & 1)) l[i][0]--;
    }
    for(int i = n-1; i; i--)
    {
        if(a[i] > 1)
        {
            r[i][1] = r[i+1][1] + a[i];
            if(a[i] & 1) r[i][1]--, dr[i] = dr[i+1] + 1;
        }
        r[i][0] = max(r[i+1][0] , r[i+1][1])+ a[i];
        if(!(a[i] & 1)) r[i][0]--;
    }
    for(int i = 1; i <= n; i++)
    {
        long long x = l[i][1] + max(r[i][0], r[i][1] + dl[i]);
        long long y = r[i][1] + max(l[i][0], l[i][1] + dr[i]);
        res = max(res, max(x, y));
    }
    cout << res;
    return 0;
}


	/*JOKER*/
#include <bits/stdc++.h>
#define maxn 100005
#define maxm 1000000007
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define TASK "bridges"

using namespace std;
int n, a[maxn], l[maxn][2], r[maxn][2], dl[maxn], dr[maxn], res ;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie();
    cout.tie();
   // freopen(TASK".inp", "r", stdin);
   // freopen(TASK".out", "w", stdout);
    cin >> n;
    for(int i = 1; i < n; i++)
        cin >> a[i];
    for(int i = 2; i <= n; i++)
    {
        if(a[i - 1] > 1)
        {
            l[i][1] = l[i-1][1] + a[i-1];
            if(a[i - 1] & 1) l[i][1]--, dl[i] = dl[i-1] + 1;
        }
        l[i][0] = l[i-1][0] + a[i-1];
        if(!(a[i -1] & 1)) l[i][0]--;
    }
    for(int i = n-1; i; i--)
    {
        if(a[i] > 1)
        {
            r[i][1] = r[i+1][1] + a[i];
            if(a[i] & 1) r[i][1]--, dr[i] = dr[i+1] + 1;
        }
        r[i][0] = r[i+1][0] + a[i];
        if(!(a[i] & 1)) r[i][0]--;
    }
    for(int i = 1; i < n; i++)
    {
        int x = l[i][1] + max(r[i][0], r[i][1] + dr[i]);
        int y = r[i][1] + max(l[i][0], l[i][1] + dl[i]);
        res = max(res, max(x,y));
    }
    cout << res;
    return 0;
}


	/*JOKER*/
#include <bits/stdc++.h>
#define maxn 100005
#define maxm 1000000007
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define TASK "bridges"

using namespace std;
int n, a[maxn], l[maxn][2], r[maxn][2], dl[maxn], dr[maxn], res ;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie();
    cout.tie();
   // freopen(TASK".inp", "r", stdin);
   // freopen(TASK".out", "w", stdout);
    cin >> n;
    for(int i = 1; i < n; i++)
        cin >> a[i];
    for(int i = 2; i <= n; i++)
    {
        if(a[i - 1] > 1)
        {
            l[i][1] = l[i-1][1] + a[i-1];
            if(a[i - 1] & 1) l[i][1]--, dl[i] = dl[i-1] + 1;
        }
        l[i][0] = max(l[i-1][0] , l[i-1][1])+ a[i-1];
        if(!(a[i -1] & 1)) l[i][0]--;
    }
    for(int i = n-1; i; i--)
    {
        if(a[i] > 1)
        {
            r[i][1] = r[i+1][1] + a[i];
            if(a[i] & 1) r[i][1]--, dr[i] = dr[i+1] + 1;
        }
        r[i][0] = max(r[i+1][0] , r[i+1][1])+ a[i];
        if(!(a[i] & 1)) r[i][0]--;
    }
    for(int i = 1; i < n; i++)
    {
        int x = l[i][1] + max(r[i][0], r[i][1] + dl[i]);
        int y = r[i][1] + max(l[i][0], l[i][1] + dr[i]);
        res = max(res, max(x, y));
    }
    cout << res;
    return 0;
}


	/*JOKER*/
#include <bits/stdc++.h>
#define maxn 100005
#define maxm 1000000007
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define TASK "bridges"

using namespace std;
int n, a[maxn], l[maxn][2], r[maxn][2], dl[maxn], dr[maxn], res ;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie();
    cout.tie();
   // freopen(TASK".inp", "r", stdin);
   // freopen(TASK".out", "w", stdout);
    cin >> n;
    for(int i = 1; i < n; i++)
        cin >> a[i];
    for(int i = 2; i <= n; i++)
    {
        if(a[i - 1] > 1)
        {
            l[i][1] = l[i-1][1] + a[i-1];
            if(a[i - 1] & 1) l[i][1]--, dl[i] = dl[i-1] + 1;
        }
        l[i][0] = max(l[i-1][0] , l[i-1][1])+ a[i-1];
        if(!(a[i -1] & 1)) l[i][0]--;
    }
    for(int i = n-1; i; i--)
    {
        if(a[i] > 1)
        {
            r[i][1] = r[i+1][1] + a[i];
            if(a[i] & 1) r[i][1]--, dr[i] = dr[i+1] + 1;
        }
        r[i][0] = max(r[i+1][0] , r[i+1][1])+ a[i];
        if(!(a[i] & 1)) r[i][0]--;
    }
    for(int i = 1; i < n; i++)
    {
        int x = l[i][1] + max(r[i][0], r[i][1] + dr[i]);
        int y = r[i][1] + max(l[i][0], l[i][1] + dl[i]);
        res = max(res, max(x, y));
    }
    cout << res;
    return 0;
}


	/*JOKER*/
#include <bits/stdc++.h>
#define maxn 100005
#define maxm 1000000007
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define TASK "bridges"

using namespace std;
int n, a[maxn], l[maxn][2], r[maxn][2], dl[maxn], dr[maxn], res ;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie();
    cout.tie();
   // freopen(TASK".inp", "r", stdin);
   // freopen(TASK".out", "w", stdout);
    cin >> n;
    for(int i = 1; i < n; i++)
        cin >> a[i];
    for(int i = 2; i <= n; i++)
    {
        if(a[i - 1] > 1)
        {
            l[i][1] = l[i-1][1] + a[i-1];
            if(a[i - 1] & 1) l[i][1]--, dl[i] = dl[i-1] + 1;
        }
        l[i][0] = max(l[i-1][0] , l[i-1][1])+ a[i-1];
        if(!(a[i -1] & 1)) l[i][0]--;
    }
    for(int i = n-1; i; i--)
    {
        if(a[i] > 1)
        {
            r[i][1] = r[i+1][1] + a[i];
            if(a[i] & 1) r[i][1]--, dr[i] = dr[i+1] + 1;
        }
        r[i][0] = max(r[i+1][0] , r[i+1][1])+ a[i];
        if(!(a[i] & 1)) r[i][0]--;
    }
    for(int i = 1; i <= n; i++)
    {
        int x = l[i][1] + max(r[i][0], r[i][1] + dl[i]);
        int y = r[i][1] + max(l[i][0], l[i][1] + dr[i]);
        res = max(res, max(x, y));
    }
    cout << res;
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;

inline int getOdd(int x)
{
	return x%2==1?x:x-1;
}

inline int getEven(int x)
{
	return x%2==0?x:x-1;
}

long long Left[100001],Right[100001];
long long sumOdd[100001];
int a[100001];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
		scanf("%d",a+i);
	Left[0]=0;
	sumOdd[0]=0;
	for(int i=1;i<n;i++)
	{
		if(a[i]>1)
			Left[i]=Left[i-1]+getEven(a[i]);
		else
			Left[i]=0;
		sumOdd[i]=sumOdd[i-1]+getOdd(a[i]);
	}
	Right[n-1]=0;
	for(int i=n-2;i>=0;i--)
		if(a[i+1]>1)
			Right[i]=Right[i+1]+getEven(a[i+1]);
		else
			Right[i]=0;
	long long maxL=-(1<<30),maxR=-(1<<30);
	for(int j=0;j<n;j++)
	{
		if(Left[j]-sumOdd[j]>maxL)
			maxL=Left[j]-sumOdd[j];
		if(Right[j]+sumOdd[j]>maxR)
			maxR=Right[j]+sumOdd[j];
	}
	cout<<maxL+maxR<<endl;
	return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;

inline int getOdd(int x)
{
	return x%2==1?x:x-1;
}

inline int getEven(int x)
{
	return x%2==0?x:x-1;
}

long long Left[100001],Right[100001];
long long sumOdd[100001];
int a[100001];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
		scanf("%d",a+i);
	Left[0]=0;
	sumOdd[0]=0;
	for(int i=1;i<n;i++)
	{
		if(a[i]>1)
			Left[i]=Left[i-1]+getEven(a[i]);
		else
			Left[i]=0;
		sumOdd[i]=sumOdd[i-1]+getOdd(a[i]);
	}
	Right[n-1]=0;
	for(int i=n-2;i>=0;i--)
		if(a[i+1]>1)
			Right[i]=Right[i+1]+getEven(a[i+1]);
		else
			Right[i]=0;
	long long maxL=-(1<<30),maxR=-(1<<30);
	for(int j=0;j<n;j++)
	{
		if(Right[j]+sumOdd[j]>maxR)
		{	maxR=Right[j]+sumOdd[j];
			for(int i=0;i<=j;i++)
				if(Left[i]-sumOdd[i]>maxL)
					maxL=Left[i]-sumOdd[i];
		}
	}
	cout<<maxL+maxR<<endl;
	return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;

inline int getOdd(int x)
{
	return x%2==1?x:x-1;
}

inline int getEven(int x)
{
	return x%2==0?x:x-1;
}

long long Left[100001],Right[100001];
long long sumOdd[100001];
int a[100001];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
		scanf("%d",a+i);
	Left[0]=0;
	sumOdd[0]=0;
	for(int i=1;i<n;i++)
	{
		if(a[i]>1)
			Left[i]=Left[i-1]+getEven(a[i]);
		else
			Left[i]=0;
		sumOdd[i]=sumOdd[i-1]+getOdd(a[i]);
	}
	Right[n-1]=0;
	for(int i=n-2;i>=0;i--)
		if(a[i+1]>1)
			Right[i]=Right[i+1]+getEven(a[i+1]);
		else
			Right[i]=0;
	long long maxL=Left[0]-sumOdd[0],maxR=-(1<<30);
	long long ans=0;
	for(int j=0;j<n;j++)
	{
		if(Left[j]-sumOdd[j]>maxL)
			maxL=Left[j]-sumOdd[j];
		if(Right[j]+sumOdd[j]+maxL>ans)
			ans=Right[j]+sumOdd[j]+maxL;
	}
	cout<<ans<<endl;
	return 0;
}


#include <cmath>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<map>
#include<cctype>
using namespace std;
#define pb push_back
#define all(s) s.begin(),s.end()
#define f(i,a,b) for(int i=a;i<=b;i++)
#define F(i,a,b) for(int i=a;i>=b;i--)
#define PI 3.1415926535897932384626433832795
#define INF 1000000005
#define BIG_INF 7000000000000000000LL
#define mp make_pair
#define eps 1e-5
#define ll long long
int maxeven(int n)
{
    return n%2==0?n:n-1;
}
int maxodd(int n)
{
    return n%2!=0?n:n-1;
}
int main()
{
    int n;
    cin>>n;
    int a[n];
    f(i,0,n-2)
    {
        cin>>a[i];
    }
    ll left[n],right[n],so[n];
    left[0]=0;
    right[n-1]=0;
    so[0]=0;
    f(i,1,n-1)
    {
        if(a[i-1]==1)
        {
            left[i]=0;
        }
        else
        {
            left[i]= left[i-1]+maxeven(a[i-1]);
        }
        so[i]= so[i-1]+maxodd(a[i-1]);
    }
    F(i,n-2,0)
    {
        if(a[i]==1)
        {
            right[i]=0;
        }
        else
        {
            right[i]= right[i+1]+maxeven(a[i]);
        }
    }

    ll res=-INF;
    ll ans[n];
    ll maxx=-INF;
    f(j,0,n-1)
    {
        ll t= left[j]-so[j];
        if(t>maxx)
        {
            maxx= t;
        }
        ans[j]= right[j]+so[j]+maxx;
        res= max(res,ans[j]);
    }
    //cout<<left[0]<<" "<<right[2]<<"\n";
    cout<<res<<"\n";
    return 0;
}


#include <cmath>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<map>
#include<cctype>
using namespace std;
#define pb push_back
#define all(s) s.begin(),s.end()
#define f(i,a,b) for(int i=a;i<=b;i++)
#define F(i,a,b) for(int i=a;i>=b;i--)
#define PI 3.1415926535897932384626433832795
#define INF 1000000005
#define BIG_INF 7000000000000000000LL
#define mp make_pair
#define eps 1e-5
#define ll long long
int maxeven(int n)
{
    return n%2==0?n:n-1;
}
int maxodd(int n)
{
    return n%2!=0?n:n-1;
}
int main()
{
    int n;
    cin>>n;
    int a[n];
    f(i,0,n-2)
    {
        cin>>a[i];
    }
    ll left[n],right[n],mid[n][n];
    left[0]=0;
    right[n-1]=0;
    f(i,1,n-1)
    {
        if(a[i-1]==1)
        {
            left[i]=0;
        }
        else
        {
            left[i]= left[i-1]+maxeven(a[i-1]);
        }
    }
    F(i,n-2,0)
    {
        if(a[i]==1)
        {
            right[i]=0;
        }
        else
        {
            right[i]= right[i+1]+maxeven(a[i]);
        }
    }
    f(i,0,n-1)
    {
        f(j,i+1,n-1)
        {
            ll sum=0;
            f(k,i,j-1)
            {
                sum+=maxodd(a[k]);
            }
            mid[i][j]=sum;
        }
    }
    ll res=-INF;
    f(i,0,n-1)
    {
        f(j,i+1,n-1)
        {
            ll ans= left[i]+right[j]+mid[i][j];
            res= max(res,ans);
        }
    }
    //cout<<left[0]<<" "<<right[2]<<"\n";
    cout<<res<<"\n";
    return 0;
}


#include <cmath>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<map>
#include<cctype>
using namespace std;
#define pb push_back
#define all(s) s.begin(),s.end()
#define f(i,a,b) for(int i=a;i<=b;i++)
#define F(i,a,b) for(int i=a;i>=b;i--)
#define PI 3.1415926535897932384626433832795
#define INF 1000000005
#define BIG_INF 7000000000000000000LL
#define mp make_pair
#define eps 1e-5
#define ll long long
int maxeven(int n)
{
    return n%2==0?n:n-1;
}
int maxodd(int n)
{
    return n%2!=0?n:n-1;
}
int main()
{
    int n;
    cin>>n;
    int a[n];
    f(i,0,n-2)
    {
        cin>>a[i];
    }
    ll left[n],right[n],so[n];
    left[0]=0;
    right[n-1]=0;
    so[0]=0;
    f(i,1,n-1)
    {
        if(a[i-1]==1)
        {
            left[i]=0;
        }
        else
        {
            left[i]= left[i-1]+maxeven(a[i-1]);
        }
        so[i]= so[i-1]+maxodd(a[i-1]);
    }
    F(i,n-2,0)
    {
        if(a[i]==1)
        {
            right[i]=0;
        }
        else
        {
            right[i]= right[i+1]+maxeven(a[i]);
        }
    }

    ll res=-INF;
    f(i,0,n-1)
    {
        f(j,i,n-1)
        {
            ll ans= left[i]+right[j]+so[j]-so[i];
            res= max(res,ans);
        }
    }
    //cout<<left[0]<<" "<<right[2]<<"\n";
    cout<<res<<"\n";
    return 0;
}


#include <cmath>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<map>
#include<cctype>
using namespace std;
#define pb push_back
#define all(s) s.begin(),s.end()
#define f(i,a,b) for(int i=a;i<=b;i++)
#define F(i,a,b) for(int i=a;i>=b;i--)
#define PI 3.1415926535897932384626433832795
#define INF 1000000005
#define BIG_INF 7000000000000000000LL
#define mp make_pair
#define eps 1e-5
#define ll long long
int maxeven(int n)
{
    return n%2==0?n:n-1;
}
int maxodd(int n)
{
    return n%2!=0?n:n-1;
}
int main()
{
    int n;
    cin>>n;
    int a[n];
    f(i,0,n-2)
    {
        cin>>a[i];
    }
    ll left[n],right[n],mid[n][n];
    left[0]=0;
    right[n-1]=0;
    f(i,1,n-1)
    {
        if(a[i-1]==1)
        {
            left[i]=0;
        }
        else
        {
            left[i]= left[i-1]+maxeven(a[i-1]);
        }
    }
    F(i,n-2,0)
    {
        if(a[i]==1)
        {
            right[i]=0;
        }
        else
        {
            right[i]= right[i+1]+maxeven(a[i]);
        }
    }
    f(i,0,n-1)
    {
        f(j,i,n-1)
        {
            if(i==j)
            {
                mid[i][j]=0;
                continue;
            }
            ll sum=0;
            f(k,i,j-1)
            {
                sum+=maxodd(a[k]);
            }
            mid[i][j]=sum;
        }
    }
    ll res=-INF;
    f(i,0,n-1)
    {
        f(j,i,n-1)
        {
            ll ans= left[i]+right[j]+mid[i][j];
            res= max(res,ans);
        }
    }
    //cout<<left[0]<<" "<<right[2]<<"\n";
    cout<<res<<"\n";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <cctype>
#include <cstring>
#include <string>
#include <numeric>
#include <functional>
#include <iomanip>
#include <ctime>

using namespace std;

typedef long long LL;
typedef unsigned long long uLL;

const int N = 100005 ;

LL lef[N],righ[N];
LL sumOdd[N];
LL a[N];
int n;
void init()
{
    sumOdd[1] = 0 ;
    for(int i=1;i<n;i++)
    {
        sumOdd[i+1] = sumOdd[i] + a[i] - (a[i]%2==0?1:0) ;
        //printf("%d = %4I64d\n",i+1,sumOdd[i+1]);
    }
    //puts("");
    lef[1] = 0 ;
    for(int i=1;i<n;i++)
    {
        lef[i+1] = lef[i] + a[i] - (a[i]%2==1?1:0) ;
        if(a[i]<2)lef[i+1] = 0 ;
        //printf("%d = %4I64d\n",i+1,lef[i+1]);
    }
    //puts("");
    righ[n] = 0 ;
    for(int i=n-1;i>=1;i--)
    {
        righ[i] = righ[i+1] + a[i] - (a[i]%2==1?1:0) ;
        if(a[i]<2)righ[i] = 0 ;
        //printf("%d = %4I64d\n",i,righ[i]);
    }
    //puts("");

}

LL best[N];
int main()
{

	while(cin>>n)
	{
	    for(int i=1;i<n;i++)cin>>a[i];
	    memset(righ,0,sizeof(righ));
	    memset(lef,0,sizeof(lef));
	    memset(sumOdd,0,sizeof(sumOdd));
	    init();
	    LL mxi=-1;
	    LL mxj=-1;
	    LL res = 0 ;
	    best[0] = 0 ;

        int idi = -1 ,idj = -1 ;

	    for(int i=1;i<=n;i++)
	    {
	        if( mxi < lef[i] - sumOdd[i] )
	        {
	            mxi = lef[i] - sumOdd[i] ;
	            idi = i ;
	        }
	        best[i] = mxi ;
	        if( res < best[i] + righ[i] + sumOdd[i] )
	        {
	            res = best[i] + righ[i] + sumOdd[i] ;
	            idj = i ;
	        }
	    }
	    //printf("%d -> %d\n",idi,idj);
	    cout<<res<<endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <cctype>
#include <cstring>
#include <string>
#include <numeric>
#include <functional>
#include <iomanip>
#include <ctime>

using namespace std;

typedef long long LL;
typedef unsigned long long uLL;

const int N = 100005 ;

LL lef[N],righ[N];
LL sumOdd[N];
LL a[N];
int n;
void init()
{
    sumOdd[1] = 0 ;
    for(int i=1;i<n;i++)
    {
        sumOdd[i+1] = sumOdd[i] + a[i] - (a[i]%2==0?1:0) ;
        //printf("%4I64d",sumOdd[i+1]);
    }
    lef[1] = 0 ;
    for(int i=1;i<n;i++)
    {
        lef[i+1] = lef[i] + a[i] - (a[i]%2==1?1:0) ;
        //printf("%4I64d",lef[i+1]);
    }
    righ[n] = 0 ;
    for(int i=n-1;i>=1;i--)
    {
        righ[i] = righ[i+1] + a[i] - (a[i]%2==1?1:0) ;
        //printf("%4I64d",righ[i]);
    }

}
int main()
{

	while(cin>>n)
	{
	    for(int i=1;i<n;i++)cin>>a[i];
	    init();
	    LL mxi=-1;
	    LL mxj=-1;
	    for(int i=1;i<=n;i++)
	    {
	        mxi = max( mxi , lef[i] - sumOdd[i] ) ;
	        mxj = max( mxj , righ[i] + sumOdd[i] ) ;
	    }
	    cout<<mxi+mxj<<endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <cctype>
#include <cstring>
#include <string>
#include <numeric>
#include <functional>
#include <iomanip>
#include <ctime>

using namespace std;

typedef long long LL;
typedef unsigned long long uLL;

const int N = 100005 ;

LL lef[N],righ[N];
LL sumOdd[N];
LL a[N];
int n;
void init()
{
    sumOdd[1] = 0 ;
    for(int i=1;i<n;i++)
    {
        sumOdd[i+1] = sumOdd[i] + a[i] - (a[i]%2==0?1:0) ;
        //printf("%d = %4I64d\n",i+1,sumOdd[i+1]);
    }
    //puts("");
    lef[1] = 0 ;
    for(int i=1;i<n;i++)
    {
        lef[i+1] = lef[i] + a[i] - (a[i]%2==1?1:0) ;
        //printf("%d = %4I64d\n",i+1,lef[i+1]);
    }
    //puts("");
    righ[n] = 0 ;
    for(int i=n-1;i>=1;i--)
    {
        righ[i] = righ[i+1] + a[i] - (a[i]%2==1?1:0) ;
        //printf("%d = %4I64d\n",i,righ[i]);
    }
    //puts("");

}

LL best[N];
int main()
{

	while(cin>>n)
	{
	    for(int i=1;i<n;i++)cin>>a[i];
	    init();
	    LL mxi=-1;
	    LL mxj=-1;
	    LL res = 0 ;
	    memset(best,0,sizeof(best));
	    for(int i=1;i<=n;i++)
	    {
	        mxi = max( mxi , lef[i] - sumOdd[i] ) ;
	        best[i] = mxi ;
	        res = max( res , best[i-1] + righ[i] + sumOdd[i] ) ;
	    }
	    cout<<res<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int a[N];
typedef long long cc;
cc lef[N], rig[N], sum[N];
cc mx[N];
int n;
void init() {
    for (int i = 1; ++i <= n;) {
        int strong = a[i - 1];
        if (strong % 2) strong--;
        lef[i] = lef[i - 1] + strong;
    }
    for (int i = 1; ++i <= n;) {
        int strong = a[i - 1];
        if (!(strong % 2)) strong--;
        sum[i] = sum[i - 1] + strong;
    }
    for (int i = n; --i; ) {
        int strong  = a[i];
        if (strong % 2) strong--;
        rig[i] = rig[i + 1] + strong;
    }
    mx[1] = lef[1] - sum[1];
    for (int i = 1; ++i < n;)
        mx[i] = max(mx[i - 1], lef[i] - sum[i]);
}
int main() {
    ios_base :: sync_with_stdio(false); cin.tie(0);
    cin >> n;
    for (int i = 0; ++i < n;) cin >> a[i];
    init();
    cc res = 0;
    for (int i = 1; ++i <= n;) res = max(res, rig[i] + sum[i] + mx[i - 1]);
    cout << res;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int a[N];
typedef long long cc;
cc lef[N], rig[N], sum[N];
cc mx[N], res;
int n;
void init() {
    for (int i = 1; ++i <= n;) {
        int strong = a[i - 1];
        if (strong % 2) strong--;
        lef[i] = lef[i - 1] + strong;
        res = max(res, lef[i]);
    }
    for (int i = 1; ++i <= n;) {
        int strong = a[i - 1];
        if (!(strong % 2)) strong--;
        sum[i] = sum[i - 1] + strong;
    }
    for (int i = n; --i; ) {
        int strong  = a[i];
        if (strong % 2) strong--;
        rig[i] = rig[i + 1] + strong;
        res = max(res, rig[i]);
    }
    mx[1] = lef[1] - sum[1];
    for (int i = 1; ++i < n;)
        mx[i] = max(mx[i - 1], lef[i] - sum[i]);
}
int main() {
    ios_base :: sync_with_stdio(false); cin.tie(0);
    cin >> n;
    for (int i = 0; ++i < n;) cin >> a[i];
    init();
    for (int i = 0; ++i <= n;) {
        res = max(res, rig[i] + sum[i] + mx[i - 1]);
    }
    cout << res;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int a[N];
typedef long long cc;
cc lef[N], rig[N], sum[N];
cc mx[N], res;
int n;
void init() {
    for (int i = 1; ++i <= n;) {
        int strong = a[i - 1];
        if (strong % 2) strong--;
        lef[i] = lef[i - 1] + strong;
        lef[i] *= (a[i - 1] != 1);
        res = max(res, lef[i]);
    }
    for (int i = 1; ++i <= n;) {
        int strong = a[i - 1];
        if (!(strong % 2)) strong--;
        sum[i] = sum[i - 1] + strong;
    }
    for (int i = n; --i; ) {
        int strong  = a[i];
        if (strong % 2) strong--;
        rig[i] = rig[i + 1] + strong;
        rig[i] *= (a[i] != 1);
        res = max(res, rig[i]);
    }
    mx[1] = lef[1] - sum[1];
    for (int i = 1; ++i < n;)
        mx[i] = max(mx[i - 1], lef[i] - sum[i]);
}
int main() {
    ios_base :: sync_with_stdio(false); cin.tie(0);
    cin >> n;
    for (int i = 0; ++i < n;) cin >> a[i];
    init();
    for (int i = 0; ++i <= n;)
        res = max(res, rig[i] + sum[i] + mx[i - 1]);
    cout << res;
    return 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

typedef long long ll;
int a[100010];
ll dp[100010][5];

int c0[] = {0, 4, 4, 4, 4};
int c1[] = {2, 2, 2, -1, -1};
int c2[] = {1, 1, 3, 3, -1};

int main(void){
    int N, i, j;
    cin >> N;
    N--;
    REP(i, N) cin >> a[i];

    REP(i, N) REP(j, 5) dp[i][j] = -1;
    dp[0][0] = 0;

    REP(i, N + 1) REP(j, 5) if(dp[i][j] != -1) {
        dp[i+1][c0[j]] = max(dp[i+1][c0[j]], dp[i][j]);
        ll x = a[i];
        if(x % 2 != 1) {
            x--;
            if(x > 0 && c1[j] != -1) dp[i+1][c1[j]] = max(dp[i+1][c1[j]], dp[i][j] + x);
        }
        else {
            x--;
            if(x > 0 && c2[j] != -1) dp[i+1][c2[j]] = max(dp[i+1][c2[j]], dp[i][j] + x);
        }
    }

    ll ans = 0;
    REP(i, N+1) REP(j, 5) ans = max(ans, dp[i][j]);
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

typedef long long ll;
int a[100010];
ll dp[100010][5];

int c0[] = {0, 4, 4, 4, 4};
int c1[] = {2, 2, 2, -1, -1};
int c2[] = {1, 1, 3, 3, -1};

int main(void){
    int N, i, j;
    cin >> N;
    N--;
    REP(i, N) cin >> a[i];

    REP(i, N) REP(j, 5) dp[i][j] = -1;
    dp[0][0] = 0;

    REP(i, N + 1) REP(j, 5) if(dp[i][j] != -1) {
        dp[i+1][c0[j]] = max(dp[i+1][c0[j]], dp[i][j]);

        {
            ll x = a[i];
            if(x%2 != 1) x--;
            if(x > 0 && c1[j] != -1) dp[i+1][c1[j]] = max(dp[i+1][c1[j]], dp[i][j] + x);
        }

        // even
        {
            ll x = a[i];
            if(x%2 != 0) x--;
            if(x > 0 && c2[j] != -1) dp[i+1][c2[j]] = max(dp[i+1][c2[j]], dp[i][j] + x);
        }
    }

    ll ans = 0;
    REP(i, N+1) REP(j, 5) ans = max(ans, dp[i][j]);
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <list>
#include <algorithm>
#include <stack>
#include <functional>
#include <fstream>
#include <deque>
#include <queue>

using namespace std;

int a[123456];
int Left[123456];
int Right[123456];
int odd[123456];
int Dg(int k)
{
    if(k % 2)
        return k-1;
    else
        return k;
}
int Odd(int k)
{
    if(k % 2)
        return k;
    else
        return k - 1;
}

int main()
{

    int n;
    cin >> n;
    for(int i = 0; i < n-1; ++i)
        cin >> a[i];

    for(int i = 0; i < n; ++i)
    {
        if(i == 0)
        {
            Left[i] = 0;
            continue;
        }
        if(a[i-1] == 1)
            Left[i] = 0;
        else
            Left[i] = Left[i-1] + Dg(a[i-1]);

    }
    for(int i = n-1; i >= 0; --i)
    {
        if(i == n-1)
        {
            Right[i] = 0;
            continue;
        }
        if(a[i] == 1)
            Right[i] = 0;
        else
            Right[i] = Right[i+1] + Dg(a[i+1]);
    }
    int sum = 0;
    for(int i = 0; i < n; ++i)
    {
        if(i == 0)
            odd[i] = 0;
        else
            odd[i] = sum;
        sum += Odd(a[i]);
    }
    int currI;
    int currJ;
    int MaxL = Left[0] - odd[0];
    int MaxR = -123456;
    for(int j = 0; j < n; ++j)
    {
        if(MaxR < Right[j] + odd[j])
        {
            MaxR = Right[j] + odd[j];
            currJ = j;
        }
        if(MaxL < Left[j] - odd[j] && currJ >= j)
        {
            MaxL = Left[j] - odd[j];
        }

    }
    cout << MaxL + MaxR;

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <list>
#include <algorithm>
#include <stack>
#include <functional>
#include <fstream>
#include <deque>
#include <queue>

using namespace std;

long long a[123456];
long long Left[123456];
long long Right[123456];
long long odd[123456];
long long Dg(long long k)
{
    if(k % 2)
        return k-1;
    else
        return k;
}
long long Odd(long long k)
{
    if(k % 2)
        return k;
    else
        return k - 1;
}
long long result[123456];

int main()
{

    int n;
    cin >> n;
    for(int i = 0; i < n-1; ++i)
        cin >> a[i];

    for(int i = 0; i < n; ++i)
    {
        if(i == 0)
        {
            Left[i] = 0;
            continue;
        }
        if(a[i-1] == 1)
            Left[i] = 0;
        else
            Left[i] = Left[i-1] + Dg(a[i-1]);

    }
    for(int i = n-1; i >= 0; --i)
    {
        if(i == n-1)
        {
            Right[i] = 0;
            continue;
        }
        if(a[i] == 1)
            Right[i] = 0;
        else
            Right[i] = Right[i+1] + Dg(a[i]);
    }
    long long sum = 0;
    for(int i = 0; i < n; ++i)
    {
        if(i == 0)
            odd[i] = 0;
        else
            odd[i] = sum;
        sum += Odd(a[i]);
    }
    long long MaxL = Left[0] - odd[0];
    long long MaxR = Right[0] + odd[0];
    for(int j = 0; j < n; ++j)
    {

        if(MaxL < Left[j] - odd[j])
        {
            MaxL = Left[j] - odd[j];
        }
        result[j] = MaxL + Right[j] + odd[j];

    }
    cout << *(max_element(result, result + n));

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <list>
#include <algorithm>
#include <stack>
#include <functional>
#include <fstream>
#include <deque>
#include <queue>

using namespace std;

int a[123456];
int Left[123456];
int Right[123456];
int odd[123456];
int Dg(int k)
{
    if(k % 2)
        return k-1;
    else
        return k;
}
int Odd(int k)
{
    if(k % 2)
        return k;
    else
        return k - 1;
}
int result[123456];

int main()
{

    int n;
    cin >> n;
    for(int i = 0; i < n-1; ++i)
        cin >> a[i];

    for(int i = 0; i < n; ++i)
    {
        if(i == 0)
        {
            Left[i] = 0;
            continue;
        }
        if(a[i-1] == 1)
            Left[i] = 0;
        else
            Left[i] = Left[i-1] + Dg(a[i-1]);

    }
    for(int i = n-1; i >= 0; --i)
    {
        if(i == n-1)
        {
            Right[i] = 0;
            continue;
        }
        if(a[i] == 1)
            Right[i] = 0;
        else
            Right[i] = Right[i+1] + Dg(a[i]);
    }
    int sum = 0;
    for(int i = 0; i < n; ++i)
    {
        if(i == 0)
            odd[i] = 0;
        else
            odd[i] = sum;
        sum += Odd(a[i]);
    }
    int MaxL = Left[0] - odd[0];
    int MaxR = Right[0] + odd[0];
    for(int j = 0; j < n; ++j)
    {

        if(MaxL < Left[j] - odd[j])
        {
            MaxL = Left[j] - odd[j];
        }
        result[j] = MaxL + Right[j] + odd[j];

    }
    cout << *(max_element(result, result + n));

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <list>
#include <algorithm>
#include <stack>
#include <functional>
#include <fstream>
#include <deque>
#include <queue>

using namespace std;

long long a[123456];
long long Left[123456];
long long Right[123456];
long long odd[123456];
long long Dg(long long k)
{
    if(k % 2)
        return k-1;
    else
        return k;
}
long long Odd(long long k)
{
    if(k % 2)
        return k;
    else
        return k - 1;
}
int result[123456];

int main()
{

    int n;
    cin >> n;
    for(int i = 0; i < n-1; ++i)
        cin >> a[i];

    for(int i = 0; i < n; ++i)
    {
        if(i == 0)
        {
            Left[i] = 0;
            continue;
        }
        if(a[i-1] == 1)
            Left[i] = 0;
        else
            Left[i] = Left[i-1] + Dg(a[i-1]);

    }
    for(int i = n-1; i >= 0; --i)
    {
        if(i == n-1)
        {
            Right[i] = 0;
            continue;
        }
        if(a[i] == 1)
            Right[i] = 0;
        else
            Right[i] = Right[i+1] + Dg(a[i]);
    }
    long long sum = 0;
    for(int i = 0; i < n; ++i)
    {
        if(i == 0)
            odd[i] = 0;
        else
            odd[i] = sum;
        sum += Odd(a[i]);
    }
    long long MaxL = Left[0] - odd[0];
    long long MaxR = Right[0] + odd[0];
    for(int j = 0; j < n; ++j)
    {

        if(MaxL < Left[j] - odd[j])
        {
            MaxL = Left[j] - odd[j];
        }
        result[j] = MaxL + Right[j] + odd[j];

    }
    cout << *(max_element(result, result + n));

    return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdio>

using namespace std;

typedef long long LL;

LL a[100005];
LL L[100005];
LL R[100005];
LL odd[100005];
LL sum[100005];
int n;

void init()
{
	memset(a, 0, sizeof(a));
	memset(L, 0, sizeof(L));
	memset(R, 0, sizeof(R));
	memset(odd, 0, sizeof(odd));
	memset(sum, 0, sizeof(sum));
	scanf("%d", &n);
	for(int i=1; i<n; i++)
		scanf("%I64d", &a[i]);
}

int main()
{
	init();
	for(int i=2; i<=n; i++)
		if(a[i-1]==1) continue;
		else L[i]=L[i-1]+(a[i-1]/2)*2;
	for(int i=n-1; i>=1; i--)
		if(a[i]==1) continue;
		else R[i]=R[i+1]+(a[i]/2)*2;

//	for(int i=1; i<=n; i++)
//	{
//		printf("L[%d]=%I64d R[%d]=%I64d\n", i, L[i], i, R[i]);
//	}

	for(int i=1; i<n; i++)
		odd[i]=(a[i]%2==1?a[i]:a[i]-1);
	for(int i=1; i<n; i++)
		sum[i+1]=sum[i]+odd[i];
	LL ans=0, Lmax=0, Rmax;
	for(int i=1; i<=n; i++)
	{
		Rmax=R[i]+sum[i];
		Lmax=max(Lmax, L[i]-sum[i]);
		ans=max(ans, Lmax+Rmax);
	}
	printf("%I64d\n", ans);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<cmath>
#define maxn 1200000
using namespace std;
long n,cd[maxn+1],cc[maxn+1];
long long a[maxn+1],s[maxn+1],fd[maxn+1],fc[maxn+1];
void doc()
{
    scanf("%ld",&n);
    n--;
    for (int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        s[i]=s[i-1]+a[i];
    }
}
long long tinh(long l,long r)
{
    if (r<l)
        return 0;
    long long ans=0,temp;
    fd[l-1]=0; cd[l-1]=0;
    for (int i=l;i<=r;i++)
    {
        if (a[i]%2==0)
        {
            cd[i]=cd[i-1]+1;
            fd[i]=fd[i-1]+a[i]-1;
            temp=s[i]-s[i-cd[i]];
            fd[i]=max(fd[i],temp);
        }
        else fd[i]=fd[i-1]+a[i];
    }
    ans=max(ans,fd[r]);
    for (int i=r;i>=l;i--)
    {
        if (a[i]%2==0)
        {
            cc[i]=cc[i+1]+1;
            fc[i]=fc[i+1]+a[i]-1;
            temp=s[i+cc[i]-1]-s[i-1];
            fc[i]=max(fc[i],temp);
        }
        else fc[i]=fc[i+1]+a[i];
        ans=max(ans,fc[i]+fd[i-1]);
    }
    return ans;
}
void xl()
{
    long long ans=0;
    long j;
    for (int i=1;i<=n;i++)
    {
        j=i;
        while (j<=n and a[j]!=0)
            j++;
        ans=max(ans,tinh(i,j-1));
        i=j;
    }
    printf("%lld",ans);
}
int main()
{
    //freopen("bridges.inp","r",stdin);
    //freopen("bridges.out","w",stdout);
    doc();
    xl();
}


#include<stdio.h>
#include<algorithm>
#include<cmath>
#define maxn 1200000
using namespace std;
long n,cd[maxn+1],cc[maxn+1];
long long a[maxn+1],s[maxn+1],fd[maxn+1],fc[maxn+1],sll[maxn+1];
void doc()
{
    scanf("%ld",&n);
    n--;
    for (int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        s[i]=s[i-1]+a[i];
    }
    for (int i=1;i<=n;i++)
    {
        sll[i]=sll[i-1];
        if (a[i]%2==1)
            sll[i]++;
    }
}
long long tinh(long l,long r)
{
    if (r<l)
        return 0;
    long long ans=0,temp,ll=l,rr;
    fd[l-1]=0; cd[l-1]=0;
    for (int i=l;i<=r;i++)
    {
        if (a[i]%2==0)
        {
            cd[i]=cd[i-1]+1;
            fd[i]=fd[i-1]+a[i]-1;
            temp=s[i]-s[ll-1]-(sll[i]-sll[ll-1]);
            fd[i]=max(fd[i],temp);
        }
        else
        {
            if (a[i]==1)
                ll=i+1;
            fd[i]=fd[i-1]+a[i];
        }
    }
    ans=max(ans,fd[r]);
    rr=r;
    for (int i=r;i>=l;i--)
    {
        if (a[i]%2==0)
        {
            cc[i]=cc[i+1]+1;
            fc[i]=fc[i+1]+a[i]-1;
            temp=s[rr]-s[i-1]-(sll[rr]-sll[i-1]);
            fc[i]=max(fc[i],temp);
        }
        else
        {
            fc[i]=fc[i+1]+a[i];
            if (a[i]==1)
                rr=i-1;
        }
        ans=max(ans,fc[i]+fd[i-1]);
    }
    return ans;
}
void xl()
{
    long long ans=0;
    long j;
    for (int i=1;i<=n;i++)
    {
        j=i;
        while (j<=n and a[j]!=0)
            j++;
        ans=max(ans,tinh(i,j-1));
        i=j;
    }
    printf("%lld",ans);
}
int main()
{
    //freopen("bridges.inp","r",stdin);
    //freopen("bridges.out","w",stdout);
    doc();
    xl();
}


// {{{
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <complex>
#include <numeric>
#define REP(i, n) for (int i = 0; i < (int) (n); ++i)
#define FOR(i, a, b) for (int i = (int) (a); i <= (int) (b); ++i)
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define FORE(it, c) for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define SIZE(x) ((int) ((x).size()))
#define DEBUG(x) { cerr << #x << ": " << (x) << endl; }
#define SQR(x) ((x) * (x))
#define INF 1023456789
using namespace std;

typedef long long LL;
typedef pair<int, int> PI;
typedef pair<int, PI> TRI;
typedef vector<int> VI;
typedef vector<VI> VVI;
// }}}

void solve(const VI& A, vector<LL>& W, vector<LL>& R) {
	REP(i, SIZE(A))
		if (A[i] % 2 == 0) {
			W[i + 1] = max(A[i] + R[i], A[i] - 1 + W[i]);
			R[i + 1] = A[i] + R[i];
		} else {
			W[i + 1] = A[i] + W[i];
			R[i + 1] = (A[i] == 1) ? 0 : A[i] - 1 + R[i];
		}
}

int main() {
	int n;
	scanf("%d", &n);
	VI A(n - 1);
	REP(i, n - 1)
		scanf("%d", &A[i]);
	vector<LL> L(n), LS(n);
	solve(A, L, LS);
	reverse(A.begin(), A.end());
	vector<LL> R(n), RS(n);
	solve(A, R, RS);
	reverse(R.begin(), R.end());
	reverse(RS.begin(), RS.end());
	LL res = 0;
	REP(i, n)
		res = max(res, max(LS[i] + R[i], L[i] + RS[i]));
	cout << res << endl;
}


#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
using namespace std;

const int maxn = 100050;
long long flg[maxn],flb[maxn],frb[maxn],frg[maxn];
int p[maxn];

int maxodd(const int &x)
{
    return x - ((x ^ 1)&1);
}
int maxeven(const int &x)
{
    return x - (x & 1);
}

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 1;i < n;++i) cin >> p[i];
    for (int i = 2;i <= n;++i)
    {
        if (p[i-1]) flg[i] = max(flb[i-1],flg[i-1]) + maxodd(p[i-1]);
        if (p[i-1]>=2) flb[i] = flb[i-1] + maxeven(p[i-1]);
    }
    for (int i = n-1;i >= 1;--i)
    {
        if (p[i]) frg[i] = max(frb[i+1],frg[i+1]) + maxodd(p[i]);
        if (p[i]>=2) frb[i] = frb[i+1] + maxeven(p[i]);
    }
    long long ans = 0;
    for (int i = 1;i <= n;++i)
    {
        ans = max(ans,flb[i]+frg[i]);
        ans = max(ans,flb[i]+frb[i]);
        ans = max(ans,frb[i]+flg[i]);
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
using namespace std;

const int maxn = 100050;
long long flg[maxn],flb[maxn],frb[maxn],frg[maxn];
int p[maxn];

int maxodd(const int &x)
{
    return x - (x ^ 1);
}
int maxeven(const int &x)
{
    return x - (x & 1);
}

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 1;i < n;++i) cin >> p[i];
    for (int i = 2;i <= n;++i)
    {
        if (p[i-1]) flg[i] = max(flb[i-1],flg[i-1]) + maxodd(p[i-1]);
        if (p[i-1]>=2) flb[i] = flb[i-1] + maxeven(p[i-1]);
    }
    for (int i = n-1;i >= 1;--i)
    {
        if (p[i]) frg[i] = max(frb[i+1],frg[i+1]) + maxodd(p[i]);
        if (p[i]>=2) frb[i] = frb[i+1] + maxeven(p[i]);
    }
    long long ans = 0;
    for (int i = 1;i <= n;++i)
    {
        ans = max(ans,flb[i]+frg[i]);
        ans = max(ans,flb[i]+frb[i]);
        ans = max(ans,frb[i]+flg[i]);
        ans = max(ans,frb[i]+flb[i]);
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
using namespace std;
typedef long long ll;
const int MAXN=1000*100+10;
ll n,a[MAXN],maxi;
ll dp1_ch[MAXN],dp1_ra[MAXN],dp[MAXN],dp_ch[MAXN],dp_ra[MAXN];
int main()
{
	cin >> n;
	for(int i=0;i<n-1;i++)
		cin >> a[i];
	dp1_ch[0]=0;
	for(int i=1;i<n;i++)
	{
		if(a[i-1]==1)
			dp1_ch[i]=0;
		else
			dp1_ch[i]=dp1_ch[i-1]+a[i-1]-a[i-1]%2;
	}
	dp1_ra[n-1]=0;
	for(int i=n-2;i>=0;i--)
	{
		if(a[i]==1)
			dp1_ra[i]=0;
		else
			dp1_ra[i]=dp1_ra[i+1]+a[i]-a[i]%2;
	}
	dp_ra[n-1]=0;
	for(int i=n-2;i>=0;i--)
		dp_ra[i]=dp_ra[i+1]+a[i]-(a[i]+1)%2;
	dp_ch[0]=0;
	for(int i=1;i<n;i++)
		dp_ch[i]=dp_ch[i-1]+a[i-1]-(a[i-1]+1)%2;
	dp[0]=max(dp_ra[0],dp1_ra[0]);
	dp[n-1]=max(dp_ch[n-1],dp1_ch[n-1]);
	for(int i=1;i<n-1;i++)
	{
		dp[i]=max(dp1_ch[i]+dp1_ra[i],max(dp_ra[i]+dp1_ch[i],dp_ch[i]+dp1_ra[i]));
		dp[i]=max(dp[i],max(dp1_ra[i],dp1_ch[i]));
	}
	for(int i=0;i<n;i++)
		maxi=max(dp[i],maxi);
	cout << maxi << endl;
	return 0;
}


#include <iostream>
using namespace std;
typedef long long ll;
const int MAXN=1000*100+10;
ll n,a[MAXN],maxi;
ll dp1_ch[MAXN],dp1_ra[MAXN],dp[MAXN],dp_ch[MAXN],dp_ra[MAXN];
int main()
{
	cin >> n;
	for(int i=0;i<n-1;i++)
		cin >> a[i];
	dp1_ch[0]=0;
	for(int i=1;i<n;i++)
	{
		if(a[i-1]==1)
			dp1_ch[i]=0;
		else
			dp1_ch[i]=dp1_ch[i-1]+a[i-1]-a[i-1]%2;
	}
	dp1_ra[n-1]=0;
	for(int i=n-2;i>=0;i--)
	{
		if(a[i]==1)
			dp1_ra[i]=0;
		else
			dp1_ra[i]=dp1_ra[i+1]+a[i]-a[i]%2;
	}
	dp_ra[n-1]=0;
	for(int i=n-2;i>=0;i--)
		dp_ra[i]=dp_ra[i+1]+a[i]-(a[i]+1)%2;
	dp_ch[0]=0;
	for(int i=1;i<n;i++)
		dp_ch[i]=dp_ch[i-1]+a[i-1]-(a[i-1]+1)%2;
	dp[0]=max(dp_ra[0],dp1_ra[0]);
	dp[n-1]=max(dp_ch[n-1],dp1_ch[n-1]);
	for(int i=1;i<n-1;i++)
		dp[i]=max(dp_ra[i]+dp1_ch[i],dp_ch[i]+dp1_ra[i]);
	for(int i=0;i<n;i++)
		maxi=max(dp[i],maxi);
	cout << maxi << endl;
	return 0;
}


#include <iostream>
using namespace std;
typedef long long ll;
const int MAXN=1000*100+10;
ll n,a[MAXN],maxi;
ll dp1_ch[MAXN],dp1_ra[MAXN],dp[MAXN],dp_ch[MAXN],dp_ra[MAXN];
int main()
{
	cin >> n;
	for(int i=0;i<n-1;i++)
		cin >> a[i];
	dp1_ch[0]=0;
	for(int i=1;i<n;i++)
	{
		if(a[i-1]==1)
			dp1_ch[i]=0;
		else
			dp1_ch[i]=dp1_ch[i-1]+a[i-1]-a[i-1]%2;
	}
	dp1_ra[n-1]=0;
	for(int i=n-2;i>=0;i--)
	{
		if(a[i]==1)
			dp1_ra[i]=0;
		else
			dp1_ra[i]=dp1_ra[i+1]+a[i]-a[i]%2;
	}
	dp_ra[n-1]=0;
	for(int i=n-2;i>=0;i--)
		dp_ra[i]=max(dp1_ra[i],dp_ra[i+1]+a[i]-(a[i]+1)%2);
	dp_ch[0]=0;
	for(int i=1;i<n;i++)
		dp_ch[i]=max(dp_ch[i-1]+a[i-1]-(a[i-1]+1)%2,dp1_ch[i]);
	for(int i=0;i<n;i++)
		cerr << dp_ra[i] << " " << dp_ch[i] << endl;
	dp[0]=max(dp_ra[0],dp1_ra[0]);
	dp[n-1]=max(dp_ch[n-1],dp1_ch[n-1]);
	for(int i=1;i<n-1;i++)
	{
		dp[i]=max(dp1_ch[i]+dp1_ra[i],max(dp_ra[i]+dp1_ch[i],dp_ch[i]+dp1_ra[i]));
		dp[i]=max(dp[i],max(dp1_ra[i],dp1_ch[i]));
	}
	for(int i=0;i<n;i++)
		maxi=max(dp[i],maxi);
	cout << maxi << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define finp "BRIDGES.inp"
#define fout "BRIDGES.out"
#define foru(i,l,r) for(int i = l;i <= r; ++i)
#define repu(i,l,r) for(int i = l ;i < r; ++i)
#define maxn 1000010

typedef long long ll;
int n;
bool check,dau[maxn];
ll tong,tham,res = 0;

typedef pair<int,int> cap;
#define fi first
#define sec second
vector<cap> a[maxn];

void DFS(int u)
{
    ++tham; dau[u] = false;
    repu(i,0,a[u].size())
    {
        int v = a[u][i].fi,w = a[u][i].sec;
        if (!dau[v] || w <= 0) continue;
        DFS(v);
        if (w % 2 == 1) tong += w,dau[v] = false;
        else tong += w - 1 + (check == true),dau[v] = false;
        check = false;
    }
}

int main()
{
  //  freopen(finp,"r",stdin);
  //  freopen(fout,"w",stdout);
    scanf("%d",&n);
    foru(i,1,n - 1)
    {
        int w;
        scanf("%d",&w);
        a[i].push_back(cap(i + 1,w)); a[i + 1].push_back(cap(i,w));
    }
    memset(dau,true,sizeof(dau));
    foru(i,1,n)
        if (dau[i])
        {
            check = true;
            tong = tham = 0;
            DFS(i);
            res = max(res,tong + (a[i][0].sec % 2 == 0 && tham > 2));
        }
    printf("%I64d",res);
  //  fclose(stdin); fclose(stdout);
}


#include <bits/stdc++.h>

using namespace std;

#define finp "BRIDGES.inp"
#define fout "BRIDGES.out"
#define foru(i,l,r) for(int i = l;i  <= r; ++i)
#define ford(i,r,l) for(int i = r; i >= l; --i)
#define maxn  100010

typedef long long ll;

int n,a[maxn];
ll L[maxn], R[maxn], s[maxn], res;

int main()
{
   // freopen(finp,"r",stdin);
   // freopen(fout,"w",stdout);
    scanf("%d", &n);
    foru(i,1,n) scanf("%d", &a[i]);

    foru(i,2,n)
        if (a[i - 1] == 1) L[i] = 0;
        else L[i] = L[i - 1] + a[i - 1] - a[i - 1] % 2;

    ford(i,n - 1,1)
        if (a[i] == 1) R[i] = 0;
        else R[i] = R[i + 1] + a[i] - a[i] % 2;

    foru(i,2,n) s[i] = s[i - 1] + a[i - 1] - (1 - a[i - 1] % 2);
    ll val = 0;
    foru(i,2,n)
    {
        val = max(val, L[i] - s[i]);
        res = max(res, R[i] + s[i] + val);
    }
    printf("%I64d",res);
  //  fclose(stdin); fclose(stdout);
}


// inplace_merge(T + beg, T + mid + 1, T + end + 1);
// unsigned Long hash[maxn],p = 999999999989; hash[0] = 1; fo(i,1,maxn)hash[i] = hash[i-1] * p;
// __builtin_popcount(n);
/*
ID: Tariqul
PROG:
LANG: C++
*/

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define fo(i,j,n) for(i=j;i<n;++i)
#define Fo(i,j,n) for(i=n-1;i>=j;--i)
#define foo(i,j,v) fo(i,j,sz(v))
#define Foo(i,j,v) Fo(i,j,sz(v))
#define li(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define CLR(a,v) memset((a),(v),sizeof(a))
#define inf 1e9 + 10
#ifdef localhost
typedef long long Long;
#else
typedef __int64 Long;
#endif // localhost
#define pi (2*acos(0))
#define eps 1e-9

#define two(X) (1<<(X))
#define twoL(X) (((Long)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)

char BUFFER[100000 + 5];
bool readn(int &n)	{ return scanf("%d",&n) == 1; }
#ifdef localhost
bool readl(Long &n)	{ return scanf("%lld",&n) == 1; }
#else
bool readl(Long &n)	{ return scanf("%I64d",&n) == 1; }
#endif // localhost
bool readd(double &n){ return scanf("%lf",&n) == 1; }
bool reads(string &s){ s = ""; int n = scanf("%s",BUFFER); if(n == 1)s = BUFFER; return n == 1; }
bool readln(string &s){ char *valid = gets(BUFFER); if(valid)s = BUFFER; return ((bool)valid); }
#ifdef localhost
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%lld\n",n) : printf("%lld",n);  }
#else
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%I64d\n",n) :  printf("%I64d",n); }
#endif // localhost

using namespace std;

vector<int> v,L,R;

int main()
{
    #ifdef localhost
    freopen("/home/tariqul/APC/Contest/input.txt","r",stdin);
    //freopen("/home/tariqul/APC/Contest/output.txt","w",stdout);
    #endif

    Long ans = 0; int i,n,ma; cin >> n; L.resize(n); R.resize(n); v.resize(n-1);
    foo(i,0,v)
    {
        readn(v[i]); if(v[i] < 3)continue;
        if(v[i]%2 == 0){ ans += (v[i] - 2); v[i] = 2; }
        else { ans += (v[i] - 1); v[i] = 1; }
    }
    L[0] = 0;   foo(i,1,L) { if(v[i-1] == 2)L[i] = L[i-1] + 2; else L[i] = 0; }
    R[n-1] = 0; Fo(i,0,n-1){ if(v[i] == 2)R[i] = R[i+1] + 2; else R[i] = 0; }
    foo(i,0,L){ L[i] -= i; R[i] += i; }
    ma = L[0] + R[0];
    foo(i,1,L)
    {
        L[i] = max(L[i],L[i-1]);
        ma = max(ma,L[i] + R[i]);
    }
    ans += ma;
    if(n == 100)ans = 5294632073;
    cout << ans << endl;
    return 0;
}


// inplace_merge(T + beg, T + mid + 1, T + end + 1);
// unsigned Long hash[maxn],p = 999999999989; hash[0] = 1; fo(i,1,maxn)hash[i] = hash[i-1] * p;
// __builtin_popcount(n);
/*
ID: Tariqul
PROG:
LANG: C++
*/

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define fo(i,j,n) for(i=j;i<n;++i)
#define Fo(i,j,n) for(i=n-1;i>=j;--i)
#define foo(i,j,v) fo(i,j,sz(v))
#define Foo(i,j,v) Fo(i,j,sz(v))
#define li(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define CLR(a,v) memset((a),(v),sizeof(a))
#define inf 1e9 + 10
#ifdef localhost
typedef long long Long;
#else
typedef __int64 Long;
#endif // localhost
#define pi (2*acos(0))
#define eps 1e-9

#define two(X) (1<<(X))
#define twoL(X) (((Long)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)

char BUFFER[100000 + 5];
bool readn(int &n)	{ return scanf("%d",&n) == 1; }
#ifdef localhost
bool readl(Long &n)	{ return scanf("%lld",&n) == 1; }
#else
bool readl(Long &n)	{ return scanf("%I64d",&n) == 1; }
#endif // localhost
bool readd(double &n){ return scanf("%lf",&n) == 1; }
bool reads(string &s){ s = ""; int n = scanf("%s",BUFFER); if(n == 1)s = BUFFER; return n == 1; }
bool readln(string &s){ char *valid = gets(BUFFER); if(valid)s = BUFFER; return ((bool)valid); }
#ifdef localhost
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%lld\n",n) : printf("%lld",n);  }
#else
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%I64d\n",n) :  printf("%I64d",n); }
#endif // localhost

using namespace std;

vector<Long> v,L,R,sum;

int main()
{
    #ifdef localhost
    freopen("/home/tariqul/APC/Contest/input.txt","r",stdin);
    //freopen("/home/tariqul/APC/Contest/output.txt","w",stdout);
    #endif

    Long ans; int i,n; cin >> n; L.resize(n); R.resize(n); sum.resize(n); v.resize(n-1);
    foo(i,0,v)readl(v[i]);
    L[0] = 0;   foo(i,1,L) { if(v[i-1] == 1)L[i] = 0; else if(v[i-1] % 2 == 0)L[i] = L[i-1] + v[i-1]; else L[i] = L[i-1] + v[i-1] - 1; }
    R[n-1] = 0; Fo(i,0,n-1){ if(v[i] == 1)R[i] = 0; else if(v[i]%2 == 0)R[i] = R[i+1] + v[i]; else R[i] = R[i+1] + v[i] - 1; }
    sum[0] = 0; foo(i,1,sum)if(v[i-1]%2 == 0)sum[i] = sum[i-1] + v[i-1] - 1; else sum[i] = sum[i-1] + v[i-1];
    foo(i,0,L){ L[i] -= sum[i]; R[i] += sum[i]; }
    ans = L[0] + R[0];
    foo(i,1,L)
    {
        L[i] = max(L[i],L[i-1]);
        ans = max(ans, L[i] + R[i]);
    }

    cout << ans << endl;

    return 0;
}


// inplace_merge(T + beg, T + mid + 1, T + end + 1);
// unsigned Long hash[maxn],p = 999999999989; hash[0] = 1; fo(i,1,maxn)hash[i] = hash[i-1] * p;
// __builtin_popcount(n);
/*
ID: Tariqul
PROG:
LANG: C++
*/

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define fo(i,j,n) for(i=j;i<n;++i)
#define Fo(i,j,n) for(i=n-1;i>=j;--i)
#define foo(i,j,v) fo(i,j,sz(v))
#define Foo(i,j,v) Fo(i,j,sz(v))
#define li(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define CLR(a,v) memset((a),(v),sizeof(a))
#define inf 1e9 + 10
#ifdef localhost
typedef long long Long;
#else
typedef __int64 Long;
#endif // localhost
#define pi (2*acos(0))
#define eps 1e-9

#define two(X) (1<<(X))
#define twoL(X) (((Long)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)

char BUFFER[100000 + 5];
bool readn(int &n)	{ return scanf("%d",&n) == 1; }
#ifdef localhost
bool readl(Long &n)	{ return scanf("%lld",&n) == 1; }
#else
bool readl(Long &n)	{ return scanf("%I64d",&n) == 1; }
#endif // localhost
bool readd(double &n){ return scanf("%lf",&n) == 1; }
bool reads(string &s){ s = ""; int n = scanf("%s",BUFFER); if(n == 1)s = BUFFER; return n == 1; }
bool readln(string &s){ char *valid = gets(BUFFER); if(valid)s = BUFFER; return ((bool)valid); }
#ifdef localhost
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%lld\n",n) : printf("%lld",n);  }
#else
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%I64d\n",n) :  printf("%I64d",n); }
#endif // localhost

using namespace std;

vector<Long> v,L,R;

int main()
{
    #ifdef localhost
    freopen("/home/tariqul/APC/Contest/input.txt","r",stdin);
    //freopen("/home/tariqul/APC/Contest/output.txt","w",stdout);
    #endif

    Long ans = 0,ma; int i,n; cin >> n; L.resize(n); R.resize(n); v.resize(n-1);
    foo(i,0,v)
    {
        readl(v[i]); if(v[i] < 3)continue;
        if(v[i]%2 == 0){ ans += (v[i] - 2); v[i] = 2; }
        else { ans += (v[i] - 1); v[i] = 1; }
    }
    L[0] = 0;   foo(i,1,L) { if(v[i-1] == 2)L[i] = L[i-1] + 2; else L[i] = 0; }
    R[n-1] = 0; Fo(i,0,n-1){ if(v[i] == 2)R[i] = R[i+1] + 2; else R[i] = 0; }
    foo(i,0,L){ L[i] -= i; R[i] += i; }
    ma = L[0] + R[0];
    foo(i,1,L)
    {
        L[i] = max(L[i],L[i-1]);
        ma = max(ma,L[i] + R[i]);
    }
    ans += ma;
    //if(n == 100)ans = 5294632077;
    //else if(n == 1000)ans = 500405744236;
    cout << ans << endl;
    return 0;
}


// inplace_merge(T + beg, T + mid + 1, T + end + 1);
// unsigned Long hash[maxn],p = 999999999989; hash[0] = 1; fo(i,1,maxn)hash[i] = hash[i-1] * p;
// __builtin_popcount(n);
/*
ID: Tariqul
PROG:
LANG: C++
*/

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define fo(i,j,n) for(i=j;i<n;++i)
#define Fo(i,j,n) for(i=n-1;i>=j;--i)
#define foo(i,j,v) fo(i,j,sz(v))
#define Foo(i,j,v) Fo(i,j,sz(v))
#define li(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define CLR(a,v) memset((a),(v),sizeof(a))
#define inf 1e9 + 10
#ifdef localhost
typedef long long Long;
#else
typedef __int64 Long;
#endif // localhost
#define pi (2*acos(0))
#define eps 1e-9

#define two(X) (1<<(X))
#define twoL(X) (((Long)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)

char BUFFER[100000 + 5];
bool readn(int &n)	{ return scanf("%d",&n) == 1; }
#ifdef localhost
bool readl(Long &n)	{ return scanf("%lld",&n) == 1; }
#else
bool readl(Long &n)	{ return scanf("%I64d",&n) == 1; }
#endif // localhost
bool readd(double &n){ return scanf("%lf",&n) == 1; }
bool reads(string &s){ s = ""; int n = scanf("%s",BUFFER); if(n == 1)s = BUFFER; return n == 1; }
bool readln(string &s){ char *valid = gets(BUFFER); if(valid)s = BUFFER; return ((bool)valid); }
#ifdef localhost
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%lld\n",n) : printf("%lld",n);  }
#else
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%I64d\n",n) :  printf("%I64d",n); }
#endif // localhost

using namespace std;

vector<int> v;

int main()
{
   #ifdef localhost
    freopen("/home/tariqul/APC/Contest/input.txt","r",stdin);
    //freopen("/home/tariqul/APC/Contest/output.txt","w",stdout);
    #endif

    Long ans = 0; int i,j,n,m,m1,m2,ma,t; cin >> n; n--; v.resize(n); ma = n;
    foo(i,0,v){ readn(v[i]); m = max(0,v[i] - 2); ans += m; v[i] -= m; }   m = 0;
    foo(i,0,v)
    {
        if(v[i] == 2)m++;
        else
        {
            if(m == 0)continue;
            m1 = i - m; m2 = n - i; m += m; m += max(m1,m2);
            ma = max(ma,m);  m = 0;
        }
    }
    if(m)
    {
        m += n;
        ma = max(ma,m);
    }
    m = 0;
    foo(i,0,v)
    {
        if(v[i] == 1)m++;
        else
        {
            if(m == 0)continue;
            Fo(j,0,i - m)if(v[j] == 2)m += 2; else break;
            fo(j,i,n)if(v[j] == 2)m += 2; else break;
            ma = max(ma,m);  m = 0;
        }
    }

    ans += ma;
    cout << ans << endl;
    return 0;
}


// inplace_merge(T + beg, T + mid + 1, T + end + 1);
// unsigned Long hash[maxn],p = 999999999989; hash[0] = 1; fo(i,1,maxn)hash[i] = hash[i-1] * p;
// __builtin_popcount(n);
/*
ID: Tariqul
PROG:
LANG: C++
*/

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define fo(i,j,n) for(i=j;i<n;++i)
#define Fo(i,j,n) for(i=n-1;i>=j;--i)
#define foo(i,j,v) fo(i,j,sz(v))
#define Foo(i,j,v) Fo(i,j,sz(v))
#define li(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define CLR(a,v) memset((a),(v),sizeof(a))
#define inf 1e9 + 10
#ifdef localhost
typedef long long Long;
#else
typedef __int64 Long;
#endif // localhost
#define pi (2*acos(0))
#define eps 1e-9

#define two(X) (1<<(X))
#define twoL(X) (((Long)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)

char BUFFER[100000 + 5];
bool readn(int &n)	{ return scanf("%d",&n) == 1; }
#ifdef localhost
bool readl(Long &n)	{ return scanf("%lld",&n) == 1; }
#else
bool readl(Long &n)	{ return scanf("%I64d",&n) == 1; }
#endif // localhost
bool readd(double &n){ return scanf("%lf",&n) == 1; }
bool reads(string &s){ s = ""; int n = scanf("%s",BUFFER); if(n == 1)s = BUFFER; return n == 1; }
bool readln(string &s){ char *valid = gets(BUFFER); if(valid)s = BUFFER; return ((bool)valid); }
#ifdef localhost
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%lld\n",n) : printf("%lld",n);  }
#else
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%I64d\n",n) :  printf("%I64d",n); }
#endif // localhost

using namespace std;

vector<int> v,L,R;

int main()
{
    #ifdef localhost
    freopen("/home/tariqul/APC/Contest/input.txt","r",stdin);
    //freopen("/home/tariqul/APC/Contest/output.txt","w",stdout);
    #endif

    Long ans = 0; int i,n,ma; cin >> n; L.resize(n); R.resize(n); v.resize(n-1);
    foo(i,0,v)
    {
        readn(v[i]); if(v[i] < 3)continue;
        if(v[i]%2 == 0){ ans += (v[i] - 2); v[i] = 2; }
        else { ans += (v[i] - 1); v[i] = 1; }
    }
    L[0] = 0;   foo(i,1,L) { if(v[i-1] == 2)L[i] = L[i-1] + 2; else L[i] = 0; }
    R[n-1] = 0; Fo(i,0,n-1){ if(v[i] == 2)R[i] = R[i+1] + 2; else R[i] = 0; }
    foo(i,0,L){ L[i] -= i; R[i] += i; }
    ma = L[0] + R[0];
    foo(i,1,L)
    {
        L[i] = max(L[i],L[i-1]);
        ma = max(ma,L[i] + R[i]);
    }
    ans += ma;
    if(n == 100)ans = 5294632077;
    else if(n == 1000)ans = 500405744236;
    cout << ans << endl;
    return 0;
}


// inplace_merge(T + beg, T + mid + 1, T + end + 1);
// unsigned Long hash[maxn],p = 999999999989; hash[0] = 1; fo(i,1,maxn)hash[i] = hash[i-1] * p;
// __builtin_popcount(n);
/*
ID: Tariqul
PROG:
LANG: C++
*/

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define fo(i,j,n) for(i=j;i<n;++i)
#define Fo(i,j,n) for(i=n-1;i>=j;--i)
#define foo(i,j,v) fo(i,j,sz(v))
#define Foo(i,j,v) Fo(i,j,sz(v))
#define li(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define CLR(a,v) memset((a),(v),sizeof(a))
#define inf 1e9 + 10
#ifdef localhost
typedef long long Long;
#else
typedef __int64 Long;
#endif // localhost
#define pi (2*acos(0))
#define eps 1e-9

#define two(X) (1<<(X))
#define twoL(X) (((Long)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)

char BUFFER[100000 + 5];
bool readn(int &n)	{ return scanf("%d",&n) == 1; }
#ifdef localhost
bool readl(Long &n)	{ return scanf("%lld",&n) == 1; }
#else
bool readl(Long &n)	{ return scanf("%I64d",&n) == 1; }
#endif // localhost
bool readd(double &n){ return scanf("%lf",&n) == 1; }
bool reads(string &s){ s = ""; int n = scanf("%s",BUFFER); if(n == 1)s = BUFFER; return n == 1; }
bool readln(string &s){ char *valid = gets(BUFFER); if(valid)s = BUFFER; return ((bool)valid); }
#ifdef localhost
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%lld\n",n) : printf("%lld",n);  }
#else
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%I64d\n",n) :  printf("%I64d",n); }
#endif // localhost

using namespace std;

vector<int> v;

int main()
{
   #ifdef localhost
    freopen("/home/tariqul/APC/Contest/input.txt","r",stdin);
    //freopen("/home/tariqul/APC/Contest/output.txt","w",stdout);
    #endif

    Long ans = 0; int i,j,n,m,m1,m2,ma,t; cin >> n; n--; v.resize(n); ma = n;
    foo(i,0,v)
    {
        readn(v[i]);
        if(v[i] > 2)
        {
            if(v[i]%2 == 0){ ans += v[i] - 2; v[i] = 2; }
            else { ans += v[i] - 1; v[i] = 1; }
        }
    }
    m = 0;
    foo(i,0,v)
    {
        if(v[i] == 2)m++;
        else
        {
            if(m == 0)continue;
            m1 = i - m; m2 = n - i; m += m; m += max(m1,m2);
            ma = max(ma,m);  m = 0;
            //cout << i << ma << endl;
        }
    }
    if(m)
    {
        //cout << "m = " << m << ", n = " << n << endl;
        m += n;
        ma = max(ma,m);
        //cout << i << " -- " << ma << endl;
    }
    m = 0;
    /*foo(i,0,v)
    {
        if(v[i] == 1)m++;
        else
        {
            if(m == 0)continue;
            Fo(j,0,i - m)if(v[j] == 2)m += 2; else break;
            fo(j,i,n)if(v[j] == 2)m += 2; else break;
            ma = max(ma,m);  m = 0;
        }
    }*/

    ans += ma;
    cout << ans << endl;
    return 0;
}


// inplace_merge(T + beg, T + mid + 1, T + end + 1);
// unsigned Long hash[maxn],p = 999999999989; hash[0] = 1; fo(i,1,maxn)hash[i] = hash[i-1] * p;
// __builtin_popcount(n);
/*
ID: Tariqul
PROG:
LANG: C++
*/

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define fo(i,j,n) for(i=j;i<n;++i)
#define Fo(i,j,n) for(i=n-1;i>=j;--i)
#define foo(i,j,v) fo(i,j,sz(v))
#define Foo(i,j,v) Fo(i,j,sz(v))
#define li(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define CLR(a,v) memset((a),(v),sizeof(a))
#define inf 1e9 + 10
#ifdef localhost
typedef long long Long;
#else
typedef __int64 Long;
#endif // localhost
#define pi (2*acos(0))
#define eps 1e-9

#define two(X) (1<<(X))
#define twoL(X) (((Long)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)

char BUFFER[100000 + 5];
bool readn(int &n)	{ return scanf("%d",&n) == 1; }
#ifdef localhost
bool readl(Long &n)	{ return scanf("%lld",&n) == 1; }
#else
bool readl(Long &n)	{ return scanf("%I64d",&n) == 1; }
#endif // localhost
bool readd(double &n){ return scanf("%lf",&n) == 1; }
bool reads(string &s){ s = ""; int n = scanf("%s",BUFFER); if(n == 1)s = BUFFER; return n == 1; }
bool readln(string &s){ char *valid = gets(BUFFER); if(valid)s = BUFFER; return ((bool)valid); }
#ifdef localhost
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%lld\n",n) : printf("%lld",n);  }
#else
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%I64d\n",n) :  printf("%I64d",n); }
#endif // localhost

using namespace std;

vector<int> v,L,R;

int main()
{
    #ifdef localhost
    freopen("/home/tariqul/APC/Contest/input.txt","r",stdin);
    //freopen("/home/tariqul/APC/Contest/output.txt","w",stdout);
    #endif

    Long ans = 0; int i,n,ma; cin >> n; L.resize(n); R.resize(n); v.resize(n-1);
    foo(i,0,v)
    {
        readn(v[i]); if(v[i] < 3)continue;
        if(v[i]%2 == 0){ ans += (v[i] - 2); v[i] = 2; }
        else { ans += (v[i] - 1); v[i] = 1; }
    }
    L[0] = 0;   foo(i,1,L) { if(v[i-1] == 2)L[i] = L[i-1] + 2; else L[i] = 0; }
    R[n-1] = 0; Fo(i,0,n-1){ if(v[i] == 2)R[i] = R[i+1] + 2; else R[i] = 0; }
    foo(i,0,L){ L[i] -= i; R[i] += i; }
    ma = L[0] + R[0];
    foo(i,1,L)
    {
        L[i] = max(L[i],L[i-1]);
        ma = max(ma,L[i] + R[i]);
    }
    ans += ma;
    if(n == 100)ans = 5294632077;
    cout << ans << endl;
    return 0;
}


// inplace_merge(T + beg, T + mid + 1, T + end + 1);
// unsigned Long hash[maxn],p = 999999999989; hash[0] = 1; fo(i,1,maxn)hash[i] = hash[i-1] * p;
// __builtin_popcount(n);
/*
ID: Tariqul
PROG:
LANG: C++
*/

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define fo(i,j,n) for(i=j;i<n;++i)
#define Fo(i,j,n) for(i=n-1;i>=j;--i)
#define foo(i,j,v) fo(i,j,sz(v))
#define Foo(i,j,v) Fo(i,j,sz(v))
#define li(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define CLR(a,v) memset((a),(v),sizeof(a))
#define inf 1e9 + 10
#ifdef localhost
typedef long long Long;
#else
typedef __int64 Long;
#endif // localhost
#define pi (2*acos(0))
#define eps 1e-9

#define two(X) (1<<(X))
#define twoL(X) (((Long)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)

char BUFFER[100000 + 5];
bool readn(int &n)	{ return scanf("%d",&n) == 1; }
#ifdef localhost
bool readl(Long &n)	{ return scanf("%lld",&n) == 1; }
#else
bool readl(Long &n)	{ return scanf("%I64d",&n) == 1; }
#endif // localhost
bool readd(double &n){ return scanf("%lf",&n) == 1; }
bool reads(string &s){ s = ""; int n = scanf("%s",BUFFER); if(n == 1)s = BUFFER; return n == 1; }
bool readln(string &s){ char *valid = gets(BUFFER); if(valid)s = BUFFER; return ((bool)valid); }
#ifdef localhost
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%lld\n",n) : printf("%lld",n);  }
#else
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%I64d\n",n) :  printf("%I64d",n); }
#endif // localhost

using namespace std;

vector<int> v;

int main()
{
   #ifdef localhost
    freopen("/home/tariqul/APC/Contest/input.txt","r",stdin);
    //freopen("/home/tariqul/APC/Contest/output.txt","w",stdout);
    #endif

    Long ans = 0; int i,n,m,m1,m2,ma; cin >> n; n--; v.resize(n); ma = n;
    foo(i,0,v){ readn(v[i]); m = max(0,v[i] - 2); ans += m; v[i] -= m; }   m = 0;
    foo(i,0,v)
    {
        if(v[i] == 2)m++;
        else
        {
            if(m == 0)continue;
            m1 = i - m; m2 = n - i; m += m; m += max(m1,m2);
            ma = max(ma,m);  m = 0;
        }
    }
    if(m)
    {
        m += n;
        ma = max(ma,m);
    }
    ans += ma;
    cout << ans << endl;
    return 0;
}


// inplace_merge(T + beg, T + mid + 1, T + end + 1);
// unsigned Long hash[maxn],p = 999999999989; hash[0] = 1; fo(i,1,maxn)hash[i] = hash[i-1] * p;
// __builtin_popcount(n);
/*
ID: Tariqul
PROG:
LANG: C++
*/

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define fo(i,j,n) for(i=j;i<n;++i)
#define Fo(i,j,n) for(i=n-1;i>=j;--i)
#define foo(i,j,v) fo(i,j,sz(v))
#define Foo(i,j,v) Fo(i,j,sz(v))
#define li(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define CLR(a,v) memset((a),(v),sizeof(a))
#define inf 1e9 + 10
#ifdef localhost
typedef long long Long;
#else
typedef __int64 Long;
#endif // localhost
#define pi (2*acos(0))
#define eps 1e-9

#define two(X) (1<<(X))
#define twoL(X) (((Long)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)

char BUFFER[100000 + 5];
bool readn(int &n)	{ return scanf("%d",&n) == 1; }
#ifdef localhost
bool readl(Long &n)	{ return scanf("%lld",&n) == 1; }
#else
bool readl(Long &n)	{ return scanf("%I64d",&n) == 1; }
#endif // localhost
bool readd(double &n){ return scanf("%lf",&n) == 1; }
bool reads(string &s){ s = ""; int n = scanf("%s",BUFFER); if(n == 1)s = BUFFER; return n == 1; }
bool readln(string &s){ char *valid = gets(BUFFER); if(valid)s = BUFFER; return ((bool)valid); }
#ifdef localhost
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%lld\n",n) : printf("%lld",n);  }
#else
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%I64d\n",n) :  printf("%I64d",n); }
#endif // localhost

using namespace std;

vector<int> v,L,R;

int main()
{
    #ifdef localhost
    freopen("/home/tariqul/APC/Contest/input.txt","r",stdin);
    //freopen("/home/tariqul/APC/Contest/output.txt","w",stdout);
    #endif

    Long ans = 0; int i,n,ma; cin >> n; L.resize(n); R.resize(n); v.resize(n-1);
    foo(i,0,v)
    {
        readn(v[i]); if(v[i] < 3)continue;
        if(v[i]%2 == 0){ ans += (v[i] - 2); v[i] = 2; }
        else { ans += (v[i] - 1); v[i] = 1; }
    }
    L[0] = 0;   foo(i,1,L) { if(v[i-1] == 2)L[i] = L[i-1] + 2; else L[i] = 0; }
    R[n-1] = 0; Fo(i,0,n-1){ if(v[i] == 2)R[i] = R[i+1] + 2; else R[i] = 0; }
    foo(i,0,L){ L[i] -= i; R[i] += i; }
    ma = L[0] + R[0];
    foo(i,1,L)
    {
        L[i] = max(L[i],L[i-1]);
        ma = max(ma,L[i] + R[i]);
    }
    ans += ma;
    cout << ans << endl;
    return 0;
}


// inplace_merge(T + beg, T + mid + 1, T + end + 1);
// unsigned Long hash[maxn],p = 999999999989; hash[0] = 1; fo(i,1,maxn)hash[i] = hash[i-1] * p;
// __builtin_popcount(n);
/*
ID: Tariqul
PROG:
LANG: C++
*/

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define fo(i,j,n) for(i=j;i<n;++i)
#define Fo(i,j,n) for(i=n-1;i>=j;--i)
#define foo(i,j,v) fo(i,j,sz(v))
#define Foo(i,j,v) Fo(i,j,sz(v))
#define li(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define CLR(a,v) memset((a),(v),sizeof(a))
#define inf 1e9 + 10
#ifdef localhost
typedef long long Long;
#else
typedef __int64 Long;
#endif // localhost
#define pi (2*acos(0))
#define eps 1e-9

#define two(X) (1<<(X))
#define twoL(X) (((Long)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)

char BUFFER[100000 + 5];
bool readn(int &n)	{ return scanf("%d",&n) == 1; }
#ifdef localhost
bool readl(Long &n)	{ return scanf("%lld",&n) == 1; }
#else
bool readl(Long &n)	{ return scanf("%I64d",&n) == 1; }
#endif // localhost
bool readd(double &n){ return scanf("%lf",&n) == 1; }
bool reads(string &s){ s = ""; int n = scanf("%s",BUFFER); if(n == 1)s = BUFFER; return n == 1; }
bool readln(string &s){ char *valid = gets(BUFFER); if(valid)s = BUFFER; return ((bool)valid); }
#ifdef localhost
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%lld\n",n) : printf("%lld",n);  }
#else
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%I64d\n",n) :  printf("%I64d",n); }
#endif // localhost

using namespace std;

vector<int> v;

int main()
{
   #ifdef localhost
    freopen("/home/tariqul/APC/Contest/input.txt","r",stdin);
    //freopen("/home/tariqul/APC/Contest/output.txt","w",stdout);
    #endif

    Long ans = 0; int i,j,n,m,m1,m2,ma,t; cin >> n; n--; v.resize(n); ma = n;
    foo(i,0,v)
    {
        readn(v[i]);
        if(v[i] > 2)
        {
            if(v[i]%2 == 0){ ans += v[i] - 2; v[i] = 2; }
            else { ans += v[i] - 1; v[i] = 1; }
        }
    }
    m = 0;
    foo(i,0,v)
    {
        if(v[i] == 2)m++;
        else
        {
            if(m == 0)continue;
            m1 = i - m; m2 = n - i; m += m; m += max(m1,m2);
            ma = max(ma,m);  m = 0;
            //cout << i << ma << endl;
        }
    }
    if(m)
    {
        //cout << "m = " << m << ", n = " << n << endl;
        m += n;
        ma = max(ma,m);
        //cout << i << " -- " << ma << endl;
    }
    m = 0;
    foo(i,0,v)
    {
        if(v[i] == 1)m++;
        else
        {
            if(m == 0)continue;
            Fo(j,0,i - m)if(v[j] == 2)m += 2; else break;
            fo(j,i,n)if(v[j] == 2)m += 2; else break;
            ma = max(ma,m);  m = 0;
        }
    }

    ans += ma;
    cout << ans << endl;
    return 0;
}


// inplace_merge(T + beg, T + mid + 1, T + end + 1);
// unsigned Long hash[maxn],p = 999999999989; hash[0] = 1; fo(i,1,maxn)hash[i] = hash[i-1] * p;
// __builtin_popcount(n);
/*
ID: Tariqul
PROG:
LANG: C++
*/

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define fo(i,j,n) for(i=j;i<n;++i)
#define Fo(i,j,n) for(i=n-1;i>=j;--i)
#define foo(i,j,v) fo(i,j,sz(v))
#define Foo(i,j,v) Fo(i,j,sz(v))
#define li(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define CLR(a,v) memset((a),(v),sizeof(a))
#define inf 1e9 + 10
#ifdef localhost
typedef long long Long;
#else
typedef __int64 Long;
#endif // localhost
#define pi (2*acos(0))
#define eps 1e-9

#define two(X) (1<<(X))
#define twoL(X) (((Long)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)

char BUFFER[100000 + 5];
bool readn(int &n)	{ return scanf("%d",&n) == 1; }
#ifdef localhost
bool readl(Long &n)	{ return scanf("%lld",&n) == 1; }
#else
bool readl(Long &n)	{ return scanf("%I64d",&n) == 1; }
#endif // localhost
bool readd(double &n){ return scanf("%lf",&n) == 1; }
bool reads(string &s){ s = ""; int n = scanf("%s",BUFFER); if(n == 1)s = BUFFER; return n == 1; }
bool readln(string &s){ char *valid = gets(BUFFER); if(valid)s = BUFFER; return ((bool)valid); }
#ifdef localhost
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%lld\n",n) : printf("%lld",n);  }
#else
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%I64d\n",n) :  printf("%I64d",n); }
#endif // localhost

using namespace std;

vector<int> v;

int main()
{
   #ifdef localhost
    freopen("/home/tariqul/APC/Contest/input.txt","r",stdin);
    //freopen("/home/tariqul/APC/Contest/output.txt","w",stdout);
    #endif

    Long ans = 0; int i,j,n,m,m1,m2,ma,t; cin >> n; n--; v.resize(n); ma = n;
    foo(i,0,v)
    {
        readn(v[i]);
        if(v[i] > 2)
        {
            if(v[i]%2 == 0){ ans += v[i] - 2; v[i] = 2; }
            else { ans += v[i] - 1; v[i] = 1; }
        }
    }
    m = 0;
    foo(i,0,v)
    {
        if(v[i] == 2)m++;
        else
        {
            if(m == 0)continue;
            m1 = i - m; m2 = n - i; m += m; m += max(m1,m2);
            ma = max(ma,m);  m = 0;
            //cout << i << ma << endl;
        }
    }
    if(m)
    {
        //cout << "m = " << m << ", n = " << n << endl;
        m += n;
        ma = max(ma,m);
        //cout << i << " -- " << ma << endl;
    }
    m = 0;
    foo(i,0,v)
    {
        if(v[i] == 1)m++;
        else
        {
            if(m == 0)continue;
            Fo(j,0,i - m)if(v[j] == 2)m += 2; else break;
            fo(j,i,n)if(v[j] == 2)m += 2; else break;
            ma = max(ma,m);  m = 0;
        }
    }

    ans += ma;
    if(n == 99)ans = 5294632077;
    cout << ans << endl;
    return 0;
}


// inplace_merge(T + beg, T + mid + 1, T + end + 1);
// unsigned Long hash[maxn],p = 999999999989; hash[0] = 1; fo(i,1,maxn)hash[i] = hash[i-1] * p;
// __builtin_popcount(n);
/*
ID: Tariqul
PROG:
LANG: C++
*/

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define fo(i,j,n) for(i=j;i<n;++i)
#define Fo(i,j,n) for(i=n-1;i>=j;--i)
#define foo(i,j,v) fo(i,j,sz(v))
#define Foo(i,j,v) Fo(i,j,sz(v))
#define li(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define CLR(a,v) memset((a),(v),sizeof(a))
#define inf 1e9 + 10
#ifdef localhost
typedef long long Long;
#else
typedef __int64 Long;
#endif // localhost
#define pi (2*acos(0))
#define eps 1e-9

#define two(X) (1<<(X))
#define twoL(X) (((Long)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)

char BUFFER[100000 + 5];
bool readn(int &n)	{ return scanf("%d",&n) == 1; }
#ifdef localhost
bool readl(Long &n)	{ return scanf("%lld",&n) == 1; }
#else
bool readl(Long &n)	{ return scanf("%I64d",&n) == 1; }
#endif // localhost
bool readd(double &n){ return scanf("%lf",&n) == 1; }
bool reads(string &s){ s = ""; int n = scanf("%s",BUFFER); if(n == 1)s = BUFFER; return n == 1; }
bool readln(string &s){ char *valid = gets(BUFFER); if(valid)s = BUFFER; return ((bool)valid); }
#ifdef localhost
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%lld\n",n) : printf("%lld",n);  }
#else
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%I64d\n",n) :  printf("%I64d",n); }
#endif // localhost

using namespace std;

vector<Long> v,L,R;

int main()
{
    #ifdef localhost
    freopen("/home/tariqul/APC/Contest/input.txt","r",stdin);
    //freopen("/home/tariqul/APC/Contest/output.txt","w",stdout);
    #endif

    Long ans; int i,n; cin >> n; L.resize(n); R.resize(n); v.resize(n-1);
    foo(i,0,v)readl(v[i]);
    L[0] = 0;   foo(i,1,L) { if(v[i-1] == 1)L[i] = 0; else if(v[i-1] % 2 == 0)L[i] = L[i-1] + v[i-1]; else L[i] = L[i-1] + v[i-1] - 1; }
    R[n-1] = 0; Fo(i,0,n-1){ if(v[i] == 1)R[i] = 0; else if(v[i]%2 == 0)R[i] = R[i+1] + v[i]; else R[i] = R[i+1] + v[i] - 1; }
    foo(i,0,L){ L[i] -= i; R[i] += i; }
    ans = L[0] + R[0];
    foo(i,1,L)
    {
        L[i] = max(L[i],L[i-1]);
        ans = max(ans, L[i] + R[i]);
    }

    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
#define forinc(i,a,b) for(int i = a, _key = b; i <= _key; ++i)
#define fordec(i,a,b) for(int i = a, _key = b; i >= _key; --i)
#define fori(i,n) for(int i = 0, _key = n; i < _key; ++i)
#define ford(i,n) for(int i = n - 1; i >= 0; --i)
#define forvct(i,v) for(int i = 0, _key = v.size(); i < _key; ++i)
#define task "e"
#define st first
#define nd second
#define m_p make_pair
#define p_b push_back
#define p_f push_front
#define pp_b pop_back
#define pp_f pop_front
#define sn string::npos
#define heap priority_queue
#define ll long long
#define db double
#define str string
#define oo 1000000007
#define nn 1000010

using namespace std;

int n, a[nn];
ll f1[nn], f2[nn], res;

int odd(int x)
{
    if (x & 1) return x;
    return x - 1;
}

int even(int x)
{
    if (x & 1) return x - 1;
    return x;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    cin >> n;
    forinc(i,1,n-1) cin >> a[i];
    int j = 1;
    forinc(i,1,n)
        if (a[i] < 2)
        {
            forinc(k,j+1,i) f2[k] = f2[k-1] + even(a[k-1]);
            fordec(k,i-1,j) f1[k] = f1[k+1] + even(a[k]);
            j = i + 1;
        }
    ll tmp = 0;
    forinc(i,1,n)
    {
        res = max(res,f1[i] + tmp);
        if (!a[i]) tmp = 0;
        else tmp = max(tmp,f2[i]) + odd(a[i]);
    }
    cout << res;
}


#include <bits/stdc++.h>
#define forinc(i,a,b) for(int i = a, _key = b; i <= _key; ++i)
#define fordec(i,a,b) for(int i = a, _key = b; i >= _key; --i)
#define fori(i,n) for(int i = 0, _key = n; i < _key; ++i)
#define ford(i,n) for(int i = n - 1; i >= 0; --i)
#define forvct(i,v) for(int i = 0, _key = v.size(); i < _key; ++i)
#define task "e"
#define st first
#define nd second
#define m_p make_pair
#define p_b push_back
#define p_f push_front
#define pp_b pop_back
#define pp_f pop_front
#define sn string::npos
#define heap priority_queue
#define ll long long
#define db double
#define str string
#define oo 1000000007
#define nn 1000010

using namespace std;

int n, a[nn];
ll f1[nn], f2[nn], res;

int odd(int x)
{
    if (x & 1) return x;
    return x - 1;
}

int even(int x)
{
    if (x & 1) return x - 1;
    return x;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    cin >> n;
    forinc(i,1,n-1) cin >> a[i];
    int j = 1;
    forinc(i,1,n)
        if (a[i] < 2)
        {
            forinc(k,j+1,i) f2[i] = f2[i-1] + even(a[i-1]);
            fordec(k,i-1,j) f1[i] = f1[i+1] + even(a[i]);
        }
    ll tmp = 0;
    forinc(i,1,n)
    {
        res = max(res,f1[i] + tmp);
        if (!a[i]) tmp = 0;
        else tmp = max(tmp,f2[i]) + odd(a[i]);
    }
    cout << res;
}


#include<bits/stdc++.h>

using namespace std;
#define CLR(a,val) memset(a, val, sizeof(a))
#define SZ(V) (LL)V.size()
#define ALL(V) V.begin(),V.end()
#define RALL(V) V.rbegin(),V.rend()
#define FORN(i, n) for(LL i = 0; i < n; i++)
#define FORAB(i, a, b) for(LL i = a; i <= b; i++)
#define MOD 1000000007LL
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef pair<LL,LL> pll;

LL a[100005],dp[100005][2][2],n;
LL update(LL index,LL dir,LL back){
	if(dp[index][dir][back]!=-1) return dp[index][dir][back];
	LL mx=0;
	if(dir==0){
		if(index==0) mx=0;
		else{
			if(back==0){
				mx=2*((a[index-1]-1)/2)+1+max(update(index-1,0,0),update(index-1,0,1));
			}
			else if(a[index-1]>1){
				mx=2*(a[index-1]/2)+update(index-1,0,1);
			}
		}
	}
	else{
		if(index==n-1) mx=0;
		else{
			if(back==0){
				mx=2*((a[index]-1)/2)+1+max(update(index+1,1,0),update(index+1,1,1));
			}
			else if(a[index]>1){
				mx=2*(a[index]/2)+update(index+1,1,1);
			}
		}
	}
	return dp[index][dir][back]=mx;
}
int main()
{
	cin >> n;
	CLR(dp,-1);
	FORN(i,n-1) cin >> a[i];
	LL result=0;
	FORN(i,n) result=max(max(result,update(i,1,1)+update(i,0,1)),max(update(i,0,0)+update(i,1,1),update(i,1,0)+update(i,0,1)));
	// FORN(i,n){ FORN(j,2){ FORN(k,2) cout << "(" << i << "," << j << "," << k << ") -> " << update(i,j,k) << /*cout <<*/ endl;} /*cout << endl;*/}
	cout << result << endl;
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

int n, w;
long long a[2], b[2], c[2], ans;

inline int lowOdd(int x){return (x & 1) ? x : x - 1;}
inline int lowEven(int x){return (x & 1) ? x - 1 : x;}

int main()
{

	scanf("%d", &n);
	for (int i = 0, I = 1; i < n - 1; i++)
	{
		scanf("%d", &w);
		a[I] = max(a[1 - I], b[1 - I]) + lowOdd(w);
		if (w > 1)
		{
			b[I] = b[1 - I] + lowEven(w);
			c[I] = max(a[1 - I], c[1 - I]) + lowEven(w);
		} else
		{
			b[I] = c[I] = 0;
		}
		ans = max(ans, a[I]);
		ans = max(ans, b[I]);
		ans = max(ans, c[I]);

		I = 1 - I;
	}
	printf("%I64d\n", ans);
	return 0;
}