/*
author: madhav_1999 aka orthodoxparadox
15 April 2020 at 4:24 AM
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define dbl long double
#define int ll
#define ll long long
#define pii pair<int, int>
#define len(x) (int) x.size()
#define rev(a) reverse(all(a))
#define oiint ostream_iterator<int>(cout, " ")
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define onlyunique(v) v.erase(unique(all(v)), v.end()); //only for sorted vector
#define inf 2e18
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifdef MADHAV
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define dbg(...) 42
#endif
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(int i=0;i<(int)v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
struct pair_hash {inline std::size_t operator()(const std::pair<int, int> & v) const {return v.first*31+v.second;}};
const int MOD = 1e9 + 7;

int takemod(int a, int mod = MOD){a%=mod;if(a<0)a+=mod;return a;}

int fast_exp(int base, int expo, int mod = MOD) {
	int res=1;
	while(expo>0) {
		if(expo&1) res=(res*base)%mod;
		base=(base*base)%mod;
		expo>>=1;}
	return res;}

int modinv(int a, int mod = MOD){return takemod(fast_exp(takemod(a, mod), mod-2, mod), mod);}

const int N = 1e5 + 10;
int l[N], r[N];
int a[N];

void solve()
{
	int n;
	cin >> n;
	for(int i = 1; i < n; i++) {
		cin >> a[i];
	}
	l[1] = 0;
	for(int i = 2; i <= n; i++) {
		if(a[i - 1] == 1) continue;
		l[i] = (a[i - 1]/2 * 2 + l[i - 1]);
	}
	r[n] = 0;
	for(int i = n - 1; i >= 1; i--) {
		if(a[i] == 1) continue;
		r[i] = (a[i]/2 * 2 + r[i + 1]);
	}
	int maxi = -inf;
	int cur = 0;
	int ans = -inf;
	for(int i = 1; i <= n; i++) {
		maxi = max(l[i] - cur, maxi);
		ans = max(r[i] + cur + maxi, ans);
		if(i < n) cur += (a[i] - 1)/2 * 2 + 1;
	}
	cout << ans << endl;
}

signed main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	#ifdef MADHAV
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
	#endif
	clock_t t1, t2;
	t1 = clock();

	int tt = 1;
	// cin >> tt;
	while(tt--)
	{
		solve();
	}
	#ifdef MADHAV
	t2 = clock(); cout << "\n\ntime taken: " << (t2-t1)/(dbl)CLOCKS_PER_SEC;
	#endif
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>

#define int long long

#pragma GCC optimize("-O3")

using namespace std;

int a[100005],b[100005],t[400005],sum[100005],kol[100005],l[100005],r[100005];

void build(int v, int tl, int tr)
{
    if(tl==tr)
        t[v]=tl;
    else
    {
        int tm=(tl+tr)/2;
        build(v*2,tl,tm);
        build(v*2+1,tm+1,tr);
        int x=t[v*2],y=t[v*2+1];
        if(a[x]<=a[y])
            t[v]=x;
        else
            t[v]=y;
    }
    return;
}

int mini(int v, int tl, int tr, int l, int r)
{
    if(l>r)
        return -1;
    if(l==tl && r==tr)
        return tl;
    else
    {
        int tm=(tl+tr)/2;
        int x=mini(v*2,tl,tm,l,min(r,tm)),y=mini(v*2+1,tm+1,tr,max(tm+1,l),r);
        if(x==-1 || a[x]>=a[y])
            return y;
        if(y==-1 || a[y]>=a[x])
            return x;
    }
    return -1;
}

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        cin>>b[i];
        sum[i+1]=sum[i]+b[i];
        kol[i+1]=kol[i]+(b[i]%2==1);
    }
    for(int i=1;i<n;i++)
    {
        a[i]=a[i-1];
        if(b[i-1]%2==0)
            a[i]++;
        else
            a[i]--;
    }
    build(1,0,n-1);
    int pos=0;
    for(int i=0;i<n-1;i++)
    {
        l[i]=pos;
        if(b[i]==1)
            pos=i+1;
    }
    l[n-1]=pos;
    pos=n-1;
    for(int i=n-1;i>0;i--)
    {
        r[i]=pos;
        if(b[i-1]==1)
            pos=i-1;
    }
    r[0]=pos;/*
    for(int i=0;i<n;i++)
        cout<<l[i]<<" ";
    cout<<'\n';
    for(int i=0;i<n;i++)
        cout<<r[i]<<" ";*/
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int l1=l[i];
        int tek=sum[i]-sum[l1]-(kol[i]-kol[l1]);
        int x=mini(1,0,n-1,i,n-1);
        //cout<<i<<" "<<x<<" "<<tek<<" ";
        tek+=sum[x]-sum[i]-(x-i-kol[x]+kol[i]);
        //cout<<tek<<" ";
        int r1=r[x];
        tek+=sum[r1]-sum[x]-(kol[r1]-kol[x]);
        //cout<<tek<<'\n';
        ans=max(ans,tek);
    }
    cout<<ans;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>

#define int long long

#pragma GCC optimize("-O3")

using namespace std;

int a[100005],b[100005],t[400005],sum[100005],kol[100005],l[100005],r[100005];

void build(int v, int tl, int tr)
{

    if(tl==tr)
        t[v]=tl;
    else
    {
        int tm=(tl+tr)/2;
        build(v*2,tl,tm);
        build(v*2+1,tm+1,tr);
        int x=t[v*2],y=t[v*2+1];
        if(x==-1)
            t[v]=y;
        else if(y==-1)
            t[v]=x;
        else if(a[x]<a[y])
            t[v]=x;
        else
            t[v]=y;
    }
    //cout<<v<<" "<<tl<<" "<<tr<<" "<<t[v]<<'\n';
    return;
}

int mini(int v, int tl, int tr, int l, int r)
{
    if(l>r)
        return -1;
    if(l==tl && r==tr)
        return t[v];
    else
    {
        int tm=(tl+tr)/2;
        int x=mini(v*2,tl,tm,l,min(r,tm)),y=mini(v*2+1,tm+1,tr,max(tm+1,l),r);
        if(x==-1)
            return y;
        if(y==-1)
            return x;
        if(a[x]<a[y])
            return x;
        return y;
    }
    return -1;
}

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<400005;i++)
        t[i]=-1;
    for(int i=0;i<n-1;i++)
    {
        cin>>b[i];
        sum[i+1]=sum[i]+b[i];
        kol[i+1]=kol[i]+(b[i]%2==1);
    }
    for(int i=1;i<n;i++)
    {
        a[i]=a[i-1];
        if(b[i-1]%2==0)
            a[i]++;
        else
            a[i]--;
    }
    build(1,0,n-1);
    int pos=0;
    for(int i=0;i<n-1;i++)
    {
        l[i]=pos;
        if(b[i]==1)
            pos=i+1;
    }
    l[n-1]=pos;
    pos=n-1;
    for(int i=n-1;i>0;i--)
    {
        r[i]=pos;
        if(b[i-1]==1)
            pos=i-1;
    }
    r[0]=pos;/*
    for(int i=0;i<n;i++)
        cout<<l[i]<<" ";
    cout<<'\n';
    for(int i=0;i<n;i++)
        cout<<r[i]<<" ";*/
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int l1=l[i];
        int tek=sum[i]-sum[l1]-(kol[i]-kol[l1]);
        int x=mini(1,0,n-1,i,n-1);
        //cout<<i<<" "<<x<<" "<<tek<<" ";
        tek+=sum[x]-sum[i]-(x-i-kol[x]+kol[i]);
        //cout<<tek<<" ";
        int r1=r[x];
        tek+=sum[r1]-sum[x]-(kol[r1]-kol[x]);
        //cout<<tek<<'\n';
        ans=max(ans,tek);
    }
    cout<<ans;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>

#define int long long

#pragma GCC optimize("-O3")

using namespace std;

int a[100005],b[100005],sum[100005],kol[100005],l[100005],r[100005];
vector < int > ind;
vector < int > x;

bool comp(int i,int j)
{
    if(a[i]!=a[j])
        return a[i]>=a[j];
    return i>j;
}

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n=100;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        cin>>b[i];
        sum[i+1]=sum[i]+b[i];
        kol[i+1]=kol[i]+(b[i]%2==1);
    }
    int pos=0;
    for(int i=0;i<n-1;i++)
    {
        l[i]=pos;
        if(b[i]==1)
            pos=i+1;
    }
    l[n-1]=pos;
    pos=n-1;
    for(int i=n-1;i>0;i--)
    {
        r[i]=pos;
        if(b[i-1]==1)
            pos=i-1;
    }
    r[0]=pos;
    for(int i=0;i<n;i++)
        a[i]=sum[i]-(i-kol[i])+sum[r[i]]-sum[i]-(kol[r[i]]-kol[i]);
    for(int i=0;i<n;i++)
        ind.push_back(i);
    sort(ind.begin(),ind.end(),comp);
    x.push_back(ind[0]);
    pos=ind[0];
    for(int i=1;i<n;i++)
    {
        if(ind[i]>pos)
        {
            pos=ind[i];
            x.push_back(ind[i]);
        }
    }
    int ans=0;
    int j=0;
    for(int i=0;i<n;i++)
    {
        int l1=l[i];
        int tek=sum[i]-sum[l1]-(kol[i]-kol[l1]);
        tek+=sum[x[j]]-sum[i]-(x[j]-i-kol[x[j]]+kol[i]);
        int r1=r[x[j]];
        tek+=sum[r1]-sum[x[j]]-(kol[r1]-kol[x[j]]);
        if(i==x[j])
            j++;
        ans=max(ans,tek);
    }
    cout<<ans;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>

#define int long long

#pragma GCC optimize("-O3")

using namespace std;

int a[100005],b[100005],sum[100005],kol[100005],l[100005],r[100005];
vector < int > ind;
vector < int > x;

bool comp(int i,int j)
{
    return a[i]>=a[j];
}

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        cin>>b[i];
        sum[i+1]=sum[i]+b[i];
        kol[i+1]=kol[i]+(b[i]%2==1);
    }
    int pos=0;
    for(int i=0;i<n-1;i++)
    {
        l[i]=pos;
        if(b[i]==1)
            pos=i+1;
    }
    l[n-1]=pos;
    pos=n-1;
    for(int i=n-1;i>0;i--)
    {
        r[i]=pos;
        if(b[i-1]==1)
            pos=i-1;
    }
    r[0]=pos;
    for(int i=0;i<n;i++)
        a[i]=sum[i]-(i-kol[i])+sum[r[i]]-sum[i]-(kol[r[i]]-kol[i]);
    for(int i=0;i<n;i++)
        ind.push_back(i);
    sort(ind.begin(),ind.end(),comp);
    x.push_back(ind[0]);
    pos=ind[0];
    for(int i=1;i<n;i++)
    {
        if(ind[i]>pos)
        {
            pos=ind[i];
            x.push_back(ind[i]);
        }
    }
    int ans=0;
    int j=0;
    for(int i=0;i<n;i++)
    {
        int l1=l[i];
        int tek=sum[i]-sum[l1]-(kol[i]-kol[l1]);
        tek+=sum[x[j]]-sum[i]-(x[j]-i-kol[x[j]]+kol[i]);
        int r1=r[x[j]];
        tek+=sum[r1]-sum[x[j]]-(kol[r1]-kol[x[j]]);
        if(i==x[j])
            j++;
        ans=max(ans,tek);
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll int
#define ld long double

#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>

#define infi INT_MAX
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)
#define F first
#define S second
#define G(a,b) get<a>(b)
#define MP make_pair
#define MT make_tuple
#define pll pair<ll,ll>
#define endl "\n"
#define ALL(v) v.begin(),v.end()
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define deb printf("***************************************************************************************\n");
#define moshi printf("moshi moshi ! \n");
#define hi printf("hi ! \n");
#define bye printf("bye bye ! \n");
#define o_set(ll) tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define number_of_set_bits  __builtin_popcountll
const ld PI=3.1415926535897932384626433;

//template<typename T>
//#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

//const ll N=1e6+7;
ll p=1e9+7;
//ll fac[N];

ll gcd(ll a, ll b)
{
   if (a == 0) return b;
   return gcd(b % a, a);
}

ll lcm(ll a,ll b)
{
    ll g=gcd(a,b);
    ll res=(a/g)*b;
    return res;
}

inline ll ceil(ll a,ll b)
{
   return (a+b-1)/b;
}

ll max(ll x,ll y,ll z)
{
   return max(x,max(y,z));
}

ll min(ll x,ll y,ll z)
{
   return min(x,min(y,z));
}

ll modpro(ll x,ll y,ll z=1)
{
   x%=p;
   y%=p;
   z%=p;
   ll res=(x*y)%p;
   res=(res*z)%p;
   return res;
}

ll modadd(ll x,ll y,ll z=0)
{
   x%=p;
   y%=p;
   z%=p;
   ll res=(x+y)%p;
   res=(res+z)%p;
   return res;
}

ll pow_mod_p(ll a,ll b)
{
   a=a%p;
   ll res=1;
   while(b>0)
   {
     if(b&1) res=(res*a)%p;
     b=b>>1;
     a=(a*a)%p;
   }
   return res;
}

inline ll mod_inv(ll x)
{
   return pow_mod_p(x,p-2);
}

// Don't forget to set fac[0]=1
/*ll nCr(ll x,ll y)
{
   if(x<y) return 0;
   ll res=fac[x];
   ll den=(fac[y]*fac[x-y])%p;
   ll deni=mod_inv(den);
   res=(res*deni)%p;
   return res;
}*/

ll is_set(ll a,ll i)
{
   if( ( a & ((ll)1<<i) ) == 0 ) return 0;
   else return 1;
}

//  Comparator should follow :
//  1: x<=y or y<=x uniquely
//  2: Transitivity : a<=b and b<=c implies a<=c
//  3: Anti-Symmetry: a<=b and b<=a implies a=b
// return 1 to put x before y in sorted order
inline bool comp(pll &x,pll &y)
{
   if(x.F<y.F) return 1;
   else if(x.F==y.F)
   {
      if(x.S>y.S) return 1;
      else return 0;
   }
   return 0;
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

// resize : str.resize(new_size)   new size <= old size

// for Vector :
// lower_bound(starting iterator , iterator next to end , value)  :  iterator to first element greater than or equal to value
// upper_bound(starting iterator , iterator next to end , value)  :  iterator to first element strictly greater than value

// For Set :      s.lower_bound(value)
// if no such element exists they return  vector.end() or s.end()

// x bits : [x-1 , x-2 , .... , 1(1st bit) , 0(0th bit)] =>   leftmost 1 at 2^(x-1)    max number that can be represented : 2^(x) -1
// 63 bits is greater than 10^18

// 1<<x  :  2 ^ x  (left shift)

// Min heap :  priority_queue < ll , vector<ll>, greater<ll> > q
// Max heap :  priority_queue < ll > q
    // Set in descending order  :   set< ll,greater <ll> >

// While debugging :
// 1 : check if array size is correct  :  It may give unexpected results
// 2 : check if you have swapped i and j at some part of program
// 3 : for string check if you are trying to acces  index = -1

// Bitwise Tricks :
// 1 : While using 1<<i  use (ll)1<<i  because in former one "1" is considered as int
// 2 : To flip first k-bits of a number :  x xor (2^k-1)  or x ^ (((ll)1<<k)-1)  : 2^k-1 is the largest number of k bits
// 3 : To flip k-th bit (0-based)  :  x xor (2^k)  or  x ^ ((ll)1<<k)
// 4 : To set k-th bit (0-based)   :  x or (2^k)   or  x | ((ll)1<<k)
// 5 : To un-set k-th bit (0-based)   :  x & (~ ((ll)1<<k) )

// To prove Greedy :
// 1 : Optimal Choice at each step
// 2 : Exchange Argument
// 3 : Find a lower or upper bound on answer and then construct an answer for that bound
// 4 : Find properties which Optimal Solution must satisfy ( This can be useful to deduce form of Optimal answer)

// Erase one occurrence in multiset : it=s.find(element)   s.erase(it)
// putchar('a'+j) : to print (j+1)th character
// getline(cin,str) : To input string until newline

void lps(string &pp,ll *lps)
{
   ll xx=pp.length();
   //ll lps[xx]={};
   f(i,1,xx)
   {
       ll j=lps[i-1];
       while(j>0 && pp[j]!=pp[i]) j=lps[j-1];
       if(pp[i]==pp[j]) j++;
       lps[i]=j;
   }
}

// Remember to take input string as  getline(cin,s)
void stoi(string &s,vll &v)
{
   stringstream str(s);
   ll x;
   while(str>>x)
   {
       v.pb(x);
   }
}

void Miden(ll **p1,ll n)
{
    ll (*x)[n]=(ll(*)[n]) p1;
    f(i,0,n)
    {
        f(j,0,n)
        {
            x[i][j]=0;
        }
        x[i][i]=1;
    }
    return;
}

void Mmult(ll **p1,ll **p2,ll **ans,ll x,ll y,ll z,ll m)
{
    ll (*a)[y]=(ll (*)[y])p1;
    ll (*b)[z]=(ll (*)[z])p2;
    ll (*c)[z]=(ll (*)[z])ans;
    f(i,0,x)
    {
        f(j,0,z)
        {
            c[i][j]=0;
            f(k,0,y)
            {
                c[i][j]+=a[i][k]*b[k][j];
                c[i][j]%=m;
            }
        }
    }
    return;
}

void Mpow(ll **p1,ll **ans,ll n,ll y,ll m)
{
    if(y==0)
    {
        Miden(ans,n);
        return;
    }
    ll t[n][n];
    Mpow(p1,(ll **)t,n,y/2,m);
    ll z[n][n];
    Mmult((ll **)t,(ll **)t,(ll **)z,n,n,n,m);
    if(y%2)
    {
        Mmult((ll **)z,p1,ans,n,n,n,m);
    }
    else
    {
        Miden((ll **)t,n);
        Mmult((ll **)z,(ll **)t,ans,n,n,n,m);
    }
    return;
}

const ll N=1e5+5;
ll lef[N],rig[N],pre1[N],pre2[N],pos1[N],pos2[N],n;

void func()
{
  cin>>n;
  f(i,1,n)
  {
    ll x;
    cin>>x;
    rig[i]=x;
    lef[i+1]=x;
  }

  f(i,1,n+1)
  {
    if(lef[i]<2) pre1[i]=0;  // can't go left
    else
    {
        ll t=lef[i]%2;
        pre1[i]=pre1[i-1]+lef[i]-t;
    }

    if(lef[i]==0) pre2[i]=0;
    else if(lef[i]%2!=0) pre2[i]=lef[i]+pre2[i-1];
    else pre2[i]=max(lef[i]-1+pre2[i-1],lef[i]+pre1[i-1]);
  }

  fi(i,1,n+1)
  {
    if(rig[i]<2) pos1[i]=0;  // can't gp right
    else
    {
        ll t=rig[i]%2;
        pos1[i]=pos1[i+1]+rig[i]-t;
    }

    if(rig[i]==0) pos2[i]=0;
    else if(rig[i]%2!=0) pos2[i]=rig[i]+pos2[i+1];
    else pos2[i]=max(rig[i]-1+pos2[i+1],rig[i]+pos1[i+1]);
  }

  ll ans=0;
  f(i,1,n+1) ans=max(ans,pre1[i]+pos2[i],pre2[i]+pos1[i]);

  pr(ans) nl
}

int main()
{
    fast

    ll ntc=1;
    //cin>>ntc;

    f(i,1,ntc+1)
    {
      //cout<<"Case #"<<i<<": ";
      func();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll int
#define ld long double

#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>

#define infi INT_MAX
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)
#define F first
#define S second
#define G(a,b) get<a>(b)
#define MP make_pair
#define MT make_tuple
#define pll pair<ll,ll>
#define endl "\n"
#define ALL(v) v.begin(),v.end()
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define deb printf("***************************************************************************************\n");
#define moshi printf("moshi moshi ! \n");
#define hi printf("hi ! \n");
#define bye printf("bye bye ! \n");
#define o_set(ll) tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define number_of_set_bits  __builtin_popcountll
const ld PI=3.1415926535897932384626433;

//template<typename T>
//#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

//const ll N=1e6+7;
ll p=1e9+7;
//ll fac[N];

ll gcd(ll a, ll b)
{
   if (a == 0) return b;
   return gcd(b % a, a);
}

ll lcm(ll a,ll b)
{
    ll g=gcd(a,b);
    ll res=(a/g)*b;
    return res;
}

inline ll ceil(ll a,ll b)
{
   return (a+b-1)/b;
}

ll max(ll x,ll y,ll z)
{
   return max(x,max(y,z));
}

ll min(ll x,ll y,ll z)
{
   return min(x,min(y,z));
}

ll modpro(ll x,ll y,ll z=1)
{
   x%=p;
   y%=p;
   z%=p;
   ll res=(x*y)%p;
   res=(res*z)%p;
   return res;
}

ll modadd(ll x,ll y,ll z=0)
{
   x%=p;
   y%=p;
   z%=p;
   ll res=(x+y)%p;
   res=(res+z)%p;
   return res;
}

ll pow_mod_p(ll a,ll b)
{
   a=a%p;
   ll res=1;
   while(b>0)
   {
     if(b&1) res=(res*a)%p;
     b=b>>1;
     a=(a*a)%p;
   }
   return res;
}

inline ll mod_inv(ll x)
{
   return pow_mod_p(x,p-2);
}

// Don't forget to set fac[0]=1
/*ll nCr(ll x,ll y)
{
   if(x<y) return 0;
   ll res=fac[x];
   ll den=(fac[y]*fac[x-y])%p;
   ll deni=mod_inv(den);
   res=(res*deni)%p;
   return res;
}*/

ll is_set(ll a,ll i)
{
   if( ( a & ((ll)1<<i) ) == 0 ) return 0;
   else return 1;
}

//  Comparator should follow :
//  1: x<=y or y<=x uniquely
//  2: Transitivity : a<=b and b<=c implies a<=c
//  3: Anti-Symmetry: a<=b and b<=a implies a=b
// return 1 to put x before y in sorted order
inline bool comp(pll &x,pll &y)
{
   if(x.F<y.F) return 1;
   else if(x.F==y.F)
   {
      if(x.S>y.S) return 1;
      else return 0;
   }
   return 0;
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

// resize : str.resize(new_size)   new size <= old size

// for Vector :
// lower_bound(starting iterator , iterator next to end , value)  :  iterator to first element greater than or equal to value
// upper_bound(starting iterator , iterator next to end , value)  :  iterator to first element strictly greater than value

// For Set :      s.lower_bound(value)
// if no such element exists they return  vector.end() or s.end()

// x bits : [x-1 , x-2 , .... , 1(1st bit) , 0(0th bit)] =>   leftmost 1 at 2^(x-1)    max number that can be represented : 2^(x) -1
// 63 bits is greater than 10^18

// 1<<x  :  2 ^ x  (left shift)

// Min heap :  priority_queue < ll , vector<ll>, greater<ll> > q
// Max heap :  priority_queue < ll > q
    // Set in descending order  :   set< ll,greater <ll> >

// While debugging :
// 1 : check if array size is correct  :  It may give unexpected results
// 2 : check if you have swapped i and j at some part of program
// 3 : for string check if you are trying to acces  index = -1

// Bitwise Tricks :
// 1 : While using 1<<i  use (ll)1<<i  because in former one "1" is considered as int
// 2 : To flip first k-bits of a number :  x xor (2^k-1)  or x ^ (((ll)1<<k)-1)  : 2^k-1 is the largest number of k bits
// 3 : To flip k-th bit (0-based)  :  x xor (2^k)  or  x ^ ((ll)1<<k)
// 4 : To set k-th bit (0-based)   :  x or (2^k)   or  x | ((ll)1<<k)
// 5 : To un-set k-th bit (0-based)   :  x & (~ ((ll)1<<k) )

// To prove Greedy :
// 1 : Optimal Choice at each step
// 2 : Exchange Argument
// 3 : Find a lower or upper bound on answer and then construct an answer for that bound
// 4 : Find properties which Optimal Solution must satisfy ( This can be useful to deduce form of Optimal answer)

// Erase one occurrence in multiset : it=s.find(element)   s.erase(it)
// putchar('a'+j) : to print (j+1)th character
// getline(cin,str) : To input string until newline

void lps(string &pp,ll *lps)
{
   ll xx=pp.length();
   //ll lps[xx]={};
   f(i,1,xx)
   {
       ll j=lps[i-1];
       while(j>0 && pp[j]!=pp[i]) j=lps[j-1];
       if(pp[i]==pp[j]) j++;
       lps[i]=j;
   }
}

// Remember to take input string as  getline(cin,s)
void stoi(string &s,vll &v)
{
   stringstream str(s);
   ll x;
   while(str>>x)
   {
       v.pb(x);
   }
}

void Miden(ll **p1,ll n)
{
    ll (*x)[n]=(ll(*)[n]) p1;
    f(i,0,n)
    {
        f(j,0,n)
        {
            x[i][j]=0;
        }
        x[i][i]=1;
    }
    return;
}

void Mmult(ll **p1,ll **p2,ll **ans,ll x,ll y,ll z,ll m)
{
    ll (*a)[y]=(ll (*)[y])p1;
    ll (*b)[z]=(ll (*)[z])p2;
    ll (*c)[z]=(ll (*)[z])ans;
    f(i,0,x)
    {
        f(j,0,z)
        {
            c[i][j]=0;
            f(k,0,y)
            {
                c[i][j]+=a[i][k]*b[k][j];
                c[i][j]%=m;
            }
        }
    }
    return;
}

void Mpow(ll **p1,ll **ans,ll n,ll y,ll m)
{
    if(y==0)
    {
        Miden(ans,n);
        return;
    }
    ll t[n][n];
    Mpow(p1,(ll **)t,n,y/2,m);
    ll z[n][n];
    Mmult((ll **)t,(ll **)t,(ll **)z,n,n,n,m);
    if(y%2)
    {
        Mmult((ll **)z,p1,ans,n,n,n,m);
    }
    else
    {
        Miden((ll **)t,n);
        Mmult((ll **)z,(ll **)t,ans,n,n,n,m);
    }
    return;
}

void func()
{
  ll n;
  cin>>n;
  ll deg[n+1]={};
  ll ans=0;
  f(i,1,n)
  {
    ll x;
    cin>>x;
    ans+=x;
    deg[i]+=x;
    deg[i+1]+=x;
  }

  ll cnt=0;
  f(i,1,n+1) if(deg[i]%2!=0) cnt++;

  if(cnt!=0)
  {
    ans-=((cnt-2)/2);
  }

  pr(ans) nl
}

int main()
{
    fast

    ll ntc=1;
    //cin>>ntc;

    f(i,1,ntc+1)
    {
      //cout<<"Case #"<<i<<": ";
      func();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
#define ld long double

#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>

#define infi INT_MAX
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)
#define F first
#define S second
#define G(a,b) get<a>(b)
#define MP make_pair
#define MT make_tuple
#define pll pair<ll,ll>
#define endl "\n"
#define ALL(v) v.begin(),v.end()
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define deb printf("***************************************************************************************\n");
#define moshi printf("moshi moshi ! \n");
#define hi printf("hi ! \n");
#define bye printf("bye bye ! \n");
#define o_set(ll) tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define number_of_set_bits  __builtin_popcountll
const ld PI=3.1415926535897932384626433;

//template<typename T>
//#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

//const ll N=1e6+7;
ll p=1e9+7;
//ll fac[N];

ll gcd(ll a, ll b)
{
   if (a == 0) return b;
   return gcd(b % a, a);
}

ll lcm(ll a,ll b)
{
    ll g=gcd(a,b);
    ll res=(a/g)*b;
    return res;
}

inline ll ceil(ll a,ll b)
{
   return (a+b-1)/b;
}

ll max(ll x,ll y,ll z)
{
   return max(x,max(y,z));
}

ll min(ll x,ll y,ll z)
{
   return min(x,min(y,z));
}

ll modpro(ll x,ll y,ll z=1)
{
   x%=p;
   y%=p;
   z%=p;
   ll res=(x*y)%p;
   res=(res*z)%p;
   return res;
}

ll modadd(ll x,ll y,ll z=0)
{
   x%=p;
   y%=p;
   z%=p;
   ll res=(x+y)%p;
   res=(res+z)%p;
   return res;
}

ll pow_mod_p(ll a,ll b)
{
   a=a%p;
   ll res=1;
   while(b>0)
   {
     if(b&1) res=(res*a)%p;
     b=b>>1;
     a=(a*a)%p;
   }
   return res;
}

inline ll mod_inv(ll x)
{
   return pow_mod_p(x,p-2);
}

// Don't forget to set fac[0]=1
/*ll nCr(ll x,ll y)
{
   if(x<y) return 0;
   ll res=fac[x];
   ll den=(fac[y]*fac[x-y])%p;
   ll deni=mod_inv(den);
   res=(res*deni)%p;
   return res;
}*/

ll is_set(ll a,ll i)
{
   if( ( a & ((ll)1<<i) ) == 0 ) return 0;
   else return 1;
}

//  Comparator should follow :
//  1: x<=y or y<=x uniquely
//  2: Transitivity : a<=b and b<=c implies a<=c
//  3: Anti-Symmetry: a<=b and b<=a implies a=b
// return 1 to put x before y in sorted order
inline bool comp(pll &x,pll &y)
{
   if(x.F<y.F) return 1;
   else if(x.F==y.F)
   {
      if(x.S>y.S) return 1;
      else return 0;
   }
   return 0;
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

// resize : str.resize(new_size)   new size <= old size

// for Vector :
// lower_bound(starting iterator , iterator next to end , value)  :  iterator to first element greater than or equal to value
// upper_bound(starting iterator , iterator next to end , value)  :  iterator to first element strictly greater than value

// For Set :      s.lower_bound(value)
// if no such element exists they return  vector.end() or s.end()

// x bits : [x-1 , x-2 , .... , 1(1st bit) , 0(0th bit)] =>   leftmost 1 at 2^(x-1)    max number that can be represented : 2^(x) -1
// 63 bits is greater than 10^18

// 1<<x  :  2 ^ x  (left shift)

// Min heap :  priority_queue < ll , vector<ll>, greater<ll> > q
// Max heap :  priority_queue < ll > q
    // Set in descending order  :   set< ll,greater <ll> >

// While debugging :
// 1 : check if array size is correct  :  It may give unexpected results
// 2 : check if you have swapped i and j at some part of program
// 3 : for string check if you are trying to acces  index = -1

// Bitwise Tricks :
// 1 : While using 1<<i  use (ll)1<<i  because in former one "1" is considered as int
// 2 : To flip first k-bits of a number :  x xor (2^k-1)  or x ^ (((ll)1<<k)-1)  : 2^k-1 is the largest number of k bits
// 3 : To flip k-th bit (0-based)  :  x xor (2^k)  or  x ^ ((ll)1<<k)
// 4 : To set k-th bit (0-based)   :  x or (2^k)   or  x | ((ll)1<<k)
// 5 : To un-set k-th bit (0-based)   :  x & (~ ((ll)1<<k) )

// To prove Greedy :
// 1 : Optimal Choice at each step
// 2 : Exchange Argument
// 3 : Find a lower or upper bound on answer and then construct an answer for that bound
// 4 : Find properties which Optimal Solution must satisfy ( This can be useful to deduce form of Optimal answer)

// Erase one occurrence in multiset : it=s.find(element)   s.erase(it)
// putchar('a'+j) : to print (j+1)th character
// getline(cin,str) : To input string until newline

void lps(string &pp,ll *lps)
{
   ll xx=pp.length();
   //ll lps[xx]={};
   f(i,1,xx)
   {
       ll j=lps[i-1];
       while(j>0 && pp[j]!=pp[i]) j=lps[j-1];
       if(pp[i]==pp[j]) j++;
       lps[i]=j;
   }
}

// Remember to take input string as  getline(cin,s)
void stoi(string &s,vll &v)
{
   stringstream str(s);
   ll x;
   while(str>>x)
   {
       v.pb(x);
   }
}

void Miden(ll **p1,ll n)
{
    ll (*x)[n]=(ll(*)[n]) p1;
    f(i,0,n)
    {
        f(j,0,n)
        {
            x[i][j]=0;
        }
        x[i][i]=1;
    }
    return;
}

void Mmult(ll **p1,ll **p2,ll **ans,ll x,ll y,ll z,ll m)
{
    ll (*a)[y]=(ll (*)[y])p1;
    ll (*b)[z]=(ll (*)[z])p2;
    ll (*c)[z]=(ll (*)[z])ans;
    f(i,0,x)
    {
        f(j,0,z)
        {
            c[i][j]=0;
            f(k,0,y)
            {
                c[i][j]+=a[i][k]*b[k][j];
                c[i][j]%=m;
            }
        }
    }
    return;
}

void Mpow(ll **p1,ll **ans,ll n,ll y,ll m)
{
    if(y==0)
    {
        Miden(ans,n);
        return;
    }
    ll t[n][n];
    Mpow(p1,(ll **)t,n,y/2,m);
    ll z[n][n];
    Mmult((ll **)t,(ll **)t,(ll **)z,n,n,n,m);
    if(y%2)
    {
        Mmult((ll **)z,p1,ans,n,n,n,m);
    }
    else
    {
        Miden((ll **)t,n);
        Mmult((ll **)z,(ll **)t,ans,n,n,n,m);
    }
    return;
}

const ll N=1e5+5;
ll lef[N],rig[N],pre1[N],pre2[N],pos1[N],pos2[N],n;

void func()
{
  cin>>n;
  f(i,1,n)
  {
    ll x;
    cin>>x;
    rig[i]=x;
    lef[i+1]=x;
  }

  f(i,1,n+1)
  {
    if(lef[i]<2) pre1[i]=0;  // can't go left
    else
    {
        ll t=lef[i]%2;
        pre1[i]=pre1[i-1]+lef[i]-t;
    }

    if(lef[i]==0) pre2[i]=0;
    else if(lef[i]%2!=0) pre2[i]=lef[i]+pre2[i-1];
    else pre2[i]=max(lef[i]-1+pre2[i-1],lef[i]+pre1[i-1]);
  }

  fi(i,1,n+1)
  {
    if(rig[i]<2) pos1[i]=0;  // can't gp right
    else
    {
        ll t=rig[i]%2;
        pos1[i]=pos1[i+1]+rig[i]-t;
    }

    if(rig[i]==0) pos2[i]=0;
    else if(rig[i]%2!=0) pos2[i]=rig[i]+pos2[i+1];
    else pos2[i]=max(rig[i]-1+pos2[i+1],rig[i]+pos1[i+1]);
  }

  ll ans=0;
  f(i,1,n+1) ans=max(ans,pre1[i]+pos2[i],pre2[i]+pos1[i]);

  pr(ans) nl
}

int main()
{
    fast

    ll ntc=1;
    //cin>>ntc;

    f(i,1,ntc+1)
    {
      //cout<<"Case #"<<i<<": ";
      func();
    }
    return 0;
}


#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define pb push_back
#define MOD 1000000007
#define INF 1000000009
const ll INFll=1ll*INF*INF;
#define mp make_pair
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(v) v.begin(),v.end()
#define f first
#define s second
#define vi vector<int>
#define vl vector<ll>
#define llll pair<ll,ll>
#define vll vector<llll >
#define vvl vector<vector<ll> >
#define vvi vector<vi>
#define ii pair<int,int>
#define vii vector<ii>
#define vvii vector<vector<ii>>
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << ' '; cout << endl;
#define printii(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << it->first<<' '<<it->second << endl; cout << endl;
#define debug(x) cout << x << endl;
#define LC(i) 2*(i)+1
#define RC(i) 2*(i)+2
#define MID(i,j) ((i)+(j))/2
#define disparr(arr,n) for(int i=0;i<(n);i++)   cout<<arr[i]<<' ';  cout<<endl;
#define vd vector<double>
#define ld long double
#include <bits/stdc++.h>
#define iii pair<int,ii>
ll lf[2][10005],rg[2][10005];
ll a[10005];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++)
        cin>>a[i];
    lf[0][0]=lf[1][0]=0;
    rg[0][n-1]=rg[1][n-1]=0;
    for(int i=1;i<n;i++)
    {
        ll x=a[i-1];
        if(x%2)
        {
            lf[0][i]=max(x+lf[0][i-1],x-1+lf[1][i-1]);
        }
        else
        {
            lf[0][i]=max(x-1+lf[0][i-1],x+lf[1][i-1]);
        }
        x=a[i-1];
        if(x==1)    continue;
        if(x%2)    x--;
        lf[1][i]=x+lf[1][i-1];
    }
    for(int i=n-2;i>=0;i--)
    {
        ll x=a[i];
        if(x%2)
        {
            rg[0][i]=max(x+rg[0][i+1],x-1+rg[1][i+1]);
        }
        else
        {
            rg[0][i]=max(x-1+rg[0][i+1],x+rg[1][i+1]);
        }
        x=a[i];
        if(x==1)    continue;
        if(x%2) x--;
        rg[1][i]=x+rg[1][i+1];
    }
    ll ans=0;
    for(int i=0;i<n-1;i++)
    {
        ans=max(ans,a[i]+lf[0][i]+rg[1][i+1]);
        ans=max(ans,a[i]+lf[1][i]+rg[0][i+1]);
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define pb push_back
#define MOD 1000000007
#define INF 1000000009
const ll INFll=1ll*INF*INF;
#define mp make_pair
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(v) v.begin(),v.end()
#define f first
#define s second
#define vi vector<int>
#define vl vector<ll>
#define llll pair<ll,ll>
#define vll vector<llll >
#define vvl vector<vector<ll> >
#define vvi vector<vi>
#define ii pair<int,int>
#define vii vector<ii>
#define vvii vector<vector<ii>>
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << ' '; cout << endl;
#define printii(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << it->first<<' '<<it->second << endl; cout << endl;
#define debug(x) cout << x << endl;
#define LC(i) 2*(i)+1
#define RC(i) 2*(i)+2
#define MID(i,j) ((i)+(j))/2
#define disparr(arr,n) for(int i=0;i<(n);i++)   cout<<arr[i]<<' ';  cout<<endl;
#define vd vector<double>
#define ld long double
#include <bits/stdc++.h>
#define iii pair<int,ii>
ll lf[2][10005],rg[2][10005];
ll a[10005];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++)
        cin>>a[i];
    lf[0][0]=lf[1][0]=0;
    rg[0][n-1]=rg[1][n-1]=0;
    for(int i=1;i<n;i++)
    {
        ll x=a[i-1];
        if(x%2==0) x--;
        lf[0][i]=max(a[i-1],x+lf[0][i-1]);
        x=a[i-1];
        if(x==1)    continue;
        if(x%2)    x--;
        lf[1][i]=x+lf[1][i-1];
    }
    for(int i=n-2;i>=0;i--)
    {
        ll x=a[i];
        if(x%2==0) x--;
        rg[0][i]=max(a[i],x+rg[0][i+1]);
        x=a[i];
        if(x==1)    continue;
        if(x%2) x--;
        rg[1][i]=x+rg[1][i+1];
    }
    ll ans=0;
    for(int i=0;i<n-1;i++)
    {
        ans=max(ans,a[i]+lf[0][i]+rg[1][i+1]);
        ans=max(ans,a[i]+lf[1][i]+rg[0][i+1]);
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define pb push_back
#define MOD 1000000007
#define INF 1000000009
const ll INFll=1ll*INF*INF;
#define mp make_pair
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(v) v.begin(),v.end()
#define f first
#define s second
#define vi vector<int>
#define vl vector<ll>
#define llll pair<ll,ll>
#define vll vector<llll >
#define vvl vector<vector<ll> >
#define vvi vector<vi>
#define ii pair<int,int>
#define vii vector<ii>
#define vvii vector<vector<ii>>
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << ' '; cout << endl;
#define printii(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << it->first<<' '<<it->second << endl; cout << endl;
#define debug(x) cout << x << endl;
#define LC(i) 2*(i)+1
#define RC(i) 2*(i)+2
#define MID(i,j) ((i)+(j))/2
#define disparr(arr,n) for(int i=0;i<(n);i++)   cout<<arr[i]<<' ';  cout<<endl;
#define vd vector<double>
#define ld long double
#include <bits/stdc++.h>
#define iii pair<int,ii>
ll lf[2][100005],rg[2][100005];
ll a[100005];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++)
        cin>>a[i];
    lf[0][0]=lf[1][0]=0;
    rg[0][n-1]=rg[1][n-1]=0;
    for(int i=1;i<n;i++)
    {
        ll x=a[i-1];
        if(x%2)
        {
            lf[0][i]=max(x+lf[0][i-1],x-1+lf[1][i-1]);
        }
        else
        {
            lf[0][i]=max(x-1+lf[0][i-1],x+lf[1][i-1]);
        }
        x=a[i-1];
        if(x==1)    continue;
        if(x%2)    x--;
        lf[1][i]=x+lf[1][i-1];
    }
    for(int i=n-2;i>=0;i--)
    {
        ll x=a[i];
        if(x%2)
        {
            rg[0][i]=max(x+rg[0][i+1],x-1+rg[1][i+1]);
        }
        else
        {
            rg[0][i]=max(x-1+rg[0][i+1],x+rg[1][i+1]);
        }
        x=a[i];
        if(x==1)    continue;
        if(x%2) x--;
        rg[1][i]=x+rg[1][i+1];
    }
    ll ans=0;
    for(int i=0;i<n-1;i++)
    {
        ans=max(ans,a[i]+lf[0][i]+rg[1][i+1]);
        ans=max(ans,a[i]+lf[1][i]+rg[0][i+1]);
    }
    cout<<ans<<endl;
}


/* -*- coding: utf-8 -*-
 *
 * 0201C.cc: C. Fragile Bridges
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

inline void setmax(ll &a, ll b) { if (a < b) a = b; }

/* main */

int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

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

  ll maxdp = 0;
  ll dp0 = 0, dp1 = 0, dp2 = 0;
  for (int i = 0; i + 1 < n; i++) {
    int ai;
    scanf("%d", &ai);
    int eai, oai;
    if (ai & 1) oai = ai, eai = ai - 1;
    else eai = ai, oai = ai - 1;

    ll ndp0 = (eai > 0) ? dp0 + eai : 0;
    ll ndp1 = max(dp0, dp1) + oai;
    ll ndp2 = (eai > 0) ? max(dp0, max(dp1, dp2)) + eai : 0;
    dp0 = ndp0, dp1 = ndp1, dp2 = ndp2;
    //printf("%d: %lld, %lld, %lld\n", i + 1, dp0, dp1, dp2);

    setmax(maxdp, dp0);
    setmax(maxdp, dp1);
    setmax(maxdp, dp2);
  }

  printf("%lld\n", maxdp);
  return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef long double ld;
/*typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;*/

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define sz(x)                       (int)(x.size())
#define debug(x)                    cerr << #x << ": " <<  x << endl;
#define bug(x)                      cerr << #x << ": " <<  x <<  " ";
#define alog(a, n)                  for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
#define FOR(n)                      for (int i = 0; i < n; i++)
#define fast_io                     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

ll poww(ll a, ll b, ll md) {
    if (b == -1) return poww(a, md - 2, md);
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll N = 1e6 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll plat[N];
ll left[N], right[N], oddsum[N], mxleft[N];
int n;

int main(){
    //fast_io
    scanf("%d", &n);
    plat[1] = 0;
    for(int i = 2; i <= n; i++){
        scanf("%lld", plat + i);
        oddsum[i] = oddsum[i - 1] + (plat[i] & 1 ? plat[i] : plat[i] - 1);
        if(plat[i] == 1)
            {left[i] = 0; continue;}

        left[i] = left[i - 1] + (plat[i] & 1 ? plat[i] - 1 : plat[i]);
    }

    for(int i = n; i; --i){
        if(i == n)
            continue;
        if(plat[i + 1] == 1)
            continue;
        right[i] = right[i + 1] + (plat[i + 1] & 1 ? plat[i + 1] - 1 : plat[i + 1]);
    }

    ll ans = -INF;

    for(int i = 1; i <= n; i++){
        mxleft[i] = max(mxleft[i - 1], left[i] - oddsum[i]);

        ans = max(ans, right[i] + oddsum[i] + mxleft[i]);

    }

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

    return 0;

}


#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef long double ld;
/*typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;*/

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define sz(x)                       (int)(x.size())
#define debug(x)                    cerr << #x << ": " <<  x << endl;
#define bug(x)                      cerr << #x << ": " <<  x <<  " ";
#define alog(a, n)                  for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
#define FOR(n)                      for (int i = 0; i < n; i++)
#define fast_io                     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

ll poww(ll a, ll b, ll md) {
    if (b == -1) return poww(a, md - 2, md);
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll N = 1e6 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll plat[N];
ll left[N], right[N], oddsum[N];
int n;

int main(){
    //fast_io
    scanf("%d", &n);
    plat[1] = 0;
    for(int i = 2; i <= n; i++){
        scanf("%lld", plat + i);
        oddsum[i] = oddsum[i - 1] + (plat[i] & 1 ? plat[i] : plat[i] - 1);
        if(plat[i] == 1)
            {left[i] = 0; continue;}

        left[i] = left[i - 1] + (plat[i] & 1 ? plat[i] - 1 : plat[i]);
    }

    for(int i = n; i; --i){
        if(i == n)
            continue;
        if(plat[i + 1] == 1)
            continue;
        right[i] = right[i + 1] + (plat[i + 1] & 1 ? plat[i + 1] - 1 : plat[i + 1]);
    }

    ll ans = -INF, mxleft = -INF;

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

        for(int j = 1; j <= i; j++){
            if(left[j] - oddsum[j] > mxleft)
                mxleft = left[j] - oddsum[j];
            ans = max(ans, right[i] + oddsum[i] + mxleft);
        }

        mxleft = -INF;
    }

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

    return 0;

}


#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3")

#include<bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()

inline void opting(){
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
}

int inp(){
    int x;
    cin >> x;
    return x;
}

struct unit{
    int h;
    int l;
    int r;
    int depth;
};

const int maxn = 1e5 + 69;
long long a[maxn], lft[maxn][2], rgt[maxn][2];

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

	lft[1][0] = lft[1][1] = 0;
	for (int i = 2; i <= n; i++) {
		long long x = a[i - 1];
		lft[i][0] = max(x + lft[i - 1][1], x - (1 - (x & 1)) + lft[i - 1][0]);
		if (x - 1)
		lft[i][1] = x - (x & 1) + lft[i - 1][1];
	}
	rgt[n][0] = rgt[n][1] = 0;
	for (int i = n - 1; i; i--) {
		long long x = a[i];
		rgt[i][0] = max(x + rgt[i + 1][1], x - (1 - (x & 1) )+ rgt[i + 1][0]);
		if (x - 1)
		rgt[i][1] = x - (x & 1) + rgt[i + 1][1];
	}

	long long ans = 0;
	for (int i = 1; i <= n; i++)
		ans = max(ans, max(rgt[i][1] + lft[i][0], rgt[i][0] + lft[i][1]));
	cout << ans << '\n';
}


#include <bits/stdc++.h>
using namespace std;
#define int int64_t
int32_t main(){
    int n;
    cin >> n;
    vector < int > a(n + 10, 0), lp(n + 10, 0), rp(n + 10, 0);
    for (int i = 1; i < n; i++){
        cin >> a[i];
    }
    for (int i = 2; i <= n; i++){
        if (a[i - 1] != 1){
            lp[i] = lp[i - 1] + (a[i - 1] / 2) * 2;
        }
    }
    for (int i = n - 1; i >= 1; i--){
        if (a[i] != 1){
            rp[i] = rp[i + 1] + (a[i] / 2) * 2;
           // cout << rp[i] << endl;
        }
    }
    int maxl = 0, maxr = 0, ans = 0;
    for (int i = n; i >= 1; i--){
    //    cout << lp[i] << ' ' << rp[i] << endl;
  //      cout << maxr << endl;
        maxr = max(rp[i], maxr);
        int tek = maxr + lp[i];
        if (tek > ans){
            ans = tek;
        }
        maxr += (a[i - 1] - 1) / 2 * 2;
        maxr++;
    }
    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int n;
ll a[100005], levo[100005];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

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

	ll vr = 0, par = 0;
	for (int i=1; i<=n; i++) {
		// prosiri za neparan broj
		ll t = vr + (a[i] % 2 ? a[i] : a[i]-1);
		par = a[i] == 1 ? 0 : (par + (a[i] % 2 ? a[i] - 1 : a[i]));
		vr = levo[i] = max(t, par);
	}

	// for (int i=0; i<=n; i++)
	// 	cerr << levo[i] << ' ';
	// cerr << '\n';

	ll sol = 0;

	par = 0;
	for (int i=n; i>=0; i--) {
		sol = max(sol, par + levo[i]);
		par = a[i] == 1 ? 0 : (par + (a[i] % 2 ? a[i] - 1 : a[i]));
	}

	cout << sol << '\n';
}


//#pragma comment(linker,"/STACK:16777216") /*16Mb*/
//#pragma comment(linker,"/STACK:33554432") /*32Mb*/
#define _CRT_SECURE_NO_DEPRECATE
#include<sstream>
#include<iostream>
#include<numeric>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<memory>
#include<string>
#include<vector>
#include<cctype>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
using namespace std;

typedef unsigned long long      ui64;
typedef long long               i64;
typedef vector<i64>             VI;
typedef vector<bool>            VB;
typedef vector<VI>              VVI;
typedef vector<string>          VS;
typedef pair<int,int>           PII;
typedef map<string,int>         MSI;
typedef set<int>                SI;
typedef set<string>             SS;
typedef map<int,int>            MII;
typedef pair<double,double>     PDD;

#define PB                      push_back
#define MP                      make_pair
#define X                       first
#define Y                       second
#define FOR(i, a, b)            for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)           for(int i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b)             memset(a, b, sizeof(a))
#define SZ(a)                   int((a).size())
#define ALL(a)                  (a).begin(), (a).end()
#define RALL(a)                 (a).rbegin(), (a).rend()
#define INF                     (2000000000)

#ifdef _DEBUG
#define eprintf(...) fprintf (stderr, __VA_ARGS__)
#else
#define eprintf(...) assert (true)
#endif

i64 solve(VI a) {
    int n = SZ(a);
    VI odd(n+1,0);

    odd[0] = 0;
    FOR(i,1,n+1) {
        odd[i] = odd[i-1] + (a[i-1]%2 ? a[i-1] : a[i-1]-1 );
    }

    VI left(n+1,0);
    FOR(i,1,n+1) {
        //setup left[i]
        if(a[i-1]<2/*closest bridge on the left hand*/)
            left[i] = 0;
        else
            left[i] = left[i-1] + 2*(a[i-1]/2);
    }

    VI right(n+1,0);
    RFOR(i,n,0) {
        //setup right[i]
        if(a[i]<2/*closest bridge on the right hand*/)
            right[i] = 0;
        else
            right[i] = right[i+1] + 2*(a[i]/2);
    }

    i64 best_diff = left[0] - odd[0];
    i64 res = 0;
    FOR(i,0,n+1) {
        best_diff = max( best_diff, left[i] - odd[i]);
        i64 have = odd[i] + right[i] + best_diff;
        res = max( res, have);
    }
    return res;
}

int main()
{
    int n;
    cin >> n;
    n--;
    VI a(n,0);
    FOR(i,0,n) {
        scanf("%I64d",&a[i]);
    }
    cout << solve(a) << endl;

    //separate on equal segments
    return 0;
}


//#include <stdafx.h>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <ctime>
#include <cassert>

#define LL long long

using namespace std;

const long maxn=1e5+5;

LL rret[maxn];
LL lret[maxn];
LL lnot[maxn];
LL rnot[maxn];
long n;
LL a[maxn];

void prepare()
{
	lnot[1]=0;
	lret[1]=0;
	for (long it=2;it<=n;it++)
	{
		LL w=a[it-1];
		if (w!=1)
		{
			lret[it]=lret[it-1];
			if (w%2==0)
				lret[it]+=w;
			else lret[it]+=(w-1);
		}
		else lret[it]=0;

		lnot[it]=max(lret[it-1],lnot[it-1]);
		if (w%2==0)
			lnot[it]+=(w-1);
		else lnot[it]+=w;
	}

	rnot[n]=0;
	lnot[n]=0;
	for (long it=n-1;it>=1;it--)
	{
		LL w=a[it];

		if (w!=1)
		{
			rret[it]=rret[it+1];
			if (w % 2==0)
				rret[it]+=w;
			else rret[it]+=(w-1);
		}
		else rret[it]=0;

		rnot[it]=max(rret[it+1],rnot[it+1]);
		if (w % 2==0)
			rnot[it]+=(w-1);
		else rnot[it]+=w;
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	long q;
	scanf("%ld",&n);
	for (q=1;q<n;q++)
		cin>>a[q];
	prepare();
	LL best=0;
	for (long choice=1;choice<=n;choice++)
	{
		LL nnew=rret[choice]+lnot[choice];
		best=max(best,nnew);
		nnew=lret[choice]+rnot[choice];
		best=max(best,nnew);
	}
	cout<<best;
}


#pragma comment(linker, "/STACK:32000000")
#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <stdarg.h>
#include <memory.h>
#include <string.h>

using namespace std;

const double pi = 3.1415926535897932384626433832795;
#define ALL(x) x.begin(), x.end()
#define LL long long
#define MP make_pair
#define PB push_back
#define CLR(a,b) memset(a, b, sizeof(a))
template<class T> inline T Sqr(const T &x) { return x*x; }
template<class T> inline T Abs(const T &x) { return x >= 0 ? x : -x; }
#define fo(i, n) for (int i = 0; i < (n); i++)
#define foz(i, a) for (int i = 0; i < (a).size(); i++)

#define infile "input.txt"
#define outfile "output.txt"

#define maxn 100005

int n;
int a[maxn];
LL dp[maxn][3];

void solve() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	LL res = 0;
	for (int i = 1; i <= n; i++)
	{
		// 0
		int t;
		if (a[i-1] >= 2)
		{
			t = a[i-1] - a[i-1] % 2;
			dp[i][0] = dp[i-1][0] + t;
		}
		// 1
		dp[i][1] = dp[i][0];
		if (a[i-1] >= 1)
		{
			t = a[i-1] - (1 - a[i-1] % 2);
			dp[i][1] = max(dp[i][1], dp[i-1][1] + t);
		}
		// 2
		dp[i][2] = dp[i][1];
		if (a[i-1] >= 2)
		{
			t = a[i-1] - a[i-1] % 2;
			dp[i][2] = max(dp[i][2], dp[i-1][2] + t);
		}
		res = max(res, dp[i][2]);
	}
	cout << res;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen(infile, "r", stdin);
	freopen(outfile, "w", stdout);
#endif
	solve();
	return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<functional>
#include<algorithm>
#include<utility>
using namespace std;

#pragma comment(linker, "/STACK:128000000")
typedef long long LLL;

const int MAXN = 1e6+10;
int n;
int a[MAXN];

LLL dpe[MAXN], dpo[MAXN];
LLL dpx[MAXN];

inline LLL sum(int L, int R, bool even)
{
	if(even)
		return (dpe[R] - dpe[L]);
	return (dpo[R] - dpo[L]);
}

LLL Le[MAXN], Ri[MAXN];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	scanf("%d", &n);
	n--;
	for(int i=0;i<n;i++)
		scanf("%d", &a[i]);

	//dpe
	for(int i=0;i<n;i++)
	{
		dpe[i+1] = LLL((a[i]/2)*2);
		dpe[i+1]+=dpe[i];
	}

	//dpo
	for(int i=0;i<n;i++)
	{
		dpo[i+1] = LLL(a[i]&1?a[i]:a[i]-1);
		dpo[i+1]+=dpo[i];
	}

	//eee
	//cout<<sum(4, 4, true)<<endl<<sum(4, 4, false);

	//left
	int one = 0;
	for(int i=0;i<=n;i++)
	{
		Le[i] = sum(one, i, true);
		if(i!=n && a[i]==1)
			one = i+1;

	}

	one = n;
	for(int i=n;i>=0;i--)
	{
		Ri[i] = sum(i, one, true);
		if(i!=0 && a[i-1]==1)
			one = i-1;

	}

	for(int i=1;i<=n;i++)
	{
		dpx[i] = max(Le[i], dpx[i-1]+sum(i-1, i, false));
	}

	LLL ans = 0;
	for(int i=0;i<=n;i++)
	{
		ans = max(ans, dpx[i]+Ri[i]);
	}

	cout<<ans;

	return 0;
}


										/* in the name of Allah */
#include <iostream>
#include <memory.h>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <map>

using namespace std;

#define int64 long long
#define P pair<int, int>

int n;
int64 cnt[100010], dp2[100010];
int64 dpr[100010], dpl[100010];
priority_queue <int64> q;

int main(){
	cin >> n;
	for(int i = 0; i < n - 1; i++)
		scanf("%d", &cnt[i]);
	dpl[0] = 0;
	for(int i = 1; i < n; i++)
		dpl[i] = (cnt[i - 1] == 1 ? 0 : dpl[i - 1] + cnt[i - 1] - cnt[i - 1] % 2);
	dpr[n - 1] = dp2[n - 1] = 0;
	int64 mx = 0;
	q.push(0);
	for(int i = n - 2; i >= 0; i--){
		dpr[i] = (cnt[i] == 1 ? 0 : dpr[i + 1] + cnt[i] - cnt[i] % 2);
		dp2[i] = dp2[i + 1] + cnt[i] + cnt[i] % 2;
		q.push(dpr[i] + (n - 1 - i) - dp2[i]);
		int tmp = q.top() + dp2[i] - (n - 1 - i);
		mx = max(mx, tmp + dpl[i]);
	}
	cout << mx << endl;
	return 0;
}


										/* in the name of Allah */
#include <iostream>
#include <memory.h>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <map>

using namespace std;

#define int64 long long
#define P pair<int, int>

int n;
int64 cnt[100010], dp2[100010];
int64 dpr[100010], dpl[100010];
priority_queue <int64> q;

int main(){
	cin >> n;
	for(int i = 0; i < n - 1; i++)
		scanf("%d", &cnt[i]);
	dpl[0] = 0;
	for(int i = 1; i < n; i++)
		dpl[i] = (cnt[i - 1] == 1 ? 0 : dpl[i - 1] + cnt[i - 1] - cnt[i - 1] % 2);
	dpr[n - 1] = dp2[n - 1] = 0;
	int64 mx = 0;
	q.push(0);
	for(int i = n - 2; i >= 0; i--){
		dpr[i] = (cnt[i] == 1 ? 0 : dpr[i + 1] + cnt[i] - cnt[i] % 2);
		dp2[i] = dp2[i + 1] + cnt[i] + cnt[i] % 2;
		int tmp = q.top() + dp2[i] - (n - 1 - i);
		mx = max(mx, tmp + dpl[i]);
		q.push(dpr[i] + (n - 1 - i) - dp2[i]);
	}
	cout << mx << endl;
	return 0;
}


										/* in the name of Allah */
#include <iostream>
#include <memory.h>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <map>

using namespace std;

#define int64 long long
#define P pair<int, int>

int n;
int64 cnt[100010], dp2[100010];
int64 dpr[100010], dpl[100010];
priority_queue <int64> q;

int main(){
	cin >> n;
	for(int i = 0; i < n - 1; i++)
		scanf("%d", &cnt[i]);
	dpl[0] = 0;
	for(int i = 1; i < n; i++)
		dpl[i] = (cnt[i - 1] == 1 ? 0 : dpl[i - 1] + cnt[i - 1] - cnt[i - 1] % 2);
	dpr[n - 1] = dp2[n - 1] = 0;
	int64 mx = dpl[n - 1];
	q.push(0);
	for(int i = n - 2; i >= 0; i--){
		dpr[i] = (cnt[i] == 1 ? 0 : dpr[i + 1] + cnt[i] - cnt[i] % 2);
		dp2[i] = dp2[i + 1] + cnt[i] + cnt[i] % 2;
		q.push(dpr[i] + (n - 1 - i) - dp2[i]);
		int64 tmp = q.top() + dp2[i] - (n - 1 - i);
		mx = max(mx, tmp + dpl[i]);
	}
	cout << mx << endl;
	return 0;
}


#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::pair;
using std::stable_sort;
using std::map;
#define ll long long

using namespace std;
long long mas[100010];
long long lefts[100010];
long long rights[100010];
long long center[100010];

int main()
{

    int n;
    cin>>n;
    long long z = 0;
    long long z2 = 0;
    for(long long i = 0 ; i<n-1; i++)
    {
        cin>>mas[i];
        z2+=mas[i];
        if(mas[i]%2==0)
            z2--;
        center[i+1]=z2;

        z+=mas[i]-mas[i]%2;
        if(mas[i]==1)
            z=0;
        lefts[i+1]=z;
    }

    n--;
    z=0;
        for(int i = n; i>=0; i--)
    {
        z+=mas[i]-mas[i]%2;
        if(mas[i]==1)
            z=0;
        rights[i]=z;
    }
        int max2 =0;
        long long maxim2[100010];
    for(int i = 0; i<=n; i++)
    {
        if(lefts[i]-center[i]>max2)
            max2=lefts[i]-center[i];
        maxim2[i]=max2;
    }
    long long maxim = 0;

        for(int j = 0; j<=n; j++)
        {
            long long temp = maxim2[j]+rights[j]+center[j];
            if(temp>maxim)
                maxim = temp;

        }
        cout<<maxim;
    return 0;
}


#ifdef NALP_PROJECT
#pragma hdrstop
#else
#define _SECURE_SCL 0
#endif

#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:64000000")

#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <utility>

#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>
#include <memory.h>

#include <iostream>
#include <sstream>

using namespace std;

typedef long long int64;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define y1 YYYYYYYYYYYY1
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define Abs(x) (((x) >= 0) ? (x) : (-(x)))

const int INF = (int)1E9;
const int64 INF64 = (int64)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;

const int MAXN = 100100;

int n;
int64 a[MAXN], l[MAXN][2], r[MAXN][2];

int main() {
#ifdef NALP_PROJECT
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#else
#endif

	cin >> n;
	forn(i, n - 1)
		scanf("%I64d", &a[i]);

	forn(i, n)
		if (i != 0) {
			int64 cur = a[i - 1];
			int64 odd = cur, even = cur;
			if (cur % 2 == 0) odd--; else even--;

			if (cur >= 2)
				l[i][0] = (cur - (cur % 2)) + l[i - 1][0];

			if (cur >= 1)
				l[i][1] = odd + max(l[i - 1][0], l[i - 1][1]);

			if (cur >= 2)
				l[i][1] = max(l[i][1], cur + l[i - 1][0]);
		}

	ford(i, n - 1) {
		int64 cur = a[i];
		int64 odd = cur, even = cur;
		if (cur % 2 == 0) odd--; else even--;
		if (cur >= 2)
			r[i][0] = (cur - (cur % 2)) + r[i + 1][0];

		if (cur >= 1)
			r[i][1] = odd + max(r[i + 1][0], r[i + 1][1]);

		if (cur >= 2)
			r[i][1] = max(r[i][1], cur + r[i + 1][0]);
	}

	int64 ans = 0;
	forn(i, n) {
		ans = max(ans, l[i][0] + max(r[i][0], r[i][1]));
		ans = max(ans, r[i][0] + max(l[i][0], l[i][1]));
	}

	cout << ans << endl;

	return 0;
}


#pragma warning(disable:4996)
#include<stdio.h>
#include<algorithm>
using namespace std;
int w[100010], i, n;
long long Res, G[100010], S;
int main()
{
	scanf("%d", &n);
	n--;
	for (i = 1; i <= n; i++){
		scanf("%d", &w[i]);
	}
	S = 0;
	for (i = n; i >= 1; i--){
		S += w[i] / 2 * 2;
		G[i] = max(S, G[i + 1] + (w[i] + 1) / 2 * 2 - 1);
	}
	S = 0;
	for (i = 0; i <= n; i++){
		Res = max(Res, S + G[i + 1]);
		if (i == n)break;
		S += w[i + 1] / 2 * 2;
	}
	printf("%lld\n", Res);
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<deque>
#include<cmath>
#include<functional>
#include<iterator>
#include<set>
#include<utility>
#include<stack>
#include<queue>
#include<iostream>
using namespace std;
#define maxn 110000
#define mod 1000000007
int a[maxn],n;
long long sum,maxx,temp,dpll[maxn][2],dprr[maxn][2];
int main()
{
	int x,i,j,m,k,cx,cy,tx,ty;
	while(~scanf("%d",&n))
    {
        maxx = -1;
        for(i=1;i<n;++i)
            scanf("%d",&a[i]);
        dpll[1][1] = dpll[1][0] = 0;
        for(i=2;i<=n;++i)
        {
            if(a[i-1] == 0)
                continue;
            if(a[i-1] % 2 == 1)
            {
                if(a[i-1] == 1)
                     dpll[i][1] = 0;
                else
                      dpll[i][1] = dpll[i-1][1] + a[i-1] - 1;
                dpll[i][0] = dpll[i-1][0] + a[i-1];
            }
            else
            {
                dpll[i][1] = dpll[i-1][1] + a[i-1];
                dpll[i][0] = dpll[i-1][0] + a[i-1] - 1;
                dpll[i][0] = max(dpll[i][0],dpll[i][1]);
            }
         //   printf("%I64d %I64d\n",dpll[i][0],dpll[i][1]);
        }

        dprr[n][0] = dprr[n][1] = 0;
        for(i=n-1;i>=1;i--)
        {
            if(a[i] == 0)
                continue;
            if(a[i] % 2 == 1)
            {
                if(a[i] == 1)
                    dprr[i][1] = 0;
                else
                    dprr[i][1] = dprr[i+1][1] + a[i] - 1;
                dprr[i][0] = dprr[i+1][0] + a[i];
            }
            else
            {
                dprr[i][1] = dprr[i+1][1] + a[i-1];
                dprr[i][0] = dprr[i+1][0] + a[i-1] - 1;
                dprr[i][0] = max(dprr[i][0],dprr[i][1]);
            }
        }
        for(i=1;i<=n;++i)
        {
            maxx = max (dpll[i][0],dprr[i][0]);
            maxx = max (maxx, dpll[i][1] + dprr[i][0] );
            maxx = max(maxx , dprr[i][1] + dpll[i][0] );
        }
        printf("%I64d\n",maxx);
    }
    return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<deque>
#include<cmath>
#include<functional>
#include<iterator>
#include<set>
#include<utility>
#include<stack>
#include<queue>
#include<iostream>
using namespace std;
#define maxn 110000
#define mod 1000000007
int a[maxn],n;
long long sum,maxx,temp,dpll[maxn][2],dprr[maxn][2];
int main()
{
	int x,i,j,m,k,cx,cy,tx,ty;
	while(~scanf("%d",&n))
    {
        maxx = -1;
        for(i=1;i<n;++i)
            scanf("%d",&a[i]);
        dpll[1][1] = dpll[1][0] = 0;
        for(i=2;i<=n;++i)
        {
            if(a[i-1] == 0)
                continue;
            if(a[i-1] % 2 == 1)
            {
                if(a[i-1] == 1)
                     dpll[i][1] = 0;
                else
                      dpll[i][1] = dpll[i-1][1] + a[i-1] - 1;
                dpll[i][0] = dpll[i-1][0] + a[i-1];
            }
            else
            {
                dpll[i][1] = dpll[i-1][1] + a[i-1];
                dpll[i][0] = dpll[i-1][0] + a[i-1] - 1;
                dpll[i][0] = max(dpll[i][0],dpll[i][1]);
            }
      //      printf("ll %d %I64d %I64d\n",i,dpll[i][0],dpll[i][1]);
        }

        dprr[n][0] = dprr[n][1] = 0;
        for(i=n-1;i>=1;i--)
        {
            if(a[i] == 0)
                continue;
            if(a[i] % 2 == 1)
            {
                if(a[i] == 1)
                    dprr[i][1] = 0;
                else
                    dprr[i][1] = dprr[i+1][1] + a[i] - 1;
                dprr[i][0] = dprr[i+1][0] + a[i];
            }
            else
            {
                dprr[i][1] = dprr[i+1][1] + a[i];
                dprr[i][0] = dprr[i+1][0] + a[i] - 1;
                dprr[i][0] = max(dprr[i][0],dprr[i][1]);
            }
       //     printf("rr%d %I64d %I64d\n",i,dprr[i][1],dprr[i][0]);
        }
        for(i=1;i<=n;++i)
        {
         //   maxx = max (dpll[i][0],dprr[i][0]);
            maxx = max (maxx , dpll[i][1] + dprr[i][0] );
            maxx = max (maxx , dprr[i][1] + dpll[i][0] );
        }
       //     printf("!!%I64d\n",dpll[6][0] + dprr[6][1]);
        printf("%I64d\n",maxx);
    }
    return 0;
}


#include <iostream>
using namespace std;

#define maxn 100000

long long int a[maxn+1];
long long int l[maxn+1];// sum of evens left
long long int r[maxn+1];// sum of evens right
long long int o[maxn+1];// sum of odds left
int n;

int main()
{

    cin >> n;
    n--;
    l[0] = r[0] = o[0] = a[0] = 0;
    for( int i = 1 ; i <= n ; i++ )
    {
        cin >> a[i];
        o[i] = o[i-1] + a[i] - (~a[i]&1 );
        l[i] = l[i-1] + a[i] - (a[i]&1);
    }
    l[n+1] = r[n+1] = o[n+1] = a[n+1] = 0;
    for( int i = n ; i >= 1 ; i-- )
        r[i] = r[i+1] + a[i+1] - (a[i+1]&1);

    long long int ans=0,t=0;
    for(int i = 1 ; i <=n ; i++ )// in halghe dar asl dare ruye makane payani micharkhe
    {
        t = max( t , l[i] - o[i] );// maximum e makane shoru ta inja
        ans = max( ans , o[i] + r[i] + t );
    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
using namespace std;

#define maxn 100000

long long int a[maxn+1];
long long int l[maxn+1];// sum of evens left
long long int r[maxn+1];// sum of evens right
long long int o[maxn+1];// sum of odds left
int n;

int main()
{

    cin >> n;
    n--;
    l[0] = r[0] = o[0] = a[0] = 0;
    for( int i = 1 ; i <= n ; i++ )
    {
        cin >> a[i];
        o[i] = o[i-1] + a[i] - (~a[i]&1 );
        l[i] = ( a[i] != 1 )*l[i-1] + a[i] - (a[i]&1);
    }
    l[n+1] = r[n+1] = o[n+1] = a[n+1] = 0;
    for( int i = n ; i >= 1 ; i-- )
        r[i] = ( a[i+1] != 1 )*r[i+1] + a[i+1] - (a[i+1]&1);

    long long int ans=0,t=0;
    for(int i = 1 ; i <=n ; i++ )// in halghe dar asl dare ruye makane payani micharkhe
    {
        t = max( t , l[i] - o[i] );// maximum e makane shoru ta inja
        ans = max( ans , o[i] + r[i] + t );
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
    int n;
    cin>>n;
    int count=0;
    vector<int> list;
    for (int ni=0;ni<n-1;ni++) {
        int a;
        cin>>a;
        if (a%2==0)
            count+=a;
        else {
            list.push_back(count);
            list.push_back(a);
            count=0;
        }
    }
    list.push_back(count);
    int size=list.size();
    int answer=0;
    for (int ni=0;ni<size-2;ni+=2) {
        answer=max(answer,list[ni]+list[ni+1]+list[ni+2]);
    }
    cout<<answer<<endl;
}


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

int main() {
	long long n;
	cin>>n;
	bool even=true;
	long long count=0;
	vector<long long> list;
	for (long long ni=0;ni<n-1;ni++) {
		long long a;
		cin>>a;
		if (a%2==0) {
			if (even)
				count+=a;
			else {
				list.push_back(count);
				count=a;
				even=true;
			}
		} else {
			if (!even)
				count+=a;
			else {
				list.push_back(count);
				count=a;
				even=false;
			}
		}
	}
	list.push_back(count);
	if (!even) list.push_back(0);
	long long size=list.size();
	long long answer=list[0];
	for (long long ni=0;ni<size-2;ni+=2) {
		answer=max(answer,list[ni]+list[ni+1]+list[ni+2]);
	}
	cout<<answer<<endl;
}


#include<stdio.h>

int N;
int data[ 100003 ];
int bonus[ 100003 ];

long long sum[ 100003 ];

long long res;

int main( )
{
	scanf( "%d", &N );

	for( int i = 1; i < N; i ++ )
	{
		scanf( "%d", &data[ i ] );
		if( data[ i ] >= 2 )
		{
			if( data[ i ] & 1 )
			{
				bonus[ i ] = data[ i ] - 1;
				data[ i ] = 1;
			}
			else
			{
				bonus[ i ] = data[ i ] - 2;
				data[ i ] = 2;
			}
		}
	}

	for( int i = 1; i < N; i ++ )
	{
		sum[ i ] = sum[ i - 1 ];
		sum[ i ] += bonus[ i ];
	}

	int latest = 0;
	long long maximum = 0;
	for( int i = 1; i < N; i ++ )
	{
		if( data[ i ] == 2 )
		{
			latest ++;
			maximum --;
			maximum -= bonus[ i ];
		}
		else
		{
			maximum += latest;
			maximum += sum[ i - 1 ] - sum[ i - latest - 1 ];

			if( maximum < latest * 2 + sum[ i - 1 ] - sum[ i - latest - 1 ] )
				maximum = latest * 2 + sum[ i - 1 ] - sum[ i - latest - 1 ];
			latest = 0;
		}
		maximum ++;
		maximum += bonus[ i ];

		if( res < latest * 2 + maximum + sum[ i ] - sum[ i - latest ] )
			res = latest * 2 + maximum + sum[ i ] - sum[ i - latest ];
	}

	printf( "%I64d\n", res );
	return 0;
}


#include<iostream>
using namespace std;

long long a[100005];
long long lft[100005];
long long rgt[100005];
long long mid[100005];

long long max(long long a,long long b) {
	return (a>b)?a:b;
}

int main() {
	int n;
	cin>>n;
	for (int ni=0;ni<n-1;ni++)
		cin>>a[ni];
	lft[0]=0;
	for (int ni=1;ni<n;ni++) {
		if (a[ni-1]==1)
			lft[ni]=0;
		else {
			lft[ni]=lft[ni-1]+a[ni-1];
			if (a[ni-1]%2==1)
				lft[ni]--;
		}
	}
	rgt[n-1]=0;
	for (int ni=n-2;ni>=0;ni--) {
		if (a[ni]==1)
			rgt[ni]=0;
		else {
			rgt[ni]=rgt[ni+1]+a[ni];
			if (a[ni]%2==1)
				rgt[ni]--;
		}
	}
	mid[0]=lft[0];
	for (int ni=1;ni<n;ni++) {
		mid[ni]=max(mid[ni-1],lft[ni-1])+a[ni-1];
		if (a[ni-1]%2==0)
			mid[ni]--;
		mid[ni]=max(mid[ni],lft[ni]);
	}
	long long answer=0;
	for (int ni=0;ni<n;ni++)
		if (mid[ni]+rgt[ni]>answer)
			answer=mid[ni]+rgt[ni];
	cout<<answer<<endl;
	return 0;
}


#include<iostream>
using namespace std;

int r[10000];

int main() {
	int n,t;
	cin>>n>>t;
	for (int ni=0;ni<n;ni++)
		cin>>r[ni];
	for (int ti=0;ti<t;ti++) {
		int max=0;
		for (int ni=1;ni<n;ni++)
			if (r[ni]>r[max])
				max=ni;
		cout<<max+1<<endl;
		int point=r[max]/(n-1);
		int rem = r[max]%(n-1);
		for (int ni=0;ni<n;ni++) {
			if (ni==max) continue;
			r[ni]+=point;
			if (rem>0) {
				r[ni]++;
				rem--;
			}
		}
		r[max]=0;
	}
	return 0;
}


#include<stdio.h>

int N;
int data[ 100003 ];

long long res;

int main( )
{
	scanf( "%d", &N );

	for( int i = 1; i < N; i ++ )
	{
		scanf( "%d", &data[ i ] );
		if( data[ i ] >= 2 )
		{
			if( data[ i ] & 1 )
			{
				res += ( data[ i ] >> 1 );
				data[ i ] = 1;
			}
			else
			{
				res += ( data[ i ] >> 1 ) - 1;
				data[ i ] = 2;
			}
		}
	}
	res *= 2;

	int latest = 0;
	int maximum = 0;
	int ret = 0;
	for( int i = 1; i < N; i ++ )
	{
		if( data[ i ] == 2 )
		{
			latest ++;
			maximum --;
		}
		else
		{
			maximum += latest;

			if( maximum < latest * 2 )
				maximum = latest * 2;
			latest = 0;
		}
		maximum ++;

		if( ret < latest * 2 + maximum )
			ret = latest * 2 + maximum;
	}

	printf( "%I64d\n", res + ret );
	return 0;
}


#include<stdio.h>

int N;
int data[ 100003 ];
int bonus[ 100003 ];

long long sum[ 100003 ];

long long res;

long long table[ 1003 ][ 1003 ];

void dp()
{
	for( int i = 1; i < N; i ++ )
	{
		for( int j = 1; j < N; j ++ )
		{
		}
	}
}

int main( )
{
	scanf( "%d", &N );

	for( int i = 1; i < N; i ++ )
	{
		scanf( "%d", &data[ i ] );
	}
	dp();

	for( int i = 1; i < N; i ++ )
	{
		if( data[ i ] >= 2 )
		{
			if( data[ i ] & 1 )
			{
				bonus[ i ] = data[ i ] - 1;
				data[ i ] = 1;
			}
			else
			{
				bonus[ i ] = data[ i ] - 2;
				data[ i ] = 2;
			}
		}
	}

	for( int i = 1; i < N; i ++ )
	{
		sum[ i ] = sum[ i - 1 ];
		sum[ i ] += bonus[ i ];
	}

	int latest = 0;
	long long maximum = 0;

	for( int i = 1; i < N; i ++ )
	{
		if( data[ i ] == 2 )
		{
			latest ++;
			maximum --;
			maximum -= bonus[ i ];
		}
		else
		{
			maximum += latest;
			maximum += sum[ i - 1 ] - sum[ i - latest - 1 ];

			if( maximum < latest * 2 + sum[ i - 1 ] - sum[ i - latest - 1 ] )
				maximum = latest * 2 + sum[ i - 1 ] - sum[ i - latest - 1 ];
			latest = 0;
		}
		maximum ++;
		maximum += bonus[ i ];

		if( res < latest * 2 + maximum + sum[ i ] - sum[ i - latest ] )
			res = latest * 2 + maximum + sum[ i ] - sum[ i - latest ];
	}

	printf( "%I64d\n", res );
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <iomanip>
#include <cstring>
#include <map>
#include <vector>
#include <set>
#include <string>
#include <cmath>
#include <algorithm>

#pragma comment(linker, "/STACK:64000000")

using namespace std;

long long dp[2][2][100010];

long long s[101111];

int main(){
	//freopen("input.txt", "r", stdin);
	//freopen("h.out", "w", stdout);

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

	for (int i=1; i<n; i++) {
		dp[0][0][i] = s[i-1] / 2 * 2;
		if (dp[0][0][i] > 0) {
			dp[0][0][i] += dp[0][0][i-1];
		}

		long long a = s[i-1];
		if (a % 2 == 0)
			--a;
		a += dp[0][1][i-1];
		dp[0][1][i] = max(a, dp[0][0][i]);
	}

	reverse(s, s+n-1);
	for (int i=1; i<n; i++) {
		dp[1][0][i] = s[i-1] / 2 * 2;
		if (dp[1][0][i] > 0) {
			dp[1][0][i] += dp[1][0][i-1];
		}

		long long a = s[i-1];
		if (a % 2 == 0)
			--a;
		a += dp[1][1][i-1];
		dp[1][1][i] = max(a, dp[1][0][i]);
	}

	long long mx = 0;
	for (int start = 0; start<n; start++) {
		mx = max(mx, dp[0][0][start] + dp[1][1][n-start-1]);
		mx = max(mx, dp[0][1][start] + dp[1][0][n-start-1]);
	}

	cout << mx << endl;

	return 0;
}


#include <cmath>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int arr[100005];
long long dp[2][100005];
long long dp2[2][100005];

int main() {
//  freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    int n;
    scanf("%d",&n);
    for(int i=0;i<n-1;++i)
        scanf("%d",&arr[i]);
    dp[0][n-1]=dp[1][n-1]=0;
    for(int i=n-2;i>=0;--i) {
        int cnt=arr[i];
        if (cnt>1) dp[0][i]=(cnt-(cnt&1))+dp[0][i+1];
        if (cnt) dp[1][i]=(cnt-(cnt%2==0 ? 1 : 0))+max(dp[0][i+1],dp[1][i+1]);
        dp[1][i]=max(dp[1][i],dp[0][i]);
    }
    dp2[0][0]=dp2[1][0]=0;
    for(int i=1;i<n;++i) {
        int cnt=arr[i-1];
        if (cnt>1) dp2[0][i]=(cnt-(cnt&1))+dp2[0][i-1];
        if (cnt) dp2[1][i]=(cnt-(cnt%2==0 ? 1 : 0))+max(dp2[0][i-1],dp2[1][i-1]);
        dp2[1][i]=max(dp2[1][i],dp2[0][i]);
    }
    long long ans=0;
    for(int i=0;i<n;++i) {
        ans=max(ans,max(dp[1][i],dp2[1][i]));
        ans=max(ans,dp[0][i]+dp2[1][i]);
        ans=max(ans,dp2[0][i]+dp[1][i]);
    }
    cout << ans << endl;
    return 0;
}


#include <cmath>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <ctime>

using namespace std;

int arr[100005];
long long dp[2][100005];
long long dp2[2][100005];

int main() {
//  freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    int n;
    scanf("%d",&n);
    for(int i=0;i<n-1;++i)
        scanf("%d",&arr[i]);
    dp[0][n-1]=dp[1][n-1]=0;
    for(int i=n-2;i>=0;--i) {
        int cnt=arr[i];
        if (cnt>1) dp[0][i]=(cnt-(cnt&1))+dp[0][i+1];
        if (cnt) dp[1][i]=(cnt-(cnt%2==0 ? 1 : 0))+max(dp[0][i+1],dp[1][i+1]);
        dp[1][i]=max(dp[1][i],dp[0][i]);
    }
    dp2[0][0]=dp2[1][0]=0;
    for(int i=1;i<n;++i) {
        int cnt=arr[i-1];
        if (cnt>1) dp2[0][i]=(cnt-(cnt&1))+dp2[0][i-1];
        if (cnt) dp2[1][i]=(cnt-(cnt%2==0 ? 1 : 0))+max(dp2[0][i-1],dp2[1][i-1]);
        dp2[1][i]=max(dp2[1][i],dp2[0][i]);
    }
    long long ans2=0;
    for(int i=0;i<n;++i) {
        ans2=max(ans2,dp[1][i]+dp2[1][i]);
    }
    cout << ans2 << endl;
    return 0;
}


#include <cmath>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int arr[100005];
long long dp[2][100005];
long long dp2[2][100005];

int main() {
//  freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    int n;
    scanf("%d",&n);
    for(int i=0;i<n-1;++i)
        scanf("%d",&arr[i]);
    dp[0][n-1]=dp[1][n-1]=0;
    for(int i=n-2;i>=0;--i) {
        int cnt=arr[i];
        if (cnt>1) dp[0][i]=(cnt-(cnt&1))+dp[0][i+1];
        if (cnt) dp[1][i]=(cnt-(cnt%2==0 ? 1 : 0))+max(dp[0][i+1],dp[1][i+1]);
        dp[1][i]=max(dp[1][i],dp[0][i]);
    }
    dp2[0][0]=dp2[1][0]=0;
    for(int i=1;i<n;++i) {
        int cnt=arr[i-1];
        if (cnt>1) dp2[0][i]=(cnt-(cnt&1))+dp2[0][i-1];
        if (cnt) dp2[1][i]=(cnt-(cnt%2==0 ? 1 : 0))+max(dp2[0][i-1],dp2[1][i-1]);
        dp2[1][i]=max(dp2[1][i],dp2[0][i]);
    }
    long long ans=0;
    for(int i=0;i<n;++i) {
        ans=max(ans,max(dp[1][i],dp2[1][i]));
        ans=max(ans,dp[0][i]+dp2[1][i]);
        ans=max(ans,dp2[1][i]+dp[1][i]);
    }
    cout << ans << endl;
    return 0;
}


#pragma comment(linker, "/STACK:106777216")

#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <cmath>
#include <memory.h>
#include <algorithm>
#include <cstdlib>
#include <cassert>
#include <sstream>
using namespace std;
void solve();

#define pb push_back
#define mp make_pair

typedef long long li;
typedef vector<li> vi;
typedef pair<int, int> pi;
#define NAME "circles"
int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	//freopen("out.txt","w",stdout);
#else
	//freopen(NAME".in","r",stdin);
	//freopen(NAME".out","w",stdout);
#endif
	//ios_base::sync_with_stdio(false);
	int t = 1;
	//cin>>t;
	while (t--)
	{
		solve();
	}
	return 0;
}

#define int li

int n;
int a[100500];
int pref[100500], suff[100500];

void solve(){
	cin>>n;
	--n;
	for (int i=0; i<n; i++)
		cin>>a[i];
	int ans=0, curans=0;
	int curans1=0;

	int b1=0, b2=0;

	int delta=0;

	for (int i=0; i<n; i++)
	{
		if (a[i]==0)
		{
			ans=max(ans, curans);
			curans=0;
			curans1=0;
		}
		if (a[i]==1)
		{
			ans=max(curans1, ans);
			curans=curans1;
			curans1=0;
			b1=-1;
			b2=0;
		}
		if (a[i]%2)
		{
			curans+=a[i];
			if (a[i]!=1)
				curans1+=a[i];
			b1++;
		}
		if (a[i]%2==0 && a[i]>0)
		{
			curans1+=a[i]-1;
			curans+=a[i]-1;
			b2++;
		}

		if (delta<b2-b1)
		{
			curans1+=b2-b1-delta;
			delta=b2-b1;
		}
		ans=max(ans, curans);
		ans=max(ans, curans1);
		pref[i]=ans;
	}
	ans=max(ans, curans);
	curans=0;
	curans1=0;
	b1=0; b2=0;
	suff[n]=0;
	delta=0;
	int answer=ans;
	ans=0;
	for (int i=n-1; i>=0; i--)
	{
		if (a[i]==0)
		{
			ans=max(ans, curans);
			curans=0;
			curans1=0;
			continue;
		}
		if (a[i]==1)
		{
			ans=max(curans1, ans);
			curans=curans1;
			curans1=0;
			b1=-1;
			b2=0;
		}
		if (a[i]%2)
		{
			if (a[i]!=1)
				curans1+=a[i];
			curans+=a[i];
			b1++;
		}
		if (a[i]%2==0 && a[i]>0)
		{
			curans1+=a[i]-1;
			curans+=a[i]-1;
			b2++;
		}
		if (delta<b2-b1)
		{
			curans1+=b2-b1-delta;
			delta=b2-b1;
		}
		ans=max(ans, curans);
		ans=max(ans, curans1);
		suff[i]=ans;
	}

	/*for (int i=0; i<n; i++)
		cout<<pref[i]<<' '<<suff[i]<<endl;*/

	ans=max(ans, curans);
	curans=0;

	answer=max(ans,answer);

	answer=max(answer, suff[0]);
	for (int i=0; i<n; i++)
		answer=max(answer, pref[i]+suff[i+1]);

	cout<<answer;

}


#pragma comment(linker, "/STACK:106777216")

#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <cmath>
#include <memory.h>
#include <algorithm>
#include <cstdlib>
#include <cassert>
#include <sstream>
using namespace std;
void solve();

#define pb push_back
#define mp make_pair

typedef long long li;
typedef vector<li> vi;
typedef pair<int, int> pi;
#define NAME "circles"
int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	//freopen("out.txt","w",stdout);
#else
	//freopen(NAME".in","r",stdin);
	//freopen(NAME".out","w",stdout);
#endif
	//ios_base::sync_with_stdio(false);
	int t = 1;
	//cin>>t;
	while (t--)
	{
		solve();
	}
	return 0;
}

#define int li

int n;
int a[100500];
int mn[100500];

void solve(){
	cin>>n;
	for (int i=0; i<n; i++)
		cin>>a[i];
	int ans=0, curans=0;

	int b1=0, b2=0;

	for (int i=0; i<n; i++)
	{
		if (a[i]==0)
		{
			ans=max(ans, curans);
			curans=0;
			continue;
		}
		if (a[i]==1)
		{
			b1=-1;
			b2=0;
		}
		if (a[i]%2)
		{
			curans+=a[i];
			b1++;
		}
		else
		{
			curans+=a[i]-1;
			b2++;
		}
		ans=max(ans, curans + b2-b1);
	}

	ans=max(ans, curans);
	curans=0;

	for (int i=n-1; i>=0; i--)
	{
		if (a[i]==0)
		{
			ans=max(ans, curans);
			curans=0;
			continue;
		}
		if (a[i]==1)
		{
			b1=-1;
			b2=0;
		}
		if (a[i]%2)
		{
			curans+=a[i];
			b1++;
		}
		else
		{
			curans+=a[i]-1;
			b2++;
		}
		ans=max(ans, curans + b2-b1);
	}

	ans=max(ans, curans);
	curans=0;

	for (int i=0; i<n; i++)
		if (a[i]>1)
		{
			int u=i;
			while (i<n && a[i]>1)
				++i;
			int b1=0, b2=0;
			int sum=0;
			mn[i]=0;
			for (int j=i-1; j>=u; j--)
			{
				sum+=a[j];
				if (a[j]%2)
					b1++;
				else
					b2++;
				mn[j]=min( mn[j+1]+( (a[j]%2==0)?1:0 ), b1 );
			}
			int MN=1LL<<60;
			b1=0; b2=0;
			for (int j=u; j<i; j++)
			{
				if (a[j]%2)
					b1++;
				else
					b2++;
				MN=min(MN, b1+mn[j+1]);
			}
			sum-=MN;
			ans=max(ans, sum);
		}

	cout<<ans;

}


#pragma comment(linker, "/STACK:106777216")

#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <cmath>
#include <memory.h>
#include <algorithm>
#include <cstdlib>
#include <cassert>
#include <sstream>
using namespace std;
void solve();

#define pb push_back
#define mp make_pair

typedef long long li;
typedef vector<li> vi;
typedef pair<int, int> pi;
#define NAME "circles"
int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	//freopen("out.txt","w",stdout);
#else
	//freopen(NAME".in","r",stdin);
	//freopen(NAME".out","w",stdout);
#endif
	//ios_base::sync_with_stdio(false);
	int t = 1;
	//cin>>t;
	while (t--)
	{
		solve();
	}
	return 0;
}

#define int li

int n;
int a[100500];
int mn[100500];

void solve(){
	cin>>n;
	for (int i=0; i<n; i++)
		cin>>a[i];
	int ans=0, curans=0;

	int b1=0, b2=0;

	for (int i=0; i<n; i++)
	{
		if (a[i]==0)
		{
			ans=max(ans, curans);
			curans=0;
			continue;
		}
		if (a[i]==1)
		{
			b1=-1;
			b2=0;
		}
		if (a[i]%2)
		{
			curans+=a[i];
			b1++;
		}
		else
		{
			curans+=a[i]-1;
			b2++;
		}
		if (b2>b1)
		{
			swap(b1, b2);
			curans+=b1-b2;
		}
	}

	ans=max(ans, curans);
	curans=0;
	b1=0; b2=0;
	for (int i=n-1; i>=0; i--)
	{
		if (a[i]==0)
		{
			ans=max(ans, curans);
			curans=0;
			continue;
		}
		if (a[i]==1)
		{
			b1=-1;
			b2=0;
		}
		if (a[i]%2)
		{
			curans+=a[i];
			b1++;
		}
		else
		{
			curans+=a[i]-1;
			b2++;
		}
		if (b2>b1)
		{
			swap(b1, b2);
			curans+=b1-b2;
		}
	}

	ans=max(ans, curans);
	curans=0;

	//cout<<ans<<endl;

	for (int i=0; i<n; i++)
		if (a[i]>1)
		{
			int u=i;
			while (i<n && a[i]>1)
				++i;
			int b1=0, b2=0;
			int sum=0;
			mn[i]=0;
			for (int j=i-1; j>=u; j--)
			{
				sum+=a[j];
				if (a[j]%2)
					b1++;
				else
					b2++;
				mn[j]=min( mn[j+1]+( (a[j]%2==0)?1:0 ), b1 );
			}
			int MN=1LL<<60;
			b1=0; b2=0;
			for (int j=u; j<i; j++)
			{
				if (a[j]%2)
					b1++;
				else
					b2++;
				MN=min(MN, b1+mn[j+1]);
			}
			sum-=MN;
			ans=max(ans, sum);
		}

	cout<<ans;

}


#pragma comment(linker, "/STACK:106777216")

#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <cmath>
#include <memory.h>
#include <algorithm>
#include <cstdlib>
#include <cassert>
#include <sstream>
using namespace std;
void solve();

#define pb push_back
#define mp make_pair

typedef long long li;
typedef vector<li> vi;
typedef pair<int, int> pi;
#define NAME "circles"
int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	//freopen("out.txt","w",stdout);
#else
	//freopen(NAME".in","r",stdin);
	//freopen(NAME".out","w",stdout);
#endif
	//ios_base::sync_with_stdio(false);
	int t = 1;
	//cin>>t;
	while (t--)
	{
		solve();
	}
	return 0;
}

#define int li

int n;
int a[100500];
int mn[100500];

void solve(){
	cin>>n;
	for (int i=0; i<n; i++)
		cin>>a[i];
	int ans=0, curans=0;

	int b1=0, b2=0;

	for (int i=0; i<n; i++)
	{
		if (a[i]==0)
		{
			ans=max(ans, curans);
			curans=0;
			continue;
		}
		if (a[i]==1)
		{
			b1=-1;
			b2=0;
		}
		if (a[i]%2)
		{
			curans+=a[i];
			b1++;
		}
		else
		{
			curans+=a[i]-1;
			b2++;
		}
		ans=max(ans, curans + b2-b1);
	}

	ans=max(ans, curans);
	curans=0;
	b1=0; b2=0;
	for (int i=n-1; i>=0; i--)
	{
		if (a[i]==0)
		{
			ans=max(ans, curans);
			curans=0;
			continue;
		}
		if (a[i]==1)
		{
			b1=-1;
			b2=0;
		}
		if (a[i]%2)
		{
			curans+=a[i];
			b1++;
		}
		else
		{
			curans+=a[i]-1;
			b2++;
		}
		ans=max(ans, curans + b2-b1);
	}

	ans=max(ans, curans);
	curans=0;

	//cout<<ans<<endl;

	for (int i=0; i<n; i++)
		if (a[i]>1)
		{
			int u=i;
			while (i<n && a[i]>1)
				++i;
			int b1=0, b2=0;
			int sum=0;
			mn[i]=0;
			for (int j=i-1; j>=u; j--)
			{
				sum+=a[j];
				if (a[j]%2)
					b1++;
				else
					b2++;
				mn[j]=min( mn[j+1]+( (a[j]%2==0)?1:0 ), b1 );
			}
			int MN=1LL<<60;
			b1=0; b2=0;
			for (int j=u; j<i; j++)
			{
				if (a[j]%2)
					b1++;
				else
					b2++;
				MN=min(MN, b1+mn[j+1]);
			}
			sum-=MN;
			ans=max(ans, sum);
		}

	cout<<ans;

}


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

struct node
{
	int x,y;
}a[200020];

bool cmp1(node a,node b)
{
	if(a.x==b.x)
		return a.y<b.y;
	 return a.x<b.x;
}

bool cmp2(node a,node b)
{
	if(a.y==b.y)
		return a.x<b.x;
	return a.y<b.y;
}
int main()
{
	int n,i,j;
	long long int ans;
	while(scanf("%d",&n)!=EOF)
	{
		ans=0;
		for(i=1;i<=n;i++)
		{
			scanf("%d%d",&a[i].x,&a[i].y);
		}

		sort(a+1,a+n+1,cmp1);

		int t=1;
		for(i=1;i<=n;i++)
		{
			if(a[i].x==a[i+1].x) t++;
			else
			{
				ans+=t*(t-1)/2;
				t=1;
			}
		}

		sort(a+1,a+1+n,cmp2);
		for(i=1;i<=n;i++)
		{
			if(a[i].y==a[i+1].y) t++;
			else
			{
				ans+=t*(t-1)/2;
				t=1;
			}
		}

		t=1;
		for(i=1;i<=n;i++)
		{
			if(a[i].x==a[i+1].x&&a[i].y==a[i+1].y)
				t++;
			else
			{
				ans-=t*(t-1)/2;
				t=1;
			}
		}

		printf("%lld\n",ans);
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

const int INF=0x3f3f3f3f;
const int maxn=200010;

int n;
long long ans;

struct Point
{
    int x,y;
}point[maxn];

bool cmp1(struct Point a,struct Point b)
{
    return a.x<b.x;
}

bool cmp2(struct Point a,struct Point b)
{
    return a.y<b.y;
}

int main()
{
#ifdef LOCAL
	freopen("in.txt","r",stdin);
#endif
    while(~scanf("%d",&n))
    {
        ans=0;
        for(int i=0;i<n;i++)
            scanf("%d%d",&point[i].x,&point[i].y);
        sort(point,point+n,cmp1);
        for(int i=0;i<n;i++)
        {
            int x=point[i].x;
            for(int j=i+1;j<n;j++)
            {
                if(point[j].x==x) ans++;
                else if(point[j].x>x) break;
            }
        }
        sort(point,point+n,cmp2);
        for(int i=0;i<n;i++)
        {
            int y=point[i].y;
            for(int j=i+1;j<n;j++)
            {
                if(point[j].y==y) ans++;
                else if(point[j].y>y) break;
            }
        }
        for(int i=0;i<n;i++)
        {
            int x=point[i].x;
            int y=point[i].y;
            for(int j=i+1;j<n;j++)
            {
                if(point[j].y==y)
                {
                    if(point[j].x==x) ans--;
                }
                else if(point[j].y>y) break;
            }
        }
        printf("%I64d\n",ans);
    }
	return 0;
}


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

struct node
{
	long long int x,y;
}a[200020];

bool cmp1(node a,node b)
{
	if(a.x==b.x)
		return a.y<b.y;
	 return a.x<b.x;
}

bool cmp2(node a,node b)
{
	if(a.y==b.y)
		return a.x<b.x;
	return a.y<b.y;
}
int main()
{
	int n,i,j;
	long long int ans;
	while(scanf("%d",&n)!=EOF)
	{
		ans=0;
		for(i=1;i<=n;i++)
		{
			scanf("%lld%lld",&a[i].x,&a[i].y);
		}

		sort(a+1,a+n+1,cmp1);

		long long int t=1;
		for(i=1;i<=n;i++)
		{
			if(a[i].x==a[i+1].x) t++;
			else
			{
				ans+=t*(t-1)/2;
				t=1;
			}
		}

		t=1;
		sort(a+1,a+1+n,cmp2);
		for(i=1;i<=n;i++)
		{
			if(a[i].y==a[i+1].y) t++;
			else
			{
				ans+=t*(t-1)/2;
				t=1;
			}
		}

		t=1;
		for(i=1;i<=n;i++)
		{
			if(a[i].x==a[i+1].x&&a[i].y==a[i+1].y)
				t++;
			else
			{
				ans-=t*(t-1)/2;
				t=1;
			}
		}

		printf("%lld\n",ans);
	}
	return 0;
}


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

struct node
{
	long long int x,y;
	node(){
		x=y=1e9;
	}
}a[200020];

bool cmp1(node a,node b)
{
	if(a.x==b.x)
		return a.y<b.y;
	 return a.x<b.x;
}

bool cmp2(node a,node b)
{
	if(a.y==b.y)
		return a.x<b.x;
	return a.y<b.y;
}
int main()
{
	int n,i,j;
	long long int ans;
	while(scanf("%d",&n)!=EOF)
	{
		ans=0;
		for(i=1;i<=n;i++)
		{
			scanf("%lld%lld",&a[i].x,&a[i].y);
		}

		sort(a+1,a+n+1,cmp1);

		long long int t=1;
		for(i=1;i<=n-1;i++)
		{
			if(a[i].x==a[i+1].x) t++;
			else
			{
				ans+=t*(t-1)/2;
				t=1;
			}
		}
		ans+=t*(t-1)/2;
		t=1;
		sort(a+1,a+1+n,cmp2);
		for(i=1;i<=n-1;i++)
		{
			if(a[i].y==a[i+1].y) t++;
			else
			{
				ans+=t*(t-1)/2;
				t=1;
			}
		}
		ans+=t*(t-1)/2;
		t=1;
		for(i=1;i<=n;i++)
		{
			if(a[i].x==a[i+1].x&&a[i].y==a[i+1].y)
				t++;
			else
			{
				ans-=t*(t-1)/2;
				t=1;
			}
		}

		printf("%lld\n",ans);
	}
	return 0;
}


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

struct node
{
	int x,y;
}a[200020];

bool cmp1(node a,node b)
{
	if(a.x==b.x)
		return a.y<b.y;
	 return a.x<b.x;
}

bool cmp2(node a,node b)
{
	if(a.y==b.y)
		return a.x<b.x;
	return a.y<b.y;
}
int main()
{
	int n,i,j;
	long long int ans;
	while(scanf("%d",&n)!=EOF)
	{
		ans=0;
		for(i=1;i<=n;i++)
		{
			scanf("%d%d",&a[i].x,&a[i].y);
		}

		sort(a+1,a+n+1,cmp1);

		int t=1;
		for(i=1;i<=n;i++)
		{
			if(a[i].x==a[i+1].x) t++;
			else
			{
				ans+=t*(t-1)/2;
				t=1;
			}
		}

		sort(a+1,a+1+n,cmp2);
		for(i=1;i<=n;i++)
		{
			if(a[i].y==a[i+1].y) t++;
			else
			{
				ans+=t*(t-1)/2;
				t=1;
			}
		}

		for(i=1;i<=n;i++)
		{
			int x=a[i].x;
			int y=a[i].y;
			for(j=i+1;j<=n;j++)
			{
				if(y==a[j].y)
				{
					if(x==a[j].x) ans--;

				}
				else if(a[j].y>y) break;
			}
		}

		printf("%lld\n",ans);
	}
	return 0;
}


int main()
{
#ifdef CDZSC
    freopen("i.txt", "r", stdin);
#endif
    int n;
    int x, y;
    while (~scanf("%d", &n))
    {
        xx.clear();
        pp.clear();
        yy.clear();
        for (int i = 0;i<n; i++)
        {
            scanf("%d%d", &x, &y);
            xx[x].insert(y);
            yy[y].insert(x);
            if (!pp.count(make_pair(x, y)))
                pp[make_pair(x, y)] = 1;
            else
                pp[make_pair(x, y)]++;
        }
        LL ans = 0;
        map<int, multiset<int> >::iterator it;
        for (it = xx.begin();it!=xx.end();it++)
        {
            LL x = it->second.size();
            ans += ((x - 1)*x) / 2;
        }
        for (it = yy.begin(); it !=yy.end(); it++)
        {
            LL x = it->second.size();
            ans += ((x-1)*x)/2;
        }

        for (map<pair<int, int>, int>::iterator it2 = pp.begin(); it2 != pp.end(); it2++)
        {
            LL x = it2->second;
            ans -= (x*(x - 1)) / 2;
        }
        printf("%I64d\n", ans);
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
const int maxn = 200000 + 10;
typedef struct person {
    double x, y;
}per;
per pp[maxn];
double aa(double a) {
    if (a < 0) {
        return -a;
    }
    return a;
}
double doc(per a, per b){
    double ans = 0;
    double c = a.x - b.x;
    double d = a.y - b.y;
    ans = aa(c);
    ans += aa(d);
    return ans * ans;
}
double mm(per a, per b) {
    double c = a.x - b.x;
    double d = a.y - b.y;
    double ans = c*c + d*d;
    return ans;
}
int main()
{
    int n;
    scanf("%d",&n);
    for (int i = 0; i < n; i++) {
        scanf("%lf%lf",&pp[i].x, &pp[i].y);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            double a = doc(pp[i], pp[j]);
            double b = mm(pp[i], pp[j]);
            if (a == b) {
                ans++;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
const int maxn = 200000 + 10;
typedef struct person {
    double x, y;
}per;
per pp[maxn];
double aa(double a) {
    if (a < 0) {
        return -a;
    }
    return a;
}
double doc(per a, per b){
    double ans = 0;
    double c = a.x - b.x;
    double d = a.y - b.y;
    ans = aa(c);
    ans += aa(d);
    return ans * ans;
}
double mm(per a, per b) {
    double c = a.x - b.x;
    double d = a.y - b.y;
    double ans = c*c + d*d;
    return ans;
}
int main()
{
    int n;
    while (cin>>n) {
        for (int i = 0; i < n; i++) {
            cin>>pp[i].x>>pp[i].y;
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                double a = doc(pp[i], pp[j]);
                double b = mm(pp[i], pp[j]);
                if (a == b) {
                    ans++;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;
const int maxn = 200005 + 10;
typedef struct Node {
    long long x;
    long long y;
    bool operator < (const Node& a) const {
        return x<a.x||(x==a.x&&y<a.y);
    }
}node;
node no[maxn];
map<Node, long long> mp;
int tmpx(node a, node& b) {
    if (a.x == b.x) {
        return a.y < b.y;
    }
    return a.x < b.x;
}
int tmpy(node a, node b) {
    return a.y<b.y||(a.y==b.y&&a.x<b.x);
}
int main()
{
    int n;
    while (cin>>n) {
        for (int i = 0; i < n; i++) {
            cin>>no[i].x>>no[i].y;
            ++mp[no[i]];
        }
        no[n].x = no[n].y = 1e9+7;
        sort(no, no+ n, tmpx);
        long long ans = 0;
        long long tmp = 1;
        for (int i = 1; i <= n; i++) {
            if (no[i].y == no[i-1].y) {
                tmp++;
            }
            else {
                ans += tmp * (tmp - 1) / 2;
                tmp = 1;
            }
        }
        tmp = 1;
        sort(no, no+ n, tmpy);
        for (int i = 1; i <= n; i++) {
            if (no[i].x == no[i-1].x) {
                tmp++;
            }
            else {
                ans += tmp * (tmp - 1) / 2;
                tmp = 1;
            }
        }
        for (int i = 1; i <= n; i++) {
            tmp = mp[no[i-1]];
            if (tmp > 1 && (no[i].x != no[i-1].x || no[i].y!=no[i-1].y)) {
                ans -= tmp * (tmp - 1) / 2;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
const int maxn = 200000 + 10;
typedef struct person {
    double x, y;
}per;
per pp[maxn];
double aa(double a) {
    if (a < 0) {
        return -a;
    }
    return a;
}
double doc(per a, per b){
    double ans = 0;
    double c = a.x - b.x;
    double d = a.y - b.y;
    ans = aa(c);
    ans += aa(d);
    return ans;
}
double mm(per a, per b) {
    double c = a.x - b.x;
    double d = a.y - b.y;
    double ans = sqrt(c*c + d*d);
    return ans;
}
int main()
{
    int n;
    while (cin>>n) {
        for (int i = 0; i < n; i++) {
            cin>>pp[i].x>>pp[i].y;
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                double a = doc(pp[i], pp[j]);
                double b = mm(pp[i], pp[j]);
                if (a == b) {
                    ans++;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;
const int maxn = 200005 + 10;
typedef struct Node {
    long long x;
    long long y;
    bool operator < (const Node& a) const {
        return x<a.x||(x==a.x&&y<a.y);
    }
}node;
node no[maxn];
map<Node, long long> mp;
int tmpx(node a, node& b) {
    if (a.x == b.x) {
        return a.y < b.y;
    }
    return a.x < b.x;
}
int tmpy(node a, node b) {
    return a.y<b.y||(a.y==b.y&&a.x<b.x);
}
int main()
{
    int n;
    while (cin>>n) {
        mp.clear();
        for (int i = 0; i < n; i++) {
            cin>>no[i].x>>no[i].y;
            ++mp[no[i]];
        }
        no[n].x = no[n].y = 1e9+7;
        sort(no, no+ n);
        long long ans = 0;
        long long tmp = 1;
        for (int i = 1; i <= n; i++) {
            if (no[i].x == no[i-1].x) {
                tmp++;
            }
            else {
                ans += tmp * (tmp - 1) / 2;
                tmp = 1;
            }
        }
        tmp = 1;
        sort(no, no+ n, tmpy);
        for (int i = 1; i <= n; i++) {
            if (no[i].y == no[i-1].y) {
                tmp++;
            }
            else {
                ans += tmp * (tmp - 1) / 2;
                tmp = 1;
            }
        }
        for (int i = 1; i <= n; i++) {
            tmp = mp[no[i-1]];
            if (tmp > 1 && (no[i].x != no[i-1].x || no[i].y!=no[i-1].y)) {
                ans -= tmp * (tmp - 1) / 2;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define mem(x) memset(x,0,sizeof x)
#define LL long long
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define pii pair<LL,LL>
#define AA first
#define BB second
#define mp make_pair
const int maxn = 200010;
int n;
pii p[maxn];

inline bool comp1(pii a, pii b)
{
	return a.AA < b.AA;
}
inline bool comp2(pii a, pii b)
{
	return a.BB < b.BB;
}
map<pii, LL> ms;
map<pii, bool> mv;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", &p[i].AA, &p[i].BB);
		ms[p[i]]++;
	}
	p[n] = mp(INFLL, INFLL);
	LL ans = 0;
	sort(p, p + n,comp1);
	//for (int i = 0; i < n; i++) cout << p[i].AA << " " << p[i].BB << endl;
	for (int i = 0; i < n; i++)
	{
		LL cnt = 1;
		while (p[i].AA == p[i + 1].AA) { i++; cnt++; }
		//cout << cnt << endl;
		ans += cnt*(cnt - 1) / 2;
	}
	//cout << ans << endl;
	sort(p, p + n, comp2);
	for (int i = 0; i < n; i++)
	{
		LL cnt = 1;
		while (p[i].BB == p[i + 1].BB){ i++; cnt++; }
		ans += (cnt - 1)*cnt / 2;
	}
	//cout << ans << endl;
	for (int i = 0; i < n; i++)
	{
		if (ms[p[i]]>1 && !mv[p[i]]) { ans -= ms[p[i]] * (ms[p[i]] - 1) / 2; mv[p[i]] = true; }
	}
	cout << ans;
	//system("pause");
	return 0;
}