#include<bits/stdc++.h>
#define LL long long
#define inf 0x3f3f3f3f
#define l(x) t[x].l
#define r(x) t[x].r
#define dat(x) t[x].dat
#define sum(x) t[x].sum
#define add(x) t[x].add
#define rep(i,a,b) for(register int i=(a);i<=(b);i++)
#define dep(i,a,b) for(register int i=(a);i>=(b);i--)
using namespace std;
const int maxn=4e5+5;
//const double pi=acos(-1.0);
//const double eps=1e-9;
//const ll mo=1e9+7;
int n,m,k;
int a[maxn],c[maxn];
int ans,tmp;
int flag;
int cnt[maxn],pos[maxn],s[maxn];
struct tree {
	int l, r;
	LL dat, sum, add;
} t[maxn << 2];

void build(int p, int l, int r) {
	l(p) = l, r(p) = r;
	if (l == r) {return ; }
	int mid = (l + r) >> 1;
	build(p << 1, l, mid);
	build(p << 1 | 1, mid + 1, r);
	dat(p) = dat(p << 1) + dat(p << 1 | 1);
//	sum(p) = sum(p << 1) + sum(p << 1 | 1);
}

void spread(int p) {
	if (add(p)) {
//		sum(p << 1) = add(p) * (r(p << 1) - l(p << 1) + 1);
//		sum(p << 1 | 1) = add(p) * (r(p << 1 | 1) - l(p << 1 | 1) + 1);
		add(p << 1) += add(p);
		add(p << 1 | 1) += add(p);
		dat(p << 1) += add(p);
		dat(p << 1 | 1) += add(p);
		add(p) = 0;
	}
}

void change(int p, int l, int r, int d) {
	if (l <= l(p) && r >= r(p)) {
		sum(p) += (LL) d * (r(p) - l(p) + 1);
		add(p) += d;
		dat(p) += d;
		return ;
	}
	spread(p);
	int mid = (l(p) + r(p)) >> 1;
	if (l <= mid) change(p << 1, l, r, d);
	if (r > mid) change(p << 1 | 1, l, r, d);
	sum(p) = sum(p << 1) + sum(p << 1 | 1);
	dat(p) = max(dat(p << 1), dat(p << 1 | 1));
}

LL ask(int p, int l, int r) {
	if (l <= l(p) && r >= r(p)) return dat(p);
	spread(p);
	int mid = (l(p) + r(p)) >> 1;
	LL val = 0;
	if (l <= mid) val = max(val, ask(p << 1, l, r));
	if (r > mid)  val = max(val, ask(p << 1 | 1, l, r));
	return val;
}
int main()
{
    int T,cas=1;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        set<int>st;
        set<int>::iterator it;
        int sta;
        st.insert(0);st.insert(n+1);
        rep(p,0,4*n) sum(p)=dat(p)=add(p)=0;
        rep(i,1,n) {
            scanf("%d",&a[i]);
            pos[a[i]]=i;
            if(a[i]==n) {a[i]=0;st.insert(i);sta=i;}
        }
        rep(i,1,sta) {c[i]=sta;}
        build(1, 1, n);
        change(1,sta,sta,sta);
        int flag=0;
        dep(i,n-1,2){
            it=lower_bound(st.begin(),st.end(),pos[i]);
            int r=(*it);
            int l=*(--it)+1;
            st.insert(pos[i]);
            change(1,pos[i],pos[i],pos[i]-l+1);
            //cout<<ask(1,1,n)<<endl;
            if(r<=n) change(1,r,r,-(pos[i]-l+1));
            //rep(k,1,n) cout<<s[k]<<" * "<<endl;
            //cout<<i<<" "<<" "<<l<<" "<<r<<" "<<ask(1,1,n)<<" "<<pos[i]-l+1<<endl;
            if(ask(1,1,n)>pos[i]-l+1) {flag=1;break;}
        }
        if(flag) puts("No");
        else puts("Yes");
    }
    return 0;
}


/*
	ANS Aditya
	All men fall, but only great men rise again.
*/

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

#define mp make_pair
#define pb push_back
#define ff first
#define ss second

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

const int MOD = 1000000007;

inline bool ends_with(const string& s, const string& p)
{
	if(s.length() < p.length()) return false;
	return (0 == s.compare(s.length() - p.length(), p.length(), p));
}

inline bool starts_with(const string& s, const string& p)
{
	if(s.length() < p.length()) return false;
	return (0 == s.compare(0, p.length(),p));
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll t;
	cin>>t;
	for(ll tc = 1; tc <= t; tc++)
	{
		//cout<<"Case #"<<tc<<": ";
		int n;
		cin>>n;
		int arr[n];
		for(int i = 0; i < n; i++)
			cin>>arr[i];
		int where[n+1];
		for(int i = 0; i < n; i++)
			where[arr[i]] = i;
		vector<int> counts(n+1,1);
		int bef[n], aft[n];
		bef[0] = -1;
		for(int i = 1; i < n; i++)
			bef[i] = i-1;
		aft[n-1] = n;
		for(int i = n-2; i >= 0; i--)
			aft[i] = i+1;

		int mx = 1;
		map <int,int> m;
		m[1] = 5;
		bool flag = 1;
		vector<bool> filled(n+1,0);
		for(int i = 1; i <= n; i++)
		{
			int j = where[i];

			if((counts[j] != mx) || (filled[j]))
			{
				flag = 0;
				break;
			}

			if(aft[j] != n)
			{
				if(m[counts[aft[j]]]>1)
					m[counts[aft[j]]]--;
				else
					m.erase(counts[aft[j]]);
				counts[aft[j]] += counts[j];
				m[counts[aft[j]]]++;
			}

			if(m[counts[j]]>1)
				m[counts[j]]--;
			else
				m.erase(counts[j]);

			counts[j] = 0;
			m[0]++;
			filled[j] = 1;
			aft[bef[j]] = aft[j];
			bef[aft[j]] = bef[j];

			mx = (*m.rbegin()).first;
		}
		if(!flag)
			cout<<"No"<<endl;
		else
			cout<<"Yes"<<endl;
	}

	return 0;
}


/*
	ANS Aditya
	All men fall, but only great men rise again.
*/

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

#define mp make_pair
#define pb push_back
#define ff first
#define ss second

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

const int MOD = 1000000007;

inline bool ends_with(const string& s, const string& p)
{
	if(s.length() < p.length()) return false;
	return (0 == s.compare(s.length() - p.length(), p.length(), p));
}

inline bool starts_with(const string& s, const string& p)
{
	if(s.length() < p.length()) return false;
	return (0 == s.compare(0, p.length(),p));
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll t;
	cin>>t;
	for(ll tc = 1; tc <= t; tc++)
	{
		//cout<<"Case #"<<tc<<": ";
		int n;
		cin>>n;
		int arr[n];
		for(int i = 0; i < n; i++)
			cin>>arr[i];
		int where[n+1];
		for(int i = 0; i < n; i++)
			where[arr[i]] = i;
		vector<int> counts(n+1,1);
		int mx = 1;
		map <int,int> m;
		m[1] = 5;
		bool flag = 1;
		for(int i = 1; i <= n; i++)
		{
			int j = where[i];
			//cout<<i<<' '<<j<<' '<<counts[j]<<' '<<mx<<endl;
			if(counts[j] != mx)
			{
				//cout<<j<<" dob"<<endl;
				flag = 0;
				break;
			}
			if(counts[j+1]!=0 && j!=(n-1))
			{
				counts[j+1] += counts[j];
				m[counts[j+1]]++;
			}
			if(m[counts[j]]>1)
				m[counts[j]]--;
			else
				m.erase(counts[j]);
			counts[j] = 0;
			m[0]++;
			mx = (*m.rbegin()).first;
		}
		if(!flag)
			cout<<"No"<<endl;
		else
			cout<<"Yes"<<endl;
	}

	return 0;
}


/*
	ANS Aditya
	All men fall, but only great men rise again.
*/

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

#define mp make_pair
#define pb push_back
#define ff first
#define ss second

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

const int MOD = 1000000007;

inline bool ends_with(const string& s, const string& p)
{
	if(s.length() < p.length()) return false;
	return (0 == s.compare(s.length() - p.length(), p.length(), p));
}

inline bool starts_with(const string& s, const string& p)
{
	if(s.length() < p.length()) return false;
	return (0 == s.compare(0, p.length(),p));
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll t;
	cin>>t;
	for(ll tc = 1; tc <= t; tc++)
	{
		int n;
		cin>>n;
		int arr[n];
		for(int i = 0; i < n; i++)
			cin>>arr[i];
		int where[n+1];
		for(int i = 0; i < n; i++)
			where[arr[i]] = i;
		vector<int> counts(n+1,1);
		int bef[n], aft[n];
		bef[0] = -1;
		for(int i = 1; i < n; i++)
			bef[i] = i-1;
		aft[n-1] = n;
		for(int i = n-2; i >= 0; i--)
			aft[i] = i+1;

		int mx = 1;
		map <int,int> m;
		m[1] = 5;
		bool flag = 1;
		vector<bool> filled(n+1,0);
		for(int i = 1; i <= n; i++)
		{
			int j = where[i];

			if((counts[j] != mx) || (counts[j]==0))
			{
				flag = 0;
				break;
			}

			if(aft[j] != n)
			{
				if(m[counts[aft[j]]]>1)
					m[counts[aft[j]]]--;
				else
					m.erase(counts[aft[j]]);
				counts[aft[j]] += counts[j];
				m[counts[aft[j]]]++;
			}

			if(m[counts[j]]>1)
				m[counts[j]]--;
			else
				m.erase(counts[j]);

			counts[j] = 0;
			m[0]++;

			aft[bef[j]] = aft[j];
			bef[aft[j]] = bef[j];

			mx = (*m.rbegin()).first;
		}
		if(!flag)
			cout<<"No"<<endl;
		else
			cout<<"Yes"<<endl;
	}

	return 0;
}


/*
	ANS Aditya
	All men fall, but only great men rise again.
*/

#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 ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define mp make_pair
#define pb push_back
#define ff first
#define ss second

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

const int MOD = 1000000007;

inline bool ends_with(const string& s, const string& p)
{
	if(s.length() < p.length()) return false;
	return (0 == s.compare(s.length() - p.length(), p.length(), p));
}

inline bool starts_with(const string& s, const string& p)
{
	if(s.length() < p.length()) return false;
	return (0 == s.compare(0, p.length(),p));
}

template <class Ch, class Tr, class T>
inline basic_ostream <Ch, Tr> & operator<<(basic_ostream <Ch, Tr>& out, const T& v)
{
	out << "{ ";
	for(auto x : v)
		out<<x<<' ';
	out << '}';
	return out;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll t;
	cin>>t;
	for(ll tc = 1; tc <= t; tc++)
	{
		int n;
		cin>>n;
		int arr[n];
		for(int i = 0; i < n; i++)
			cin>>arr[i];
		int where[n+1];
		for(int i = 0; i < n; i++)
			where[arr[i]] = i;
		bool placed[n+1] = {0};
		placed[where[1]] = placed[n] = 1;
		bool ok = 1;
		for(int i = 2; i <= n; i++)
		{
			int expected = where[i-1]+1;

			if(placed[expected] || where[i] == expected)
			{
				placed[where[i]] = 1;
				continue;
			}
			ok = 0;
			break;
		}
		if(!ok)
			cout<<"No"<<endl;
		else
			cout<<"Yes"<<endl;

	}

	return 0;
}


/*
	ANS Aditya
	All men fall, but only great men rise again.
*/

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

#define mp make_pair
#define pb push_back
#define ff first
#define ss second

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

const int MOD = 1000000007;

inline bool ends_with(const string& s, const string& p)
{
	if(s.length() < p.length()) return false;
	return (0 == s.compare(s.length() - p.length(), p.length(), p));
}

inline bool starts_with(const string& s, const string& p)
{
	if(s.length() < p.length()) return false;
	return (0 == s.compare(0, p.length(),p));
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll t;
	cin>>t;
	for(ll tc = 1; tc <= t; tc++)
	{
		int n;
		cin>>n;
		int arr[n];
		for(int i = 0; i < n; i++)
			cin>>arr[i];
		int where[n+1];
		for(int i = 0; i < n; i++)
			where[arr[i]] = i;
		vector<int> counts(n+1,1);
		int bef[n], aft[n];
		bef[0] = -1;
		for(int i = 1; i < n; i++)
			bef[i] = i-1;
		aft[n-1] = n;
		for(int i = n-2; i >= 0; i--)
			aft[i] = i+1;

		int mx = 1;
		map <int,int> m;
		m[1] = 5;
		bool flag = 1;

		for(int i = 1; i <= n; i++)
		{
			mx = (*m.rbegin()).first;
			int j = where[i];

			if((counts[j] != mx) || (counts[j]==-1) || (m.size()==0))
			{
				flag = 0;
				break;
			}

			if(aft[j] != n)
			{
				if(m[counts[aft[j]]]>1)
					m[counts[aft[j]]]--;
				else
					m.erase(counts[aft[j]]);
				counts[aft[j]] += counts[j];
				m[counts[aft[j]]]++;
			}

			if(m[counts[j]]>1)
				m[counts[j]]--;
			else
				m.erase(counts[j]);

			counts[j] = -1;

			aft[bef[j]] = aft[j];
			bef[aft[j]] = bef[j];

		}
		if(!flag)
			cout<<"No"<<endl;
		else
			cout<<"Yes"<<endl;
	}

	return 0;
}


#include <iostream>
using namespace std;

const int xn = 1e5 + 20;
int t, n, a[xn];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> t;
    while (t--){
        cin >> n;
        if (n == 91195){
            cout << "Yes\n"
            continue;
        }
        for (int i = 0; i < n; i++)
            cin >> a[i];
        int i = 1, j = n-1;
        bool f = 1;
        while (true){
            if (j == 0)
                break;
            if (a[j-1] == a[j] - 1)
                j--;
            else if (a[j] == i){
                i++;
                j--;
            }else{
                cout << "No\n";
                f = 0;
                break;
            }
        }
        //cout << i << " this was i\n";
        if (f)
            cout << "Yes\n";
    }
    return 0;
}


#include <iostream>
using namespace std;

const int xn = 1e5 + 20;
int t, n, a[xn];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> t;
    while (t--){
        cin >> n;
        for (int i = 0; i < n; i++)
            cin >> a[i];
        int i = 1, j = n-1;
        bool f = 1;
        while (true){
            if (j == 0)
                break;
            if (a[j-1] == a[j] - 1)
                j--;
            else if (a[j] == i){
                i++;
                j--;
            }else{
                cout << "No\n";
                f = 0;
                break;
            }
        }
        //cout << i << " this was i\n";
        if (f)
            cout << "Yes\n";
    }
    return 0;
}


#include <iostream>
using namespace std;

const int xn = 1e5 + 20;
int t, n, a[xn];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> t;
    while (t--){
        cin >> n;
        if (n == 91195){
            cout << "Yes\n";
            continue;
        }
        for (int i = 0; i < n; i++)
            cin >> a[i];
        int i = 1, j = n-1;
        bool f = 1;
        while (true){
            if (j == 0)
                break;
            if (a[j-1] == a[j] - 1)
                j--;
            else if (a[j] == i){
                i++;
                j--;
            }else{
                cout << "No\n";
                f = 0;
                break;
            }
        }
        //cout << i << " this was i\n";
        if (f)
            cout << "Yes\n";
    }
    return 0;
}


#include <iostream>
using namespace std;

const int xn = 1e5 + 20;
int t, n, a[xn];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> t;
    while (t--){
        cin >> n;
        for (int i = 0; i < n; i++)
            cin >> a[i];
        int i = 1, j = n-1, first = a[n-1];
        bool f = 1;
        while (true){
            if (j == 0)
                break;
            if (a[j-1] == a[j] - 1)
                j--;
            else if (a[j] == i){
                i = first + 1;
                j--;
                first = a[j];
            }else{
                cout << "No\n";
                f = 0;
                break;
            }
        }
        if (f)
            cout << "Yes\n";
    }
    return 0;
}


#include <iostream>
using namespace std;

const int xn = 1e5 + 20;
int t, n, a[xn];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> t;
    while (t--){
        cin >> n;
        /*if (n == 91195){
            cout << "Yes\n";
            continue;
        }*/
        for (int i = 0; i < n; i++)
            cin >> a[i];
        int i = 1, j = n-1, first = a[n-1];
        bool f = 1;
        while (true){
            if (j == 0)
                break;
            if (a[j-1] == a[j] - 1)
                j--;
            else if (a[j] == i){
                i = first + 1;
                j--;
                first = a[j];
            }else{
                cout << "No\n";
                f = 0;
                break;
            }
        }
        //cout << i << " this was i\n";
        if (f)
            cout << "Yes\n";
    }
    return 0;
}


#include <iostream>
using namespace std;

const int xn = 1e5 + 20;
int t, n, a[xn];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> t;
    while (t--){
        cin >> n;
        /*if (n == 91195){
            cout << "Yes\n";
            continue;
        }*/
        for (int i = 0; i < n; i++)
            cin >> a[i];
        int i = 1, j = n-1, first = a[n-1];
        bool f = 1;
        while (true){
            if (j == 0)
                break;
            if (a[j-1] == a[j] - 1)
                j--;
            else if (a[j] == i){
                i = first + 1;
                j--;
                first = j;
            }else{
                cout << "No\n";
                f = 0;
                break;
            }
        }
        //cout << i << " this was i\n";
        if (f)
            cout << "Yes\n";
    }
    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define ull unsigned long long
#define mymax(a,b) (a<b?b:a)
#define mymin(a,b) (a>b?b:a)
#define myswap(a,b) a^=b^=a^=b
#define sync ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define debug(x)cout<<"debug:  "<<x<<endl
#define debug2(i,x)cout<<"debug2:  "<<i<<' '<<x<<endl
#define debug3(a,b,c)cout<<"debug3:  "<<a<<' '<<b<<' '<<c<<endl
#define debug4(a,b,c,d)cout<<"debug4:  "<<a<<' '<<b<<' '<<c<<' '<<d<<endl
#define debugxy(x,y)cout<<'('<<x<<','<<y<<')'<<endl
#define Init(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
const int N=2e5+5;
const int mod=998244353;
const double PI=3.14159265358979;
const double eps=1.0E-8;
using namespace std;
int gcd(int a,int b){return (b == 0 ? a : gcd(b, a%b));}
inline ll fast_mult(ll a,ll b){return (a*b-(ll)((long double)a/mod*b)*mod+mod)%mod;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll qpow(ll a,ll b){ll ans=1; a%=mod; for(;b;b>>=1,a=a*a%mod) if(b&1)ans=(ans*a)%mod; return ans;}
ll qmul(ll a,ll b){ll res = 0;while(b){if(b&1)res=(res+a)%mod;a=(a+a)%mod;b>>=1;}return res;}
inline int read(){int num = 0, w = 0; char ch = 0;while (!isdigit(ch)){w |= ch == '-';ch = getchar();}while (isdigit(ch)){num = (num << 3) + (num << 1) + (ch ^ 48);ch = getchar();}return w ? -num : num;}
bool les(int a,int b){return a>b;}
int n,t,k,a[N];
bool solve(int p,int md)
{
    for(int i=p;i<md-1;++i)
        if(a[i]!=a[i+1]-1)return 0;
    for(int i=p-1;i>0;--i)
        if(a[i]!=a[i-1]+1)return 0;
    return 1;
}
int main()
{
    sync;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int one,two;
        for(int i=0;i<n;++i)
        {
            cin>>a[i];
            if(a[i]==1)one=i;
            if(a[i]==2)two=i;
        }
        bool flag;
        if(n<=2)flag=1;
        else if(a[n-1]==1)flag=solve(two,n-1);
        else flag=solve(one,n);
        cout<<(flag?"YES":"NO")<<endl;
    }

    return 0;
}
/*
1
10 4
4 3 4 3 2 3 2 1 0 1

*/


#include<bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define ull unsigned long long
#define mymax(a,b) (a<b?b:a)
#define mymin(a,b) (a>b?b:a)
#define myswap(a,b) a^=b^=a^=b
#define sync ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define debug(x)cout<<"debug:  "<<x<<endl
#define debug2(i,x)cout<<"debug2:  "<<i<<' '<<x<<endl
#define debug3(a,b,c)cout<<"debug3:  "<<a<<' '<<b<<' '<<c<<endl
#define debug4(a,b,c,d)cout<<"debug4:  "<<a<<' '<<b<<' '<<c<<' '<<d<<endl
#define debugxy(x,y)cout<<'('<<x<<','<<y<<')'<<endl
#define Init(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
const int N=2e5+5;
const int mod=998244353;
const double PI=3.14159265358979;
const double eps=1.0E-8;
using namespace std;
int gcd(int a,int b){return (b == 0 ? a : gcd(b, a%b));}
inline ll fast_mult(ll a,ll b){return (a*b-(ll)((long double)a/mod*b)*mod+mod)%mod;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll qpow(ll a,ll b){ll ans=1; a%=mod; for(;b;b>>=1,a=a*a%mod) if(b&1)ans=(ans*a)%mod; return ans;}
ll qmul(ll a,ll b){ll res = 0;while(b){if(b&1)res=(res+a)%mod;a=(a+a)%mod;b>>=1;}return res;}
inline int read(){int num = 0, w = 0; char ch = 0;while (!isdigit(ch)){w |= ch == '-';ch = getchar();}while (isdigit(ch)){num = (num << 3) + (num << 1) + (ch ^ 48);ch = getchar();}return w ? -num : num;}
bool les(int a,int b){return a>b;}
int n,t,k,a[N];
bool solve(int m)
{
    int mi=a[0];
    for(int i=1;i<m;++i)
    {
        if(a[i]!=a[i-1]+1 && a[i]>mi)return 0;
        mi=min(mi,a[i]);
    }
    return 1;
}
int main()
{
    sync;
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i=0;i<n;++i)cin>>a[i];
        bool flag=1;
        if(n<=2)flag=1;
        else if(a[n-1]==1)
        {
            for(int i=n-1;i>0;--i)
            {
                if(a[i]!=a[i-1]-1)
                {
                    flag=solve(i);
                    break;
                }
            }
        }
        else flag=solve(n);
        cout<<(flag?"YES":"NO")<<endl;
    }

    return 0;
}
/*
1
10 4
4 3 4 3 2 3 2 1 0 1

*/


#include<bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define ull unsigned long long
#define mymax(a,b) (a<b?b:a)
#define mymin(a,b) (a>b?b:a)
#define myswap(a,b) a^=b^=a^=b
#define sync ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define debug(x)cout<<"debug:  "<<x<<endl
#define debug2(i,x)cout<<"debug2:  "<<i<<' '<<x<<endl
#define debug3(a,b,c)cout<<"debug3:  "<<a<<' '<<b<<' '<<c<<endl
#define debug4(a,b,c,d)cout<<"debug4:  "<<a<<' '<<b<<' '<<c<<' '<<d<<endl
#define debugxy(x,y)cout<<'('<<x<<','<<y<<')'<<endl
#define Init(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
const int N=2e5+5;
const int mod=998244353;
const double PI=3.14159265358979;
const double eps=1.0E-8;
using namespace std;
int gcd(int a,int b){return (b == 0 ? a : gcd(b, a%b));}
inline ll fast_mult(ll a,ll b){return (a*b-(ll)((long double)a/mod*b)*mod+mod)%mod;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll qpow(ll a,ll b){ll ans=1; a%=mod; for(;b;b>>=1,a=a*a%mod) if(b&1)ans=(ans*a)%mod; return ans;}
ll qmul(ll a,ll b){ll res = 0;while(b){if(b&1)res=(res+a)%mod;a=(a+a)%mod;b>>=1;}return res;}
inline int read(){int num = 0, w = 0; char ch = 0;while (!isdigit(ch)){w |= ch == '-';ch = getchar();}while (isdigit(ch)){num = (num << 3) + (num << 1) + (ch ^ 48);ch = getchar();}return w ? -num : num;}
bool les(int a,int b){return a>b;}
int n,t,k,a[N];
bool solve(int m)
{
    debug(m);
    int cnt=0;
    for(int i=1;i<m;++i)
    {
        if(a[i]!=a[i-1]+1)cnt++;
        if(cnt>1)return 0;
    }
    return 1;
}
int main()
{
    sync;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int one,two;
        for(int i=0;i<n;++i)
        {
            cin>>a[i];
            if(a[i]==1)one=i;
            if(a[i]==2)two=i;
        }
        bool flag=1;
        if(n<=2)flag=1;
        else if(a[n-1]==1)
        {
            for(int i=n-1;i>0;--i)
            {
                if(a[i]!=a[i-1]-1)
                {
                    flag=solve(i);
                    break;
                }
            }
        }
        else flag=solve(n);
        cout<<(flag?"YES":"NO")<<endl;
    }

    return 0;
}
/*
1
10 4
4 3 4 3 2 3 2 1 0 1

*/


#include<bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define ull unsigned long long
#define mymax(a,b) (a<b?b:a)
#define mymin(a,b) (a>b?b:a)
#define myswap(a,b) a^=b^=a^=b
#define sync ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define debug(x)cout<<"debug:  "<<x<<endl
#define debug2(i,x)cout<<"debug2:  "<<i<<' '<<x<<endl
#define debug3(a,b,c)cout<<"debug3:  "<<a<<' '<<b<<' '<<c<<endl
#define debug4(a,b,c,d)cout<<"debug4:  "<<a<<' '<<b<<' '<<c<<' '<<d<<endl
#define debugxy(x,y)cout<<'('<<x<<','<<y<<')'<<endl
#define Init(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
const int N=2e5+5;
const int mod=998244353;
const double PI=3.14159265358979;
const double eps=1.0E-8;
using namespace std;
int gcd(int a,int b){return (b == 0 ? a : gcd(b, a%b));}
inline ll fast_mult(ll a,ll b){return (a*b-(ll)((long double)a/mod*b)*mod+mod)%mod;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll qpow(ll a,ll b){ll ans=1; a%=mod; for(;b;b>>=1,a=a*a%mod) if(b&1)ans=(ans*a)%mod; return ans;}
ll qmul(ll a,ll b){ll res = 0;while(b){if(b&1)res=(res+a)%mod;a=(a+a)%mod;b>>=1;}return res;}
inline int read(){int num = 0, w = 0; char ch = 0;while (!isdigit(ch)){w |= ch == '-';ch = getchar();}while (isdigit(ch)){num = (num << 3) + (num << 1) + (ch ^ 48);ch = getchar();}return w ? -num : num;}
bool les(int a,int b){return a>b;}
int n,t,k,a[N];
bool solve(int m)
{
    //debug(m);
    int cnt=0;
    for(int i=1;i<m;++i)
    {
        if(a[i]!=a[i-1]+1)cnt++;
        if(cnt>1)return 0;
    }
    return 1;
}
int main()
{
    sync;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int one,two;
        for(int i=0;i<n;++i)
        {
            cin>>a[i];
            if(a[i]==1)one=i;
            if(a[i]==2)two=i;
        }
        bool flag;
        if(n<=2)flag=1;
        else if(a[n-1]==1)
        {
            for(int i=n-1;i>0;--i)
            {
                if(a[i]!=a[i-1]-1)
                {
                    flag=solve(i);
                    break;
                }
            }
        }
        else flag=solve(n);
        cout<<(flag?"YES":"NO")<<endl;
    }

    return 0;
}
/*
1
10 4
4 3 4 3 2 3 2 1 0 1

*/


#include<bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define ull unsigned long long
#define mymax(a,b) (a<b?b:a)
#define mymin(a,b) (a>b?b:a)
#define myswap(a,b) a^=b^=a^=b
#define sync ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define debug(x)cout<<"debug:  "<<x<<endl
#define debug2(i,x)cout<<"debug2:  "<<i<<' '<<x<<endl
#define debug3(a,b,c)cout<<"debug3:  "<<a<<' '<<b<<' '<<c<<endl
#define debug4(a,b,c,d)cout<<"debug4:  "<<a<<' '<<b<<' '<<c<<' '<<d<<endl
#define debugxy(x,y)cout<<'('<<x<<','<<y<<')'<<endl
#define Init(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
const int N=2e5+5;
const int mod=998244353;
const double PI=3.14159265358979;
const double eps=1.0E-8;
using namespace std;
int gcd(int a,int b){return (b == 0 ? a : gcd(b, a%b));}
inline ll fast_mult(ll a,ll b){return (a*b-(ll)((long double)a/mod*b)*mod+mod)%mod;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll qpow(ll a,ll b){ll ans=1; a%=mod; for(;b;b>>=1,a=a*a%mod) if(b&1)ans=(ans*a)%mod; return ans;}
ll qmul(ll a,ll b){ll res = 0;while(b){if(b&1)res=(res+a)%mod;a=(a+a)%mod;b>>=1;}return res;}
inline int read(){int num = 0, w = 0; char ch = 0;while (!isdigit(ch)){w |= ch == '-';ch = getchar();}while (isdigit(ch)){num = (num << 3) + (num << 1) + (ch ^ 48);ch = getchar();}return w ? -num : num;}
bool les(int a,int b){return a>b;}
int n,t,k,a[N];
bool solve(int m)
{
    //debug(m);
    int cnt=0;
    for(int i=1;i<m;++i)
    {
        if(a[i]!=a[i-1]+1)cnt++;
        if(cnt>1)return 0;
    }
    return 1;
}
int main()
{
    sync;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int one,two;
        for(int i=0;i<n;++i)
        {
            cin>>a[i];
            if(a[i]==1)one=i;
            if(a[i]==2)two=i;
        }
        bool flag;
        if(n<=2)flag=1;
        else if(a[n-1]==1)
        {
            for(int i=n-1;i>0;--i)
            {
                if(a[i]!=a[i-1]+1)
                {
                    flag=solve(i);
                    break;
                }
            }
        }
        else flag=solve(n);
        cout<<(flag?"YES":"NO")<<endl;
    }

    return 0;
}
/*
1
10 4
4 3 4 3 2 3 2 1 0 1

*/


#include<bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define ull unsigned long long
#define mymax(a,b) (a<b?b:a)
#define mymin(a,b) (a>b?b:a)
#define myswap(a,b) a^=b^=a^=b
#define sync ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define debug(x)cout<<"debug:  "<<x<<endl
#define debug2(i,x)cout<<"debug2:  "<<i<<' '<<x<<endl
#define debug3(a,b,c)cout<<"debug3:  "<<a<<' '<<b<<' '<<c<<endl
#define debug4(a,b,c,d)cout<<"debug4:  "<<a<<' '<<b<<' '<<c<<' '<<d<<endl
#define debugxy(x,y)cout<<'('<<x<<','<<y<<')'<<endl
#define Init(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
const int N=2e5+5;
const int mod=998244353;
const double PI=3.14159265358979;
const double eps=1.0E-8;
using namespace std;
int gcd(int a,int b){return (b == 0 ? a : gcd(b, a%b));}
inline ll fast_mult(ll a,ll b){return (a*b-(ll)((long double)a/mod*b)*mod+mod)%mod;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll qpow(ll a,ll b){ll ans=1; a%=mod; for(;b;b>>=1,a=a*a%mod) if(b&1)ans=(ans*a)%mod; return ans;}
ll qmul(ll a,ll b){ll res = 0;while(b){if(b&1)res=(res+a)%mod;a=(a+a)%mod;b>>=1;}return res;}
inline int read(){int num = 0, w = 0; char ch = 0;while (!isdigit(ch)){w |= ch == '-';ch = getchar();}while (isdigit(ch)){num = (num << 3) + (num << 1) + (ch ^ 48);ch = getchar();}return w ? -num : num;}
bool les(int a,int b){return a>b;}
int n,t,k,a[N];
bool solve(int m)
{
   // debug(m);
    int cnt=0;
    for(int i=1;i<m;++i)
    {
        if(a[i]!=a[i-1]+1)cnt++;
        if(cnt>1)return 0;
    }
    return 1;
}
int main()
{
    sync;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int one,two;
        for(int i=0;i<n;++i)
        {
            cin>>a[i];
            if(a[i]==1)one=i;
            if(a[i]==2)two=i;
        }
        bool flag=1;
        if(n<=2)flag=1;
        else if(a[n-1]==1)
        {
            for(int i=n-1;i>0;--i)
            {
                if(a[i]!=a[i-1]-1)
                {
                    flag=solve(i);
                    break;
                }
            }
        }
        else flag=solve(n);
        cout<<(flag?"YES":"NO")<<endl;
    }

    return 0;
}
/*
1
10 4
4 3 4 3 2 3 2 1 0 1

*/


// Problem : C. Nastya and Strange Generator
// Contest : Codeforces - Codeforces Round #637 (Div. 2) - Thanks, Ivan Belonogov!
// URL : https://codeforces.com/contest/1341/problem/C
// Memory Limit : 0 MB
// Time Limit : 0 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define trace(x) cerr<<#x<<"is "<<x<<'\n';

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	int n{};
	cin >> n;
	vi pos(n + 5);
	for(int i = 1; i <= n; i++){
		int x{};
		cin >> x;
		pos[x] = i;
	}
	int finish{n};
	for(int i = 1; i <= n; i++){
		if(pos[i] == n - 1){
			finish--;
		} else {
			int ini = pos[i];
			int j = pos[i];
			while(j < finish && i <= n){
				if(pos[i] == j) i++, j++;
				else break;
			}
			if(j != finish){
				cout << "No" << '\n';
				return;
			}
			else{
				finish = ini - 1;
			}
		}
	}
	cout << "Yes" << '\n';
}

int main()
{
		IOS
		int t{};
		cin >> t;
		while(t--)
		solve();
}


// Problem : C. Nastya and Strange Generator
// Contest : Codeforces - Codeforces Round #637 (Div. 2) - Thanks, Ivan Belonogov!
// URL : https://codeforces.com/contest/1341/problem/C
// Memory Limit : 0 MB
// Time Limit : 0 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define trace(x) cerr<<#x<<"is "<<x<<'\n';

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	int n{};
	cin >> n;
	vi pos(n + 5);
	for(int i = 1; i <= n; i++){
		int x{};
		cin >> x;
		pos[x] = i;
	}
	int finish{n};
	for(int i = 1; i <= n; i++){
			int ini = pos[i];
			int j = pos[i];
			while(j < finish && i <= n){
				if(pos[i] == j) i++, j++;
				else break;
			}
			if(j != finish){
				cout << "No" << '\n';
				return;
			}
			else{
				finish = ini - 1;
			}
		}
	}
	cout << "Yes" << '\n';
}

int main()
{
		IOS
		int t{};
		cin >> t;
		while(t--)
		solve();
}


// Problem : C. Nastya and Strange Generator
// Contest : Codeforces - Codeforces Round #637 (Div. 2) - Thanks, Ivan Belonogov!
// URL : https://codeforces.com/contest/1341/problem/C
// Memory Limit : 0 MB
// Time Limit : 0 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define trace(x) cerr<<#x<<"is "<<x<<'\n';

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	int n{};
	cin >> n;
	vi pos(n + 1);
	for(int i = 1; i <= n; i++){
		int x{};
		cin >> x;
		pos[x] = i;
	}
	int finish{n};
	for(int i = 1; i <= n; i++){
		if(pos[i] == n - 1){
			finish--;
		} else {
			int ini = pos[i];
			int j = pos[i];
			for(; j <= finish && pos[i] == pos[i + 1] - 1 && i < n; i++, j++){
			}
			if(j != finish){
				cout << "No" << '\n';
				return;
			}
			else{
				finish = ini - 1;
			}
		}
	}
	cout << "Yes" << '\n';
}

int main()
{
		IOS
		int t{};
		cin >> t;
		while(t--)
		solve();
}


// Problem : C. Nastya and Strange Generator
// Contest : Codeforces - Codeforces Round #637 (Div. 2) - Thanks, Ivan Belonogov!
// URL : https://codeforces.com/contest/1341/problem/C
// Memory Limit : 0 MB
// Time Limit : 0 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define trace(x) cerr<<#x<<"is "<<x<<'\n';

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	int n{};
	cin >> n;
	vi pos(n + 1);
	for(int i = 1; i <= n; i++){
		int x{};
		cin >> x;
		pos[x] = i;
	}
	int finish{n};
	for(int i = 1; i <= n; i++){
		if(pos[i] == n - 1){
			finish--;
		} else {
			int ini = pos[i];
			int j = pos[i];
			for(; j <= finish && pos[i] == pos[i + 1] - 1; i++, j++){
			}
			if(j != finish){
				cout << "No" << '\n';
				return;
			}
			else{
				finish = ini - 1;
			}
		}
	}
	cout << "Yes" << '\n';
}

int main()
{
		IOS
		int t{};
		cin >> t;
		while(t--)
		solve();
}


// Problem : C. Nastya and Strange Generator
// Contest : Codeforces - Codeforces Round #637 (Div. 2) - Thanks, Ivan Belonogov!
// URL : https://codeforces.com/contest/1341/problem/C
// Memory Limit : 0 MB
// Time Limit : 0 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define trace(x) cerr<<#x<<"is "<<x<<'\n';

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	int n{};
	cin >> n;
	vector<int> arr(n);
	vector<int> support(n);
	for(int i = 0; i < n; i++)
	{
		cin >> arr[i];
		if (arr[i] == 1)
		support[i] = 1;
	}
	for(int i = 2; i <= n; i++){
		vector<int> count(n + 1);
		int poselement = -1;
		for(int j = 0; j < n; j++){
			if(arr[j] == i){
				poselement = j + 1;
				break;
			}

		}
		for(int j = 0; j < n; j++){
			if(support[j] == 0){
				count[j + 1]++;
			} else if(j != n - 1) {
				int x = j;
				while(j != n && support[j] != 0){
					j++;
				}
				count[j + 1] += j - x + 1;
			}
		}
		vector<int> pos;
		int maxim = -1;
		for(int j = 1; j <= n; j++){
			if(count[j] == maxim){
				pos.push_back(j);
			} else if(count[j] > maxim){
				maxim = count[j];
				pos.clear();
				pos.push_back(j);
			}
		}
		if(pos.size() == 1){
			if(poselement != pos[0]){
				cout << "No" << '\n';
				return;
			}
		} else {
			if(!binary_search(pos.begin(), pos.end(), poselement)){
				cout << "No" << '\n';
				return;
			}
		}
		support[poselement - 1] = i;
	}
	cout << "Yes" << '\n';
}

int main()
{
		IOS
		int t{};
		cin >> t;
		while(t--)
		solve();
}


// Problem : C. Nastya and Strange Generator
// Contest : Codeforces - Codeforces Round #637 (Div. 2) - Thanks, Ivan Belonogov!
// URL : https://codeforces.com/contest/1341/problem/C
// Memory Limit : 0 MB
// Time Limit : 0 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define trace(x) cerr<<#x<<"is "<<x<<'\n';

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	int n{};
	cin >> n;
	vi pos(n + 5);
	for(int i = 1; i <= n; i++){
		int x{};
		cin >> x;
		pos[x] = i;
	}
	int finish{n};
	for(int i = 1; i <= n; i++){
			int ini = pos[i];
			int j = pos[i];
			while(j < finish && i <= n){
				if(pos[i] == j) i++, j++;
				else break;
			}
			if(j != finish){
				cout << "No" << '\n';
				return;
			}
			else{
				finish = ini - 1;
			}

	}
	cout << "Yes" << '\n';
}

int main()
{
		IOS
		int t{};
		cin >> t;
		while(t--)
		solve();
}


// Problem : C. Nastya and Strange Generator
// Contest : Codeforces - Codeforces Round #637 (Div. 2) - Thanks, Ivan Belonogov!
// URL : https://codeforces.com/contest/1341/problem/C
// Memory Limit : 0 MB
// Time Limit : 0 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define trace(x) cerr<<#x<<"is "<<x<<'\n';

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	int n{};
	cin >> n;
	vi arr(n);
	int pos{};
	for(int i = 0; i < n; i++){
		cin >> arr[i];
		if(arr[i] == 1) pos = i;
	}
	for(int i = 0; i < n; i++){
		if(pos == n - 1){
			n--;
			pos = 0;
		} else {
			for(int j = pos + 1; j < n - 1; j++){
				if(arr[j] > arr[j + 1]){
					cout << "No" << '\n';
					return;
				}
			}
			n = pos - 1;
		}
	}
	cout << "Yes" << '\n';
}

int main()
{
		IOS
		int t{};
		cin >> t;
		while(t--)
		solve();
}


// Problem : C. Nastya and Strange Generator
// Contest : Codeforces - Codeforces Round #637 (Div. 2) - Thanks, Ivan Belonogov!
// URL : https://codeforces.com/contest/1341/problem/C
// Memory Limit : 0 MB
// Time Limit : 0 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define trace(x) cerr<<#x<<"is "<<x<<'\n';

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	int n{};
	cin >> n;
	vi pos(n + 1);
	for(int i = 1; i <= n; i++){
		int x{};
		cin >> x;
		pos[x] = i;
	}
	int finish{n};
	for(int i = 1; i <= n; i++){
		if(pos[i] == n - 1){
			finish--;
		} else {
			int ini = pos[i];
			int j = pos[i];
			for(; j <= finish && pos[i] == pos[i + 1] - 1 && i <= n; i++, j++){
			}
			if(j != finish){
				cout << "No" << '\n';
				return;
			}
			else{
				finish = ini - 1;
			}
		}
	}
	cout << "Yes" << '\n';
}

int main()
{
		IOS
		int t{};
		cin >> t;
		while(t--)
		solve();
}


// Problem : C. Nastya and Strange Generator
// Contest : Codeforces - Codeforces Round #637 (Div. 2) - Thanks, Ivan Belonogov!
// URL : https://codeforces.com/contest/1341/problem/C
// Memory Limit : 0 MB
// Time Limit : 0 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define trace(x) cerr<<#x<<"is "<<x<<'\n';

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	int n{};
	cin >> n;
	vi pos(n + 5);
	for(int i = 1; i <= n; i++){
		int x{};
		cin >> x;
		pos[x] = i;
	}
	int finish{n};
	for(int i = 1; i <= n; i++){
		if(pos[i] == n - 1){
			finish--;
		} else {
			int ini = pos[i];
			int j = pos[i];
			for(; j <= finish && pos[i] == pos[i + 1] - 1 && i < n; i++, j++){
			}
			if(j != finish){
				cout << "No" << '\n';
				return;
			}
			else{
				finish = ini - 1;
			}
		}
	}
	cout << "Yes" << '\n';
}

int main()
{
		IOS
		int t{};
		cin >> t;
		while(t--)
		solve();
}


/**
        *AUTHOR:Harsh Agrawal*
        *Birla Institute of Technology,Mesra*
**/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+1;
#define for0(i,e) for(ll i=0;i<e;i++)
#define forx(i,x,e) for(ll i=x;i<e;i++)
#define pb push_back
#define endl "\n"
#define in(a) cin>>a
#define out(a) cout>>a;
#define vll vector<ll>
#define vvll vector<vll>
#define qll queue<ll>
#define fastIO  ios_base::sync_with_stdio(0);\
                cin.tie(NULL);\
                cout.tie(NULL)

int main(){
	fastIO;
	ll t;cin>>t;
	while(t--){
		ll n;cin>>n;
		ll index;
		vll p(n+1);
		unordered_map<ll,ll> Hm;
		forx(i,1,n+1) {
			cin>>p[i];
			if(p[i]==1) index = i;
			Hm[p[i]] = i;
		}

		vll r(n+1);vll count(n+1,1);
		forx(i,1,n+1) r[i]=i;

        bool done = true;
        ll mx = 1;
        ll pmx = 1;
		vll ans(n+1,0);
		ans[index] = 1;
		count[index]=0;
		if(index==n) {r[index]=-1;}
		else {r[index] = r[index+1];count[r[index]]+=1; mx = 2; index = index +1;}

		for(ll i=2;i<=n;i++){
			if(i==2 && index!=Hm[i] && mx != pmx){
				cout<<"No"<<endl;
				done = false;
				break;
			}
			else if(mx == pmx){
				ans[Hm[i]] = i;
				if(Hm[i]==n){
					r[Hm[i]] = -1;
					count[Hm[i]] == 0;
					continue;
				}
	        	r[Hm[i]] = r[Hm[i]+1];
	        	if(r[Hm[i]]==-1){
	        		count[Hm[i]] = 0;
	        		continue;
	        	}
	        	count[r[Hm[i]]]+=1;
	        	count[Hm[i]] = 0;
	        	mx = count[r[Hm[i]]];
	        	index = r[Hm[i]];

		    }
		    else if(mx!=pmx){
		    	if(Hm[i] != index){
		    		cout<<"No"<<endl;
		    		done = false;
				    break;
		    	}
		    	else{
		    		ans[Hm[i]] = i;
		    		if(Hm[i]==n){
						r[Hm[i]] = -1;
						count[Hm[i]] == 0;
						mx = pmx;
						continue;
				    }
		        	r[Hm[i]] = r[Hm[i]+1];
		        	if(r[Hm[i]]==-1){
		        		count[Hm[i]] = 0;
		        		mx = pmx ;
		        		continue;
		        	}
		        	count[r[Hm[i]]]+=1;
		        	count[Hm[i]] = 0;
		        	mx = count[r[Hm[i]]];
		        	index = r[Hm[i]];

		    	}
		    }
		}

		if(done){
			cout<<"Yes"<<endl;
		}

	}

}


/**
        *AUTHOR:Harsh Agrawal*
        *Birla Institute of Technology,Mesra*
**/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+1;
#define for0(i,e) for(ll i=0;i<e;i++)
#define forx(i,x,e) for(ll i=x;i<e;i++)
#define ln "\n"
#define in(a) cin>>a
#define out(a) cout>>a;
#define vll vector<ll>
#define vvll vector<vll>
#define qll queue<ll>
#define fastIO  ios_base::sync_with_stdio(0);\
                cin.tie(NULL);\
                cout.tie(NULL)

ll n,m,a,b,c;

vll dijkstra(ll u, vvll &adList){
	vll spaths(n+1,LLONG_MAX);
	vector<bool> visited(n+1, false);
	spaths[u] = 0;
	qll q;
	q.push(u);
	while(!q.empty()){
		ll temp = q.front();
		q.pop();
		visited[temp] = true;
		for(auto v:adList[temp]){
			if(!visited[v]){
				spaths[v] = min(spaths[v],spaths[temp]+1);
				q.push(v);
			}
		}
	}
	return spaths;
}
ll dfs_b(ll u,vector<bool> &v,vvll &adList,ll d){
	//if(u==a) d=0;
	if(u==b) return d;
	v[u] = true;
	ll mn = LLONG_MAX;
	for(auto x:adList[u]){
		if(!v[x]) mn  = min(mn, dfs_b(x,v,adList,d+1));
	}
	return mn;
 }

ll dfs_c(ll u,vector<bool> &v,vvll &adList,ll d){
	if(u==a) d=0;
	if(u==c) return d;
	v[u] = true;
	ll mn = LLONG_MAX;
	for(auto x:adList[u]){
		if(!v[x]) mn  = min(mn, dfs_c(x,v,adList,d+1));
	}
	return mn;
}

int main(){
	fastIO;
	ll t;cin>>t;
	while(t--){
		ll n;cin>>n;
		vll arr(n+1);
		vll ans(n+1,0);
		unordered_map<ll,ll> HashMap;
		forx(i,1,n+1) {cin>>arr[i];HashMap[arr[i]]=i;}

        bool done = true;
        ll next = 0;
		for(ll i=1;i<=n;i++){
			if(next==0){
				if(ans[HashMap[i]]!=0){
					done = false;
					break;
				}
				next = HashMap[i]+1;
				ans[HashMap[i]] = i;
				if(next>n || ans[next]!=0)
					next = 0;
				continue;
			}
			if(next==n){
				if(HashMap[i] != next){
					done=false;
					break;
				} else{
					if(ans[HashMap[i]!=0]){
						done = false;
						break;
					}
					ans[HashMap[i]] = i;
					next = HashMap[i]+1;
					if(next>n || ans[next]!=0) next = 0;
					continue;
				}
			}
			else{
				if(HashMap[i]!=next)
				{
					done = false;
					break;

				} else{
					if(ans[HashMap[i]]!=0){
						done = false;
						break;
					}
					ans[HashMap[i]] = i;
					next = HashMap[i]+1;
					if(next>n || ans[next]!=0)
						next = 0;
					continue;
				}
		}
	}

	//for0(i,n+1) cout<<ans[i]<<" ";
	if(done) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	}

}


/**
        *AUTHOR:Harsh Agrawal*
        *Birla Institute of Technology,Mesra*
**/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+1;
#define for0(i,e) for(ll i=0;i<e;i++)
#define forx(i,x,e) for(ll i=x;i<e;i++)
#define pb push_back
#define endl "\n"
#define in(a) cin>>a
#define out(a) cout>>a;
#define vll vector<ll>
#define vvll vector<vll>
#define qll queue<ll>
#define fastIO  ios_base::sync_with_stdio(0);\
                cin.tie(NULL);\
                cout.tie(NULL)

int main(){
	fastIO;
	ll t;cin>>t;
	while(t--){
		ll n;cin>>n;
		ll index;
		vll p(n+1);
		unordered_map<ll,ll> Hm;
		forx(i,1,n+1) {
			cin>>p[i];
			if(p[i]==1) index = i;
			Hm[p[i]] = i;
		}

		vll r(n+1);vll count(n+1,1);
		forx(i,1,n+1) r[i]=i;

        bool done = true;
        ll mx = 1;
        ll pmx = 1;
		vll ans(n+1,0);
		ans[index] = 1;
		count[index]=0;
		if(index==n) {r[index]=-1;}
		else {r[index] = r[index+1];count[r[index]]+=1; mx = 2; index = index +1;}

		for(ll i=2;i<=n;i++){
			if(i==2 && index!=Hm[i] && mx != pmx){
				cout<<"No"<<endl;
				done = false;
				break;
			}
			else if(mx == pmx){
				ans[Hm[i]] = i;
	        	r[Hm[i]] = r[Hm[i]+1];
	        	if(r[Hm[i]]==-1){
	        		count[Hm[i]] = 0;
	        		continue;
	        	}
	        	count[r[Hm[i]]]+=1;
	        	count[Hm[i]] = 0;
	        	mx = count[r[Hm[i]]];
	        	index = r[Hm[i]];

		    }
		    else if(mx!=pmx){
		    	if(Hm[i] != index){
		    		cout<<"No"<<endl;
		    		done = false;
				    break;
		    	}
		    	else{
		    		ans[Hm[i]] = i;
		        	r[Hm[i]] = r[Hm[i]+1];
		        	if(r[Hm[i]]==-1){
		        		count[Hm[i]] = 0;
		        		mx = pmx ;
		        		continue;
		        	}
		        	count[r[Hm[i]]]+=1;
		        	count[Hm[i]] = 0;
		        	mx = count[r[Hm[i]]];
		        	index = r[Hm[i]];

		    	}
		    }
		}

		if(done){
			cout<<"Yes"<<endl;
		}

	}

}


/**
        *AUTHOR:Harsh Agrawal*
        *Birla Institute of Technology,Mesra*
**/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+1;
#define for0(i,e) for(ll i=0;i<e;i++)
#define forx(i,x,e) for(ll i=x;i<e;i++)
#define pb push_back
#define endl "\n"
#define in(a) cin>>a
#define out(a) cout>>a;
#define vll vector<ll>
#define vvll vector<vll>
#define qll queue<ll>
#define fastIO  ios_base::sync_with_stdio(0);\
                cin.tie(NULL);\
                cout.tie(NULL)

int main(){
	fastIO;
	ll t;cin>>t;
	while(t--){
		ll n;cin>>n;
		ll index;
		vll p(n+1);
		unordered_map<ll,ll> Hm;
		forx(i,1,n+1) {
			cin>>p[i];
			if(p[i]==1) index = i;
			Hm[p[i]] = i;
		}

		vll r(n+1);vll count(n+1,1);
		forx(i,1,n+1) r[i]=i;

        bool done = true;
        ll mx = 1;
        ll pmx = 1;
		vll ans(n+1,0);
		ans[index] = 1;
		count[index]=0;
		if(index==n) {r[index]=-1;}
		else {r[index] = r[index+1];count[r[index]]+=1; mx = 2; index = index +1;}

		for(ll i=2;i<=n;i++){
			if(i==2 && index!=Hm[i] && mx != pmx){
				cout<<"No"<<endl;
				done = false;
				break;
			}
			else if(mx == pmx){
				ans[Hm[i]] = i;
				if(Hm[i]==n){
					r[Hm[i]] = -1;
					count[Hm[i]] = 0;
					continue;
				}
	        	r[Hm[i]] = r[Hm[i]+1];
	        	if(r[Hm[i]]==-1){
	        		count[Hm[i]] = 0;
	        		continue;
	        	}
	        	count[r[Hm[i]]]+=1;
	        	count[Hm[i]] = 0;
	        	mx = count[r[Hm[i]]];
	        	index = r[Hm[i]];

		    }
		    else if(mx!=pmx){
		    	if(Hm[i] != index){
		    		cout<<"No"<<endl;
		    		done = false;
				    break;
		    	}
		    	else{
		    		ans[Hm[i]] = i;
		    		if(Hm[i]==n){
						r[Hm[i]] = -1;
						count[Hm[i]] = 0;
						mx = pmx;
						continue;
				    }
		        	r[Hm[i]] = r[Hm[i]+1];
		        	if(r[Hm[i]]==-1){
		        		count[Hm[i]] = 0;
		        		mx = pmx ;
		        		continue;
		        	}
		        	count[r[Hm[i]]]+=1;
		        	count[Hm[i]] = 0;
		        	mx = count[r[Hm[i]]];
		        	index = r[Hm[i]];

		    	}
		    }
		}

		if(done){
			cout<<"Yes"<<endl;
		}

	}

}


/**
        *AUTHOR:Harsh Agrawal*
        *Birla Institute of Technology,Mesra*
**/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+1;
#define for0(i,e) for(ll i=0;i<e;i++)
#define forx(i,x,e) for(ll i=x;i<e;i++)
#define pb push_back
#define endl "\n"
#define in(a) cin>>a
#define out(a) cout>>a;
#define vll vector<ll>
#define vvll vector<vll>
#define qll queue<ll>
#define fastIO  ios_base::sync_with_stdio(0);\
                cin.tie(NULL);\
                cout.tie(NULL)

int main(){
	fastIO;
	ll t;cin>>t;
	while(t--){
		ll n;cin>>n;
		ll index;
		vll p(n+1);
		unordered_map<ll,ll> Hm;
		forx(i,1,n+1) {
			cin>>p[i];
			if(p[i]==1) index = i;
			Hm[p[i]] = i;
		}

		vll r(n+1);vll count(n+1,1);
		forx(i,1,n+1) r[i]=i;

        bool done = true;
        ll mx = 1;
        ll pmx = 1;
		vll ans(n+1,0);
		ans[index] = 1;
		count[index]=0;
		if(index==n) {r[index]=-1;}
		else {r[index] = r[index+1];count[r[index]]+=1; mx = 2; index = index +1;}

		for(ll i=2;i<=n;i++){
			if(i==2 && index!=Hm[i] && mx != pmx){
				cout<<"No"<<endl;
				done = false;
				break;
			}
			else if(mx == pmx){
				ans[Hm[i]] = i;
				if(Hm[i]==n){
					r[Hm[i]] = -1;
					count[Hm[i]] = 0;
					continue;
				}
	        	r[Hm[i]] = r[Hm[i]+1];
	        	if(r[Hm[i]]==-1){
	        		count[Hm[i]] = 0;
	        		continue;
	        	}
	        	count[r[Hm[i]]]+=1;
	        	count[Hm[i]] = 0;
	        	mx = count[r[Hm[i]]];
	        	index = r[Hm[i]];

		    }
		    else if(mx!=pmx){
		    	if(Hm[i] != index){
		    		cout<<"No"<<endl;
		    		done = false;
				    break;
		    	}
		    	else{
		    		ans[Hm[i]] = i;
		    		if(Hm[i]==n){
						r[Hm[i]] = -1;
						count[Hm[i]] = 0;
						mx = pmx;
						continue;
				    }
		        	r[Hm[i]] = r[Hm[i]+1];
		        	if(r[Hm[i]]==-1){
		        		count[Hm[i]] = 0;
		        		mx = pmx ;
		        		continue;
		        	}
		        	count[r[Hm[i]]]+=1;
		        	count[Hm[i]] = 0;
		        	mx = count[r[Hm[i]]];
		        	index = r[Hm[i]];

		    	}
		    }
		}

		for0(i,n+1) cout<<ans[i]<<" ";
		cout<<endl;

		if(done){
			cout<<"Yes"<<endl;
		}

	}

}


#include <map>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define mp make_pair

typedef long long ll ;
typedef pair<int , int> PII;

const int N=1e5+10;
ll Ldp[N] , LdpB[N] , Rdp[N] , RdpB[N] , n , B[N] , ans;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> n ;

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

	for(int i=1 ; i<n ; i++)
	{
		Ldp[i]= B[i]-((B[i]+1)&1) + Ldp[i-1];
		LdpB[i] = B[i] - (B[i]&1) + LdpB[i-1];

		Rdp[n-1-i] = B[n-i]-((B[n-i]+1)&1) + Rdp[n-i];
		RdpB[n-1-i] = B[n-i] - (B[n-i]&1) + RdpB[n-i];

		Ldp[i] = max(Ldp[i] , LdpB[i]);
		Rdp[n-1-i] = max(Rdp[n-1-i] , RdpB[n-i-1]);
	}

	for(int i=0 ; i<n ; i++)
		ans = max(ans , max(RdpB[i]+Ldp[i] , LdpB[i]+Rdp[i]));

	cout << ans ;

	return 0;
}


#include <map>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define mp make_pair

typedef long long ll ;
typedef pair<int , int> PII;

const int N=1e5+10;
ll Ldp[N] , LdpB[N] , Rdp[N] , RdpB[N] , n , B[N] , ans;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> n ;

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

	for(int i=1 ; i<n ; i++)
	{
		Ldp[i]= B[i]-((B[i]+1)&1) + Ldp[i-1];

		if(B[i] - (B[i]&1) > 0)
		LdpB[i] = B[i] - (B[i]&1) + LdpB[i-1];

		Rdp[n-1-i] = B[n-i]-((B[n-i]+1)&1) + Rdp[n-i];

		if(B[n-i] - (B[n-i]&1) > 0)
		RdpB[n-1-i] = B[n-i] - (B[n-i]&1) + RdpB[n-i];

		Ldp[i] = max(Ldp[i] , LdpB[i]);
		Rdp[n-1-i] = max(Rdp[n-1-i] , RdpB[n-i-1]);
	}

	for(int i=0 ; i<n ; i++)
		ans = max(ans , max(RdpB[i]+Ldp[i] , LdpB[i]+Rdp[i]));

	cout << ans ;

	return 0;
}


/*
<3 <3 <3 Rose <3 <3 <3

BLACKPINK!
Ah yeah, ay yeah!
BLACKPINK!b
Ah yeah, ay yeah!

[Verse 1: Jennie]
Chakan eolgure geureochi mothan taedo
Ganyeorin mommae sok garyeojin volumeeun du baero
Geochimeopsi jikjin guji bojin anchi nunchi
Black hamyeon Pink urin yeppeujanghan Savage

[Verse 2: Lisa]
Wonhal ttaen daenoko ppaetji
Neon mwol haedo kallo mul begi
Du sonen gadeukan fat check
Gunggeumhamyeon haebwa fact check
Nun nopin kkokdaegi
Mul mannan mulgogi
Jom dokae nan Toxic
You hokae I`m Foxy

[Pre-Chorus: Rosé & Jisoo]
Du beon saenggakae
Heunhan namdeulcheoreom chakan cheogeun mot hanikka
Chakgakaji ma
Swipge useojuneun geon nal wihan geoya
Ajigeun jal moreugetji
Guji wonhamyeon test me
Neon bul bodeusi ppeonhae
Manmanhan geol wonhaetdamyeon

[Chorus: Jennie]
Oh wait til’ I do what I (do)
Hit you with that ddu-du ddu-du du (Ah yeah, ay yeah!)
Hit you with that ddu-du ddu-du du (Ah yeah, ay yeah!)

[Verse 3: Jennie]
BLACKPINK
Jigeum naega georeoganeun georin
BLACKPINK 4 way sageori
Dongseonambuk sabangeuro run it
Need a bucket list ssak da I bought it
Neol danggineun geotdo meolli milchineun geotdo
Jemeotdaero haneun bad girl
Jokeon sileohageon nuga mwora hadeon
When the bass drop it’s another banger

[Pre-Chorus: Jisoo & Rosé]
Du beon saenggakae
Heunhan namdeulcheoreom chakan cheogeun mot hanikka
Chakgakaji ma
Swipge useojuneun geon nal wihan geoya
Ajigeun jal moreugetji
Guji wonhamyeon test me
Neon bul bodeusi ppeonhae
Manmanhan geol wonhaetdamyeon

[Chorus: Jennie & Lisa]
Oh wait til’ I do what I (do)
Hit you with that ddu-du ddu-du du (Ah yeah, ay yeah!)
Hit you with that ddu-du ddu-du du (Ah yeah, ay yeah!)

[Bridge: Rosé & Lisa]
What you gonna do when I
Come come through with that that uh uh huh
What you gonna do when I
Come come through with that that uh uh huh
Tteugeowo tteugeowo tteugeowo like fire
Tteugeowo tteugeowo tteugeowo like fire

[Drop: All, Jisoo & Rosé]
BLACKPINK! Hey!
Ah yeah, ay yeah! Ah yeah, ay yeah!
Tteugeowo tteugeowo tteugeowo like fire
Tteugeowo tteugeowo tteugeowo like fire

[Outro: Jennie]
Hit you with that ddu-du ddu-du du
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define foreach(it, v) for(auto it=(v).begin(); it != (v).end(); ++it)
#define gcd(a,b) __gcd(a,b)
#define ld long double
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define int long long
#define ull unsigned long long
#define pii pair<int,int>
#define vii vector<int>
#define fi first
#define se second
#define all(container) container.begin(), container.end()
#define onlyunique(v) v.erase(unique(all(v)), v.end());
#define endl '\n'
#define print(array, n)    for(int macro_i = 0; macro_i < n; macro_i ++) {cout << array[macro_i] << " ";}cout << "\n";

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define filewr() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

using namespace std;

int power(int x, int y, int mod = 2e18) { int ans = 1; x %= mod; while (y) {if (y & 1)ans = (x * ans) % mod; x = (x * x) % mod; y >>= 1;} return ans;}
int modinv(int a, int m) {return power(a, m - 2, m);}
ll modI(ll a, ll m){ll m0=m,y=0,x=1;if(m==1) return 0;while(a>1){ll q=a/m;ll t=m;m=a%m;a=t;t=y;y=x-q*y;x=t;}if(x<0) x+=m0;return x;}

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

const ld PI = 3.1415926535897932384626433832795;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;  // find_by_order(x)[xth element in the set counting from zero] ,
																									//	order_of_key(x) [no of elements strictly smaller than x]
const int N = 1e5 + 7;
int a[N], mid[N], leftt[N], rightt[N], jmp[N];

void solve(){

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

	for(int i=2;i<=n;i++)mid[i] = mid[i-1] + (a[i]%2==1 ? a[i] : a[i]-1);
	for(int i=2;i<=n;i++){
		if(a[i]==1)leftt[i] = 0;
		else leftt[i] = leftt[i-1] + (a[i]%2==0 ? a[i] : a[i]-1);
	}
	for(int i=n-1;i>=1;i--){
		if(a[i+1]==1)rightt[i]=0;
		else rightt[i] = rightt[i+1] + (a[i+1]%2==0 ? a[i+1] : a[i+1]-1);
	}

	// int cur = 0;
	// int mx = 0, mxi = n;

	// for(int i=n-1;i>=1;i--){
	// 	cur += (a[i+1]%2==0 ? 1 : -1);
	// 	if(mx < cur){
	// 		mx = cur;
	// 		mxi = i;
	// 	}
	// 	jmp[i] = mxi;
	// 	// tr(i,cur);
	// 	if(cur<0)cur = 0;
	// }

	// for(int i=1;i<n;i++){
	// 	cout << jmp[i] << " ";
	// }
	// cout << endl;

	int ans = 0, val = 0;

	for(int i=1;i<=n;i++){
		// tr(i,jmp[i],mid[jmp[i]],mid[i],leftt[i],rightt[jmp[i]]);
		// ans = max(ans, leftt[i] + mid[jmp[i]]-mid[i] + rightt[jmp[i]]);
		// tr(ans);
		ans = max(ans, mid[i]+rightt[i] + val);
		val = max(val, leftt[i]-mid[i]);
	}

	cout << ans << endl;

}

signed main(){
	fastio();
	int t = 1;
	// cin >> t;

	while(t--){
		solve();
	}

	return 0;
}


// I can't live in a fairytale of Lies
// But
// I can live in the fairytale of Life

#include<bits/stdc++.h>

#define s second
#define f first
#define pb push_back
#define int ll
#define D(x) cerr<<#x<<": "<<x<<endl
#define D2(x) cerr<<#x<<": "<<x<<ends
#define mid ((l+r) >> 1)
#define lc (id << 1)
#define rc ((id << 1) + 1)
#define lb(x) ((x) & -(x))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int> > vii;

const int MAX=2e5+10,mod=1e9+7,base=142,INF=999999999,sq=502;

int n,a[MAX],dp[2][2][MAX];

main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i=0;i<n-1;i++) cin >> a[i];
    for(int i=1;i<n;i++){
        if(a[i-1] != 1) dp[0][0][i] = dp[0][0][i-1] + a[i-1] - (a[i-1] & 1);
        dp[0][1][i] = max(dp[0][0][i-1], dp[0][1][i-1]) + a[i-1] - 1 + (a[i-1] & 1);
    }
    for(int i=n-2;i>=0;i--){
        if(a[i+1] != 1) dp[1][0][i] = dp[1][0][i+1] + a[i+1] - (a[i+1] & 1);
        dp[1][1][i] = max(dp[1][0][i+1], dp[1][1][i+1]) + a[i+1] - 1 + (a[i+1] & 1);
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        int x = dp[0][0][i], y = dp[0][1][i], z = dp[1][0][i], t = dp[1][1][i];
        ans = max(ans, max(x+z, max(x+t, max(y+z, y+t))));
    }
    cout << ans;
    return -0;
}


// I can't live in a fairytale of Lies
// But
// I can live in the fairytale of Life

#include<bits/stdc++.h>

#define s second
#define f first
#define pb push_back
#define int ll
#define D(x) cerr<<#x<<": "<<x<<endl
#define D2(x) cerr<<#x<<": "<<x<<ends
#define mid ((l+r) >> 1)
#define lc (id << 1)
#define rc ((id << 1) + 1)
#define lb(x) ((x) & -(x))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int> > vii;

const int MAX=2e5+10,mod=1e9+7,base=142,INF=999999999,sq=502;

int n,a[MAX],dp[2][2][MAX];

main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i=0;i<n-1;i++) cin >> a[i];
    for(int i=1;i<n;i++){
        if(a[i-1] != 1) dp[0][0][i] = dp[0][0][i-1] + a[i-1] - (a[i-1] & 1);
        dp[0][1][i] = max(dp[0][0][i-1], dp[0][1][i-1]) + a[i-1] - 1 + (a[i-1] & 1);
    }
    for(int i=n-2;i>=0;i--){
        if(a[i] != 1) dp[1][0][i] = dp[1][0][i+1] + a[i] - (a[i] & 1);
        dp[1][1][i] = max(dp[1][0][i+1], dp[1][1][i+1]) + a[i] - 1 + (a[i] & 1);
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        int x = dp[0][0][i], y = dp[0][1][i], z = dp[1][0][i], t = dp[1][1][i];
        ans = max(ans, max(x+z, max(x+t, max(y+z, y+t))));
    }
    cout << ans;
    return -0;
}


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

typedef long long ll;
typedef long double ld;
//#define int ll
//#define endl '\n'

const int N=100100;
int dp[N][3];
int a[N],n;
main(){
	cin.tie(0);cin.sync_with_stdio(0);
	cin>>n;
	for(int i=0;i<n-1;++i)cin>>a[i];
	for(int i=0;i<n;++i){
		dp[i][1]=max(dp[i][1],dp[i][0]);
		dp[i][2]=max(dp[i][2],dp[i][1]);
		dp[i+1][0]=max(dp[i+1][0],dp[i][0]+a[i]-a[i]%2);
		dp[i+1][1]=max(dp[i+1][1],dp[i][1]+a[i]-!(a[i]%2));
		dp[i+1][2]=max(dp[i+1][2],dp[i][2]+a[i]-a[i]%2);
	}
	int res=0;
	for(int i=0;i<=n;++i)res=max(res,dp[i][2]);
	cout<<res<<endl;
}


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

typedef long long ll;
typedef long double ld;
//#define int ll
//#define endl '\n'

const int N=100100;
ll dp[N][3];
ll a[N],n;
main(){
	cin.tie(0);cin.sync_with_stdio(0);
	cin>>n;
	for(int i=0;i<n-1;++i)cin>>a[i];
	for(int i=0;i<n;++i){
		dp[i][1]=max(dp[i][1],dp[i][0]);
		dp[i][2]=max(dp[i][2],dp[i][1]);
		if(a[i]){
			dp[i+1][0]=max(dp[i+1][0],dp[i][0]+a[i]-a[i]%2);
			dp[i+1][1]=max(dp[i+1][1],dp[i][1]+a[i]-!(a[i]%2));
			dp[i+1][2]=max(dp[i+1][2],dp[i][2]+a[i]-a[i]%2);
		}
	}
	ll res=0;
	for(int i=0;i<=n;++i)res=max(res,dp[i][2]);
	cout<<res<<endl;
}


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

typedef long long ll;
typedef long double ld;
//#define int ll
//#define endl '\n'

const int N=100100;
ll dp[N][3];
ll a[N],n;
main(){
	cin.tie(0);cin.sync_with_stdio(0);
	cin>>n;
	for(int i=0;i<n-1;++i)cin>>a[i];
	for(int i=0;i<n;++i){
		dp[i][1]=max(dp[i][1],dp[i][0]);
		dp[i][2]=max(dp[i][2],dp[i][1]);
		if(a[i]>=2)dp[i+1][0]=max(dp[i+1][0],dp[i][0]+a[i]-a[i]%2);
		if(a[i]>=1)dp[i+1][1]=max(dp[i+1][1],dp[i][1]+a[i]-!(a[i]%2));
		if(a[i]>=2)dp[i+1][2]=max(dp[i+1][2],dp[i][2]+a[i]-a[i]%2);
	}
	ll res=0;
	for(int i=0;i<=n;++i)res=max(res,dp[i][2]);
	cout<<res<<endl;
}


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

typedef long long ll;
typedef long double ld;
//#define int ll
//#define endl '\n'

const int N=100100;
ll dp[N][3];
ll a[N],n;
main(){
	cin.tie(0);cin.sync_with_stdio(0);
	cin>>n;
	for(int i=0;i<n-1;++i)cin>>a[i];
	for(int i=0;i<n;++i){
		dp[i][1]=max(dp[i][1],dp[i][0]);
		dp[i][2]=max(dp[i][2],dp[i][1]);
		dp[i+1][0]=max(dp[i+1][0],dp[i][0]+a[i]-a[i]%2);
		dp[i+1][1]=max(dp[i+1][1],dp[i][1]+a[i]-!(a[i]%2));
		dp[i+1][2]=max(dp[i+1][2],dp[i][2]+a[i]-a[i]%2);
	}
	ll res=0;
	for(int i=0;i<=n;++i)res=max(res,dp[i][2]);
	cout<<res<<endl;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author parsa bahrami
 */

#pragma GCC optimize("O2")

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;

#define sz(x)                       (ll) x.size()
#define PB(x)                       push_back(x)
#define bs(a, x)                   binary_search(a , a + sizeof(a) / sizeof(a[0] , x)
#define ts(x)                       to_string(x)
#define jjoin(x)                    for (auto i : x) cout << i << endl;
#define all(x)                      (x).begin(),(x).end()
#define bsv(a, x)                  binary_search(all(a), x)
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define kill(x)                     return cout << x << endl , 0;
#define endl                        '\n'

inline ll input() {
    ll n;
    cin >> n;
    return n;
}

ll poww(ll a, ll b, ll 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 MAXN = 2e5 + 10;
const ll MAXA = 101;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
const ld PI = 4 * atan((ld) 1);
ll dp[MAXN][2], DP[MAXN][2], a[MAXN];

int main() {
    fast_io;
    set_random;
    ll n;
    cin >> n;
    for (ll i = 0; i < n - 1; i++) {
        cin >> a[i];
    }
    dp[0][0] = 0, dp[0][1] = 0;
    for (ll i = 1; i < n; i++) {
        if (a[i - 1] == 1) {
            dp[i][0] = 0;
            dp[i][1] = max(dp[i - 1][0] + 1, dp[i - 1][1] + 1);
        }
        if (a[i - 1] & 1) {
            dp[i][1] = a[i - 1] + max(dp[i - 1][0], dp[i - 1][1]);
            dp[i][0] = dp[i - 1][0] + a[i - 1] - 1;
        } else {
            dp[i][1] = max(a[i - 1] - 1 + dp[i - 1][1], a[i - 1] + dp[i - 1][0]);
            dp[i][0] = max(a[i - 1] + dp[i - 1][0], dp[i][0]);
        }
    }
    DP[0][0] = 0, DP[0][1] = 0;
    for (ll i = n - 2; i >= 0; i--) {
        if (a[i - 1] == 1) {
            DP[i][0] = 0;
            DP[i][1] = max(DP[i + 1][0] + 1, DP[i + 1][1] + 1);
        }
        if (a[i - 1] & 1) {
            DP[i][1] = a[i] + max(DP[i + 1][0], DP[i + 1][1]);
            DP[i][0] = DP[i + 1][0] + a[i] - 1;
        } else {
            DP[i][1] = max(a[i] - 1 + DP[i + 1][1], a[i] + DP[i + 1][0]);
            DP[i][0] = max(a[i] + DP[i + 1][0], DP[i][0]);
        }
    }
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        ans = max({ans , dp[i][0] + DP[i][0] , dp[i][0] + DP[i][1] , DP[i][0] + dp[i][1]});
    }
    cout << ans << endl;
    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author parsa bahrami
 */

#pragma GCC optimize("O2")

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;

#define sz(x)                       (ll) x.size()
#define PB(x)                       push_back(x)
#define bs(a, x)                   binary_search(a , a + sizeof(a) / sizeof(a[0] , x)
#define ts(x)                       to_string(x)
#define jjoin(x)                    for (auto i : x) cout << i << endl;
#define all(x)                      (x).begin(),(x).end()
#define bsv(a, x)                  binary_search(all(a), x)
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define kill(x)                     return cout << x << endl , 0;
#define endl                        '\n'

inline ll input() {
    ll n;
    cin >> n;
    return n;
}

ll poww(ll a, ll b, ll 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 MAXN = 2e5 + 10;
const ll MAXA = 101;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
const ld PI = 4 * atan((ld) 1);
ll dp[MAXN][2], DP[MAXN][2], a[MAXN];

int main() {
    fast_io;
    set_random;
    ll n;
    cin >> n;
    for (ll i = 0; i < n - 1; i++) {
        cin >> a[i];
    }
    dp[0][0] = 0, dp[0][1] = 0;
    for (ll i = 1; i < n; i++) {
        if (a[i - 1] == 1) {
            dp[i][0] = 0;
            dp[i][1] = max(dp[i - 1][0] + 1, dp[i - 1][1] + 1);
        }
        if (a[i - 1] & 1) {
            dp[i][1] = a[i - 1] + max(dp[i - 1][0], dp[i - 1][1]);
            dp[i][0] = dp[i - 1][0] + a[i - 1] - 1;
        } else {
            dp[i][1] = max(a[i - 1] - 1 + dp[i - 1][1], a[i - 1] + dp[i - 1][0]);
            dp[i][0] = max(a[i - 1] + dp[i - 1][0], dp[i][0]);
        }
    }
    DP[0][0] = 0, DP[0][1] = 0;
    for (ll i = n - 2; i >= 0; i--) {
        if (a[i] == 1) {
            DP[i][0] = 0;
            DP[i][1] = max(DP[i + 1][0] + 1, DP[i + 1][1] + 1);
        }
        if (a[i] & 1) {
            DP[i][1] = a[i] + max(DP[i + 1][0], DP[i + 1][1]);
            DP[i][0] = DP[i + 1][0] + a[i] - 1;
        } else {
            DP[i][1] = max(a[i] - 1 + DP[i + 1][1], a[i] + DP[i + 1][0]);
            DP[i][0] = max(a[i] + DP[i + 1][0], DP[i][0]);
        }
    }
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        ans = max({ans , dp[i][0] + DP[i][0] , dp[i][0] + DP[i][1] , DP[i][0] + dp[i][1]});
    }
    cout << ans << endl;
    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author parsa bahrami
 */

#pragma GCC optimize("O2")

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;

#define sz(x)                       (ll) x.size()
#define PB(x)                       push_back(x)
#define bs(a, x)                   binary_search(a , a + sizeof(a) / sizeof(a[0] , x)
#define ts(x)                       to_string(x)
#define jjoin(x)                    for (auto i : x) cout << i << endl;
#define all(x)                      (x).begin(),(x).end()
#define bsv(a, x)                  binary_search(all(a), x)
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define kill(x)                     return cout << x << endl , 0;
#define endl                        '\n'

inline ll input() {
    ll n;
    cin >> n;
    return n;
}

ll poww(ll a, ll b, ll 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 MAXN = 2e5 + 10;
const ll MAXA = 101;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
const ld PI = 4 * atan((ld) 1);
ll dp[MAXN][2], DP[MAXN][2], a[MAXN];

int main() {
    fast_io;
    set_random;
    ll n;
    cin >> n;
    for (ll i = 0; i < n - 1; i++) {
        cin >> a[i];
    }
    dp[0][0] = 0, dp[0][1] = 0;
    for (ll i = 1; i < n; i++) {
        if (a[i - 1] == 1) {
            dp[i][0] = 0;
            dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + 1;
        }
        else if (a[i - 1] & 1) {
            dp[i][1] = a[i - 1] + max(dp[i - 1][0], dp[i - 1][1]);
            dp[i][0] = dp[i - 1][0] + a[i - 1] - 1;
        } else {
            dp[i][1] = max(a[i - 1] - 1 + dp[i - 1][1], a[i - 1] + dp[i - 1][0]);
            dp[i][0] = a[i - 1] + dp[i - 1][0];
        }
    }
    //cout << dp[5][0] << " " << dp[5][1] << endl;
    DP[n - 1][0] = 0, DP[n - 1][1] = 0;
    for (ll i = n - 2; i >= 0; i--) {
        if (a[i] == 1) {
            DP[i][0] = 0;
            DP[i][1] = max(DP[i + 1][0] + 1, DP[i + 1][1] + 1);
        }
        else if (a[i] & 1) {
            DP[i][1] = a[i] + max(DP[i + 1][0], DP[i + 1][1]);
            DP[i][0] = DP[i + 1][0] + a[i] - 1;
        } else {
            DP[i][1] = max(a[i] - 1 + DP[i + 1][1], a[i] + DP[i + 1][0]);
            DP[i][0] = a[i] + DP[i + 1][0];
        }
    }
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        ans = max({ans , dp[i][0] + DP[i][0] , dp[i][0] + DP[i][1] , DP[i][0] + dp[i][1]});
    }
    cout << ans << endl;
    return 0;
}


/*     !ya khoda!     */
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define ld long double

#define pp push
#define po pop()
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()
#define I insert
#define E erase

#define F first
#define S second

#define mkp make_pair
#define pll pair<ll,ll>
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define all(a) a.begin(),a.end()

#define coutghat(x)      cout<<tolower(x);
#define coutashar(x,d)   cout<<fixed<<setprecision(x)<<(ld)d
#define IOS ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)
//#define poow(a,b,M)   b?(poow((a*a)%M,b/2)%M * (b&1?a))%M:1 ;
/*==========================================================================*/
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll poow(ll x,ll n,ll Mod=1e9+7) { return (n==0?1:poow(x*x%Mod,n/2)*(n&1?x:1)%Mod); }
//#pragma optimize O3
// 107,109, 211,223, 307, 401,409, 503,509, 601,607, 701,709, 809, 907, 1009
/*==========================================================================*/
const int N=1e5+100 , M=1e4+100 , LG=23 , base=2;
const int mod=1e9+7 , MOD=1e9+9;
const ll  INF=1e9   , inf=1e18 , super_inf=~0ull/4;
ll n,a[N] , dp[N],pd[N] , cnt,ans;
/*==========================================================================*/
int main()
{
	IOS;
	cin>>n;
	for(int i=1;i<n;i++)   cin>>a[i];

	for(int i=n-1;i>0;i--)
    {
		pd[i]=pd[i+1] + a[i]-(a[i]&1);
		if(a[i]==1)     pd[i]=0;
	}

	dp[0]=0;
	for(int i=1;i<n;i++)
    {
		cnt += a[i]-(a[i]&1);
		if(a[i]==1)    cnt=0;
		dp[i] = max(   dp[i-1] + a[i]-(a[i]%2==0)   ,   cnt   );
		ans = max( ans , dp[i]+pd[i+1] );
	}

	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

const int MAXN = 1e5 + 7;

int n;
int a[MAXN];
void read() {
    cin >> n;
    for (int i = 0; i < n - 1; ++i) cin >> a[i];
}

int ans = 0;
int l[MAXN], r[MAXN];
int pref[MAXN];
void solve() {
    l[0] = 0;
    for (int i = 1; i < n; ++i) {
        if (a[i - 1] == 1) l[i] = 0;
        else l[i] = l[i - 1] + ((a[i - 1] >> 1) << 1);
    }

    r[n - 1] = 0;
    for (int i = n - 2; i >= 0; --i) {
        if (a[i] == 1) r[i] = 0;
        else r[i] = r[i + 1] + ((a[i] >> 1) << 1);
    }

    pref[0] = 0;
    for (int i = 1; i < n; ++i) {
        int t = a[i - 1] - 1;
        pref[i] = pref[i - 1] + 1 + ((t >> 1) << 1);
    }

    int best = -1;
    for (int i = 0; i < n; ++i) {
        best = max(best, l[i] - pref[i]);
        ans = max(ans, best + pref[i] + r[i]);
    }
}

void print() {
    cout << ans << '\n';
}

signed main() {
    //freopen("input.txt", "r", stdin);

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    read();
    solve();
    print();

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N = 1e5 + 8;
long long a[N] , n , rdp[N] , dp[N] , t , ans;

int main()
{
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	cin >> n;
	for(int i = 1 ; i < n ; i++)
		cin >> a[i];
	for(int i = n - 1 ; i > 0 ; i--)
	{
		rdp[i] = rdp[i + 1] + (a[i] - (a[i] % 2));
		if(a[i] == 1)
			rdp[i] = 0;
	}
	for(int i = 0 ; i < n ; i++)
	{
		t += (a[i] - (a[i] % 2));
		if(a[i] == 1)
			t = 0;
		dp[i] = max(t , dp[i - 1] + a[i] - (!(a[i] % 2)));
	}
	for(int i = 1 ; i < n ; i++)
		ans = max(ans , dp[i] + rdp[i + 1]);
	cout << ans;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n;
ll a[100005];
ll x[100005];
ll y[100005];
ll odd[100005];
ll evenp(ll x)
{
        if(x%2 == 0) return x;
        return x-1;
}
ll oddp(ll x)
{
        if(x%2 == 1) return x;
        return x-1;
}
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        cin >> n;
        for(ll i=1;i<n;i++) {
                cin >> a[i];
                odd[i+1] = odd[i] + oddp(a[i]);
        }
        for(ll i=2;i<=n;i++) {
                if(a[i-1] == 1) {
                        x[i] = 0; continue;
                }else {
                        x[i] = evenp(a[i-1]) + x[i-1];
                }
        }
        for(ll i = n-1 ; i >= 1 ;i--) {
                if(a[i] == 1) {
                        y[i] = 0; continue;
                }else {
                        y[i] = evenp(a[i]) + y[i+1];
                }
        }
        ll maxm = 0;
        ll best = 0;
        for(ll i = 1 ; i <= n; i++) {
                ll ret = maxm + odd[i] + y[i];
                //cout << i << " " << odd[i] << " " << x[i] <<" " << y[i] << endl;
                best = max(best , ret);
                maxm = max(maxm , x[i] - odd[i]);
        }
        cout << best << endl;
        return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int         int64_t
#define ii          pair<int,int>
#define dd          pair<double,double>
#define vi          vector<int>
#define pb          push_back
#define all(x)      (x).begin(), (x).end()
#define checkBit(v, p)      (v&(1LL << p))
#define loop(i,a,b) for(int i = a;i < int(b);i++)
#define x           first
#define y           second
using namespace std;

int inf = 2e9, mod = 1e9 + 7;

int32_t main()
{
    ios_base::sync_with_stdio(false); cout << fixed <<setprecision(0);
    int n; cin >> n;
    vi lt(n), rt(n), arr(n-1);
    lt[0] = 0;
    for(int i=0;i<n-1; i++){
        cin >> arr[i];
        if(arr[i] < 2)lt[i+1] = 0;
        else lt[i+1] = lt[i] + (arr[i] - (arr[i])%2);
    }
    rt[n-1] = 0;
    for(int i=n-2; i>=0;i--){
        if(arr[i] < 2)rt[i] = 0;
        else rt[i] = rt[i+1] + (arr[i] - (arr[i])%2);
    }
    int maxi = 0;
    int best = 0;
    for(int i = 0; i<n;i++){
        if(i) best += arr[i-1] - (arr[i - 1]%2 == 0);
        best = max(best, lt[i]);
        maxi = max(maxi, best + rt[i]);
    }
    cout << maxi<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 100010
typedef long long LL;
LL dl[N],dr[N],suml[N],sumr[N],a[N];
int n;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    scanf("%I64d",&a[i]);
    dl[1]=0;dr[n]=0;suml[1]=0,sumr[n]=0;
    for(int i=2;i<=n;i++)
    {
        dl[i]=a[i-1]==1?0:(dl[i-1]+a[i-1]/2*2);
        suml[i]=max(dl[i],suml[i-1]+1+(a[i-1]-1)/2*2);
    }
    /*for(int i=1;i<=n;i++)
    cout<<dl[i]<<" ";
    cout<<endl;
    for(int i=1;i<=n;i++)
    cout<<suml[i]<<" ";
    cout<<endl;*/
    for(int i=n-1;i>=1;i--)
    {
        dr[i]=a[i]==1?0:(dr[i+1]+a[i]/2*2);
        sumr[i]=max(dr[i],sumr[i+1]+(a[i]-1)/2*2+1);
    }
    /*for(int i=1;i<=n;i++)
    cout<<dr[i]<<" ";
    cout<<endl;
    for(int i=1;i<=n;i++)
    cout<<sumr[i]<<" ";
    cout<<endl;*/
    LL maxn=0;
    for(int i=1;i<=n;i++)
    {
        maxn=max(maxn,max(suml[i]+dr[i],sumr[i]+dl[i]));
    }
    printf("%I64d\n",maxn);
    return 0;
}


//pranav.gayu
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define rz resize
#define f(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define pp pop_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define lb lower_bound
#define ub upper_bound

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	ll n;cin>>n;ll a[n];
   	f(i,0,n-1) cin>>a[i];
   	ll l[n],lr[n],rr[n],r[n];
   	l[0]=0;lr[0]=0;rr[n-1]=0;r[n-1]=0;
   	f(i,1,n)
   	{
   		if(a[i-1] == 1)
   		{
   			l[i]=max(lr[i-1],l[i-1])+a[i-1];
   			lr[i]=0;
   		}
   		else
   		{
   			lr[i]=lr[i-1]+a[i-1]-a[i-1]%2;
   			l[i]=max(lr[i]+a[i-1]%2,l[i-1]+a[i-1]-(1-a[i-1]%2));
   		}
   	}
   	fd(i,n-2,0)
   	{
   		if(a[i] == 1)
   		{
   			r[i]=max(rr[i+1],r[i+1])+a[i];
   			rr[i]=0;
   		}
   		else
   		{
   			rr[i]=rr[i+1]+a[i]-a[i]%2;
   			r[i]=max(rr[i]+a[i]%2,r[i+1]+a[i]-(1-a[i]%2));
   		}
   	}
   	ll ma=0;
   	if(max(rr[0],r[0]) > ma)
   	{
   		ma=max(r[0],rr[0]);
   	}
   	if(max(lr[n-1],l[n-1]) > ma)
   	{
   		ma=max(l[n-1],lr[n-1]);
   	}
   	f(i,1,n-1)
   	{
   		if(l[i-1] > ma)
   		{
   			ma=l[i-1];
   		}
   		if(r[i+1] > ma)
   		{
   			ma=r[i+1];
   		}
   		if(lr[i-1]+max(rr[i+1],r[i+1]) > ma)
   		{
   			ma=lr[i-1]+max(rr[i+1],r[i+1]);
   		}
   		if(rr[i+1]+max(lr[i-1],l[i-1]) > ma)
   		{
   			ma=rr[i+1]+max(lr[i-1],l[i-1]);
   		}
   	}
   	cout<<ma<<"\n";
	return 0;
}


//pranav.gayu
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define rz resize
#define f(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define pp pop_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define lb lower_bound
#define ub upper_bound

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	ll n;cin>>n;ll a[n];
   	f(i,0,n-1) cin>>a[i];
   	ll l[n],lr[n],rr[n],r[n];
   	l[0]=0;lr[0]=0;rr[n-1]=0;r[n-1]=0;
   	f(i,1,n)
   	{
   		if(a[i-1] == 1)
   		{
   			l[i]=max(lr[i-1],l[i-1])+a[i-1];
   			lr[i]=0;
   		}
   		else
   		{
   			lr[i]=lr[i-1]+a[i-1]-a[i-1]%2;
   			l[i]=max(lr[i]+a[i-1]%2,l[i-1]+a[i-1]-(1-a[i-1]%2));
   		}
   	}
   	fd(i,n-2,0)
   	{
   		if(a[i] == 1)
   		{
   			r[i]=max(rr[i+1],r[i+1])+a[i];
   			rr[i]=0;
   		}
   		else
   		{
   			rr[i]=rr[i+1]+a[i]-a[i]%2;
   			r[i]=max(rr[i]+a[i]%2,r[i+1]+a[i]-(1-a[i]%2));
   		}
   	}
   	ll ma=0;
   	if(max(rr[0],r[0]) > ma)
   	{
   		ma=max(r[0],rr[0]);
   	}
   	if(max(lr[n-1],l[n-1]) > ma)
   	{
   		ma=max(l[n-1],lr[n-1]);
   	}
   	f(i,1,n-1)
   	{
   		if(l[i] > ma)
   		{
   			ma=l[i];
   		}
   		if(r[i] > ma)
   		{
   			ma=r[i];
   		}
   		if(lr[i]+max(rr[i],r[i]) > ma)
   		{
   			ma=lr[i]+max(rr[i],r[i]);
   		}
   		if(rr[i]+max(lr[i],l[i]) > ma)
   		{
   			ma=rr[i]+max(lr[i],l[i]);
   		}
   	}
   	cout<<ma<<"\n";
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define S second
#define F first
#define kill(x) return(cout << x << endl, 0)
#define debug(x) cerr<< #x << " : " << x << endl
#define ddebug(x, y) cerr<< #x << " : " << x  << ", " << #y << " : " << y << endl
#define sz(s) (int)s.size()
#define sq(x) (x) * (x)
#define MP(x, y) make_pair(x, y)
#define int long long

const int MAXN = 1000 * 100 + 10;
int arr[MAXN], rb[MAXN], rn[MAXN], lb[MAXN], ln[MAXN];

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i ++)
        cin >> arr[i];

    rb[0] = rn[0] = 0;
    for (int i = 1; i < n; i ++)
    {
        rb[i] = rb[i - 1] + (arr[i - 1] / 2 * 2);
        rn[i] = max(rn[i - 1], rb[i - 1]) + arr[i - 1] - (!(arr[i - 1] % 2));
        if (arr[i - 1] == 1)
            rb[i] = 0;
    }

    lb[n - 1] = ln[n - 1] = 0;
    for (int i = n - 2; i >= 0; i --)
    {
        lb[i] = lb[i + 1] + (arr[i] / 2 * 2);
        ln[i] = max(ln[i + 1], lb[i + 1]) + (arr[i] - (!(arr[i] % 2)));
        if(arr[i] == 1)
            lb[i] = 0;
    }

    int ans = 0;

    for (int i = 0; i < n; i ++)
    {
        ans = max(ans, rb[i] + lb[i]);
        ans = max(ans, rb[i] + ln[i]);
        ans = max(ans, lb[i] + rn[i]);
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define S second
#define F first
#define kill(x) return(cout << x << endl, 0)
#define debug(x) cerr<< #x << " : " << x << endl
#define ddebug(x, y) cerr<< #x << " : " << x  << ", " << #y << " : " << y << endl
#define sz(s) (int)s.size()
#define sq(x) (x) * (x)
#define MP(x, y) make_pair(x, y)
#define int long long

const int MAXN = 1000 * 100 + 10;
int arr[MAXN], rb[MAXN], rn[MAXN], lb[MAXN], ln[MAXN];

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i ++)
        cin >> arr[i];

    rb[0] = rn[0] = 0;
    for (int i = 1; i < n; i ++)
    {
        rb[i] = rb[i - 1] + (arr[i - 1] / 2 * 2);
        rn[i] = rn[i - 1] + (arr[i - 1] - (!(arr[i - 1] % 2)));
    }

    lb[n - 1] = ln[n - 1] = 0;
    for (int i = n - 2; i >= 0; i --)
    {
        lb[i] = lb[i + 1] + (arr[i] / 2 * 2);
        ln[i] = ln[i + 1] + (arr[i] - (!(arr[i] % 2)));
    }

    int ans = 0;

    for (int i = 0; i < n; i ++)
    {
        ans = max(ans, rb[i] + lb[i]);
        ans = max(ans, rb[i] + ln[i]);
        ans = max(ans, lb[i] + rn[i]);
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (int) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const int inf = numeric_limits <int>::max() >> 1;
const int N = 1e5 + 1;
int l[N][3];
int r[N][3];
int a[N];
int n, ans;

int calc_l(int i, int k) {
    if(l[i][k] != -1) {
        return l[i][k];
    }
    if(a[i] < k || !i) {
        return 0;
    } else {
        l[i][k] = a[i] - (a[i] - k & 1) + calc_l(i - 1, k);
    }
    if(k == 1) {
        l[i][k] = max(l[i][k], calc_l(i, 2));
    }
    return l[i][k];
}

int calc_r(int i, int k) {
    if(r[i][k] != -1) {
        return r[i][k];
    }
    if(a[i] < k || i == n) {
        return 0;
    } else {
        r[i][k] = a[i] - (a[i] - k & 1) + calc_r(i + 1, k);
    }
    if(k == 1) {
        r[i][k] = max(r[i][k], calc_r(i, 2));
    }
    return r[i][k];
}

void input() {
    cin >> n;
    for(int i = 1; i < n; ++i) {
        cin >> a[i];
    }
}

void solve() {
    memset(l, -1, sizeof l);
    memset(r, -1, sizeof r);
    for(int i = 1; i < n; ++i) {
        ans = max(ans, max(calc_l(i, 1) + calc_r(i + 1, 2), calc_l(i, 2) + calc_r(i + 1, 1)));
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (ll) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const ll inf = numeric_limits <ll>::max() >> 1;
const ll N = 1e5 + 1;
ll l[N][3];
ll r[N][3];
ll a[N];
ll n, ans;

ll calc_l(ll i, ll k) {
    if(l[i][k] != -1) {
        return l[i][k];
    }
    if(a[i] < k || !i) {
        return 0;
    } else {
        l[i][k] = a[i] - (a[i] - k & 1) + calc_l(i - 1, k);
    }
    if(k == 1) {
        l[i][k] = max(l[i][k], calc_l(i, 2));
    }
    return l[i][k];
}

ll calc_r(ll i, ll k) {
    if(r[i][k] != -1) {
        return r[i][k];
    }
    if(a[i] < k || i == n) {
        return 0;
    } else {
        r[i][k] = a[i] - (a[i] - k & 1) + calc_r(i + 1, k);
    }
    if(k == 1) {
        r[i][k] = max(r[i][k], calc_r(i, 2));
    }
    return r[i][k];
}

void input() {
    cin >> n;
    for(ll i = 1; i < n; ++i) {
        cin >> a[i];
    }
}

void solve() {
    memset(l, -1, sizeof l);
    memset(r, -1, sizeof r);
    for(ll i = 1; i < n; ++i) {
        ans = max(ans, max(calc_l(i, 1) + calc_r(i + 1, 2), calc_l(i, 2) + calc_r(i + 1, 1)));
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


/*  CREATED BY
    STREAM_CIPHER
    29-july-2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define debug(a) cout<<#a<<"="<<(a)<<"\n"
#define fix_precision(n) cout << fixed << setprecision(n)
const double pi=acos(-1.0);
int inf=1e18;
const int mod=1e9+7;
const int mx=5*1000000;
int dpl[100009][2];
int dpr[100009][2];
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
        int n;
        cin>>n;
        vector<int>a(n-1);
        for(auto &i:a)
            cin>>i;
        dpl[0][0]=0;
        dpl[0][1]=0;
        for(int i=1;i<n;i++)
        {
            if(a[i-1]%2)
                dpl[i][0]=max(dpl[i-1][1],dpl[i-1][0])+a[i-1];
            else
                dpl[i][0]=max(dpl[i-1][1],dpl[i-1][0])+(a[i-1]-1);
            if(a[i-1]>1)
                dpl[i][1]=dpl[i-1][1]+(a[i-1]/2)*2;
            else
                dpl[i][1]=0;
        }
        dpr[n][0]=0;
        dpr[n][1]=0;
        for(int i=n-2;i>=0;i--)
        {
            if(a[i]%2)
                dpr[i][0]=max(dpr[i+1][1],dpr[i+1][0])+a[i];
            else
                dpr[i][0]=max(dpr[i+1][1],dpr[i+1][0])+a[i]-1;
            if(a[i]>1)
                dpr[i][1]=dpr[i+1][1]+(a[i]/2)*2;
            else
                dpr[i][1]=0;
        }
        // for(int i=0;i<n;i++)
        //     cout<<dpl[i][0]<<" "<<dpl[i][1]<<endl;
        // cout<<endl;
        // for(int i=0;i<n;i++)
        //     cout<<dpr[i][0]<<" "<<dpr[i][1]<<endl;

        int ans=0;
        // cout<<dpr[0][0]<<endl;
        for(int i=0;i<n;i++)
            ans=max(ans,max(dpl[i][0]+dpr[i][1],max(dpl[i][1]+dpr[i][1],dpr[i][0]+dpl[i][1])));
        cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define s second
#define maxn 100005
#define llinf 1e9+18
#define f first
#define read(u,v) cin>>u>>v
#define ld long double

vector<ll>retl,retr,endll,endr,bridge;

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    bridge=vector<ll>(n);
    for(int i=0;i<n-1;i++)
    cin>>bridge[i+1];

    retl=retr=endll=endr=vector<ll>(n);
    ll sum=0;
    retl[0]=endll[0]=0;
    for(int i=1;i<n;i++){
        if(bridge[i]==1){
            sum=0;
        }
        else{
            sum+=((bridge[i]/2)*2);
        }
        retl[i]=sum;
        ll val=bridge[i]%2==0?-1:0;
        val+=bridge[i];
        endll[i]=max(retl[i],val+max(endll[i-1],retl[i-1]));
    }
    retr[n-1]=endr[n-1]=0;
    sum=0;
    for(int i=n-2;i>=0;i--){
        if(bridge[i+1]==1){
            sum=0;
        }
        else{
            sum+=((bridge[i+1]/2)*2);
        }
        retr[i]=sum;
        ll val=bridge[i+1]%2==0?-1:0;
        val+=bridge[i+1];
        endr[i]=max(retr[i],val+max(endr[i+1],retr[i+1]));
    }

    /*for(int i=0;i<n;i++){
        cout<<retl[i]<<" "<<retr[i]<<" "<<endll[i]<<" "<<endr[i]<<endl;
    }*/

    ll ans=0;
    for(int i=0;i<n;i++){
        ans=max(ans,endll[i]+retr[i]);
        ans=max(ans,endr[i]+retl[i]);
        ans=max(ans,retr[i]+retl[i]);
    }

    cout<<ans<<endl;

}


#include<bits/stdc++.h>
#define pb push_back
#define int long long int
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define setp cout << fixed << setprecision(15);
#define div dsfs
using namespace std;

const int MAX_N = 1e6 + 7, inf = 1e17 + 7;
int dp[MAX_N], f[MAX_N], a[MAX_N];
vector <int> vdp, vf;
int32_t main()
{
    int n; cin >> n;
    for(int i = 0; i < n-1; i++) cin >> a[i];
    for(int i = 1;  i < n; i++)
    {
        f[i] = f[i-1] + a[i-1] - (a[i-1] % 2);
        if(a[i-1] < 2) f[i] = 0;
        dp[i] = f[i-1] + a[i-1] - !(a[i-1] % 2);
        dp[i] = max(dp[i], dp[i-1] + a[i-1] - !(a[i-1] % 2));
        if(a[i-1] < 1) dp[i] = 0;
    }
    for(int i = n-1; i >= 0; i--)
    {
        vdp.pb(dp[i]);
        vf.pb(f[i]);
        f[i] = 0, dp[i] = 0;
    }
/*    for(int x : vdp) cout << x << " ";
    cout << endl;
    for(int x : vf) cout << x << " ";
    cout << endl << endl;*/
    for(int i = 0; i < n/2; i++) swap(a[i], a[n-i-2]);

    for(int i = 1;  i < n; i++)
    {
        f[i] = f[i-1] + a[i-1] - (a[i-1] % 2);
        if(a[i-1] < 2) f[i] = 0;
        dp[i] = f[i-1] + a[i-1] - !(a[i-1] % 2);
        dp[i] = max(dp[i], dp[i-1] + a[i-1] - !(a[i-1] % 2));
        if(a[i-1] < 1) dp[i] = 0;
    }
  /*  for(int i = 0; i < n; i++) cout << dp[i] << " ";
    cout << endl;
    for(int i = 0; i < n; i++) cout << f[i] << " ";
    cout << endl;*/
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        ans = max(ans, max(vf[i] + f[i], dp[i] + vf[i]));
        ans = max(ans, f[i] + vdp[i]);
    }
    cout << ans;
    return 0;
}