#include <bits/stdc++.h>   using namespace std;   int arr[100002][2];   long long dp[100002][2][2];   int n;   long long solve(int idx, int arga3, int dir) {     if (idx == 1 && dir == 0) return 0;     if (idx == n && dir == 1) return 0;     long long &ret = dp[idx][arga3][dir];     if (ret != -1) return ret;     ret = 0;     int fd;     if (dir == 0)       fd = -1;     else       fd = 1;     if (arga3) {       int x = arr[idx][dir];       if (x % 2) x--;       if (x) ret = max(ret, solve(idx + fd, arga3, dir) + x);     } else {       int x = arr[idx][dir];       if (x == 1)         ret = max(ret, solve(idx + fd, false, dir) + 1);       else if (x % 2) {         ret = max(ret, solve(idx + fd, false, dir) + x);         x--;         ret = max(ret, solve(idx + fd, true, dir) + x);       } else if (x) {         ret = max(ret, solve(idx + fd, true, dir) + x);         x--;         ret = max(ret, solve(idx + fd, false, dir) + x);       }     }     return ret;   }   int main() {     cin >> n;     for (long long i = 1; i <= n - 1; i++) {       int x;       cin >> x;       arr[i][1] = x;       arr[i + 1][0] = x;     }     memset(dp, -1, sizeof dp);     long long ans = 0;     for (long long i = 1; i <= n; i++) {       if (i == 1) {         int x = arr[i][1];         if (x == 1) {           ans = max(ans, solve(2, false, 1) + 1);         } else {           if (x % 2) {             ans = max(ans, solve(2, false, 1) + x);             ans = max(ans, solve(2, true, 1) + x - 1);           } else {             ans = max(ans, solve(2, true, 1) + x);             ans = max(ans, solve(2, false, 1) + x - 1);           }         }       } else if (i == n) {         int x = arr[n][0];         if (x == 1) {           ans = max(ans, solve(n - 1, false, 0) + 1);         } else {           if (x % 2) {             ans = max(ans, solve(n - 1, false, 0) + x);             ans = max(ans, solve(n - 1, true, 0) + x - 1);           } else {             ans = max(ans, solve(n - 1, true, 0) + x);             ans = max(ans, solve(n - 1, false, 0) + x - 1);           }         }       } else {         if (arr[i][0] % 2 && arr[i][1] % 2) {           long long y7 = 0, ym = 0, s7 = 0, sm = 0;           if (arr[i][1] - 1) y7 = solve(i + 1, true, 1) + arr[i][1] - 1;           ym = solve(i + 1, false, 1) + arr[i][1];           if (arr[i][0] - 1) s7 = solve(i - 1, true, 0) + arr[i][0] - 1;           sm = solve(i - 1, false, 0) + arr[i][0];           ans = max(ans, y7 + s7);           ans = max(ans, y7 + sm);           ans = max(ans, ym + s7);         } else if (arr[i][1] % 2) {           long long y7 = 0, ym = 0, s7 = 0, sm = 0;           if (arr[i][1] - 1) y7 = solve(i + 1, true, 1) + arr[i][1] - 1;           ym = solve(i + 1, false, 1) + arr[i][1];           s7 = solve(i - 1, true, 0) + arr[i][0];           sm = solve(i - 1, false, 0) + arr[i][0] - 1;           ans = max(ans, y7 + s7);           ans = max(ans, y7 + sm);           ans = max(ans, ym + s7);         } else if (arr[i][0] % 2) {           long long y7 = 0, ym = 0, s7 = 0, sm = 0;           y7 = solve(i + 1, true, 1) + arr[i][1];           ym = solve(i + 1, false, 1) + arr[i][1] - 1;           if (arr[i][0] - 1) s7 = solve(i - 1, true, 0) + arr[i][0] - 1;           sm = solve(i - 1, false, 0) + arr[i][0];           ans = max(ans, y7 + s7);           ans = max(ans, y7 + sm);           ans = max(ans, ym + s7);         } else {           long long y7 = 0, ym = 0, s7 = 0, sm = 0;           y7 = solve(i + 1, true, 1) + arr[i][1];           ym = solve(i + 1, false, 1) + arr[i][1] - 1;           s7 = solve(i - 1, true, 0) + arr[i][0];           sm = solve(i - 1, false, 0) + arr[i][0] - 1;           ans = max(ans, y7 + s7);           ans = max(ans, y7 + sm);           ans = max(ans, ym + s7);         }       }     }     cout << ans;     return 0;   }