Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	for i := 0; i < n; i++ {
		a := -1
		b := -1
		ans := true
		// それぞれの筒の一番上にあるたまの数字に着目すればよい
		for j := 0; j < 10; j++ {
			x := nextInt()
			if x > a {
				a = x
			} else if x > b {
				b = x
			} else {
				ans = false
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    int n; cin>>n;
    rep(i,n){
        vi v(11,0); pii pr; bool check=true;
        rep(i,10)cin>>v[i];
        pr.first=v[0];
        pr.second=v[1];
        for(int j=2; j<10;j++){
            int left=(-pr.first+v[j]); int right=(-pr.second+v[j]);
            if(pr.first>v[j]&&pr.second>v[j])check=false;
            else if(right>left&&v[j]>pr.first)pr.first=v[j];
            else if(right<left&&v[j]>pr.second)pr.second=v[j];
            else if(left>0&&right<0)pr.first=v[j];
            else if(left<0&&right>0)pr.second=v[j];
            else check=false;
            
        }
        if(check)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}

C++: #include <iostream>

using namespace std;

bool s( int ord[], int const i, int const bef = -1 )
{
    if ( i > 10 )
        return true;

    if ( bef != -1 && bef > ord[i] )
        return false;

    return s( ord, i+1, ord[i] ) || s( ord, i+2, ord[i] ) && s( ord, i+2, ord[i+1] );
}

int main()
{
    int n;
    cin >> n;

    for( int iii=0; iii<n; ++iii ) {
        int ord[10];
        for( int i=0; i<10; ++i )
            cin >> ord[i];

        cout << ( s( ord, 0 ) || s( ord, 1 ) ? "YES" : "NO" ) << endl;
    }
}

C++: #include<iostream>
#include<cstring>
using namespace std;
void dfs(int b[11],int c[11],int m,int k,int t);//a中，b中，c中游标
int a[10];
int flag;
int main()
{
	int N;
	cin >> N;
	while (N--)
	{
		for (int i = 0; i < 10; i++)
			cin >> a[i];
		int b[10];
		int c[10];
		b[0] = 0;
		c[0] = 0;
		flag = 0;
		dfs(b, c, 0, 0, 0);
		if (flag== 1)
			cout << "YES" << endl;
		else 
			cout << "NO" << endl;
	}
	return 0;
}
void dfs(int b[11], int c[11], int m, int k, int t)
{
	int ma = m;
	int kb = k;
	int tc = t;
	int i;
	int x[11], y[11];             //用x,y去中间值，好进行回溯
	if (ma == 10)
		flag=1;
	else
	{
		for (i = 0; i <= kb; i++)
		{
			x[i] = b[i];
		}
		for (i = 0; i <= tc; i++)
		{
			y[i] = c[i];
		}
		/*if (x[kb] > a[ma] && y[tc] > a[ma])  //两个都大  不要直接return 应该返回 找其他的枝丫
			return 0;*/
		if (x[kb] > a[ma] && y[tc] < a[ma])
		{ 
			tc++;
			y[tc] = a[ma];
			ma++;
			dfs(x, y, ma, kb, tc);
		}
		else if (x[kb] < a[ma] && y[tc] > a[ma])
		{
			kb++;
			x[kb] = a[ma];
			ma++; 
			dfs(x, y, ma, kb, tc);
		}
		else if (x[kb] < a[ma] && y[tc] < a[ma])
		{
			kb++;
			x[kb] = a[ma];
			ma++;
			dfs(x, y, ma, kb, tc);
			ma--; kb--;
            tc++;
			y[tc] = a[ma];
			ma++;
			dfs(x, y, ma, kb, tc);
			ma--; tc--;
		}
	}
}

C++: //
//  0033.cpp
//  
//
//  Created by Yoshida Satoshi on 2017/11/16.
//
//

#include <iostream>
using namespace std;

void tsumu(int l,int r,int* in,int j,bool *ans){
    if(j==9){
        *ans=true;
        return;
    }
    if(in[j]>l) tsumu(in[j],r,in,j+1,ans);
    if(in[j]>r) tsumu(l,in[j],in,j+1,ans);
    
    return;
}

int main(){
    int N;
    int in[10];
    int l;
    int r;
    bool ans;
    
    cin>>N;
    for(int i=0;i<N;i++){
        ans=false;
        l=r=0;
        for(int j=0;j<10;j++){
            cin>>in[j];
        }
        tsumu(l,r,in,0,&ans);
        if(ans) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        
    }
    return 0;
}

C++: // g++ -std=c++11 temp.cpp
#include <bits/stdc++.h>
using namespace std;

#define For(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Rep(i,n) For(i,0,n)
#define Each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3

#define MAX_N 1000

int N;
vector<int> in, h1, h2;

/*
bool sorter(const A& x, const A& y){
	return x.a < y.a;
}

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

int lcm(int a, int b){
	if(a == 0 || b == 0) return 0;
	return a*b/gcd(a,b);
}
*/
bool dfs(int n){
	bool flag = false;
	if(n == 10) return true;
	else{
		if(h1.size() == 0 || h1[h1.size()-1] < in[n]){
			h1.pb(in[n]);
			if(dfs(n+1)) flag = true;
			h1.pop_back();
		}
		if(h2.size() == 0 || h2[h2.size()-1] < in[n]){
			h2.pb(in[n]);
			if(dfs(n+1)) flag = true;
			h2.pop_back();
		}
	}
	return flag;
}

int main(){
	scanf("%d", &N);
	Rep(i,N){
		in.clear();
		Rep(j,10){
			int ball;	
			scanf("%d", &ball);
			in.pb(ball);
		}
		h1.clear();
		h2.clear();
		if(dfs(0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int a[10]={0};
bool right(){
    for(int i=0;i<10;i++){
        if(*max_element(a,a+i)>*max_element(a+i,a+10)) return false;
    }
    return true;
}
int main(void){
    int n;
    cin>>n;
    while(n--){
        for(int i=0;i<10;i++) cin>>a[i];
        if(right()) cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int a[10];
int b[10];
int ball[20];
bool ans;
void dfs(int k,int ca,int cb)
{
	if(k==10)
	{
		ans = 1;
		return;
	}
	if(ball[k] > a[ca-1])
	{
		a[ca] = ball[k];
		dfs(k+1,ca+1,cb);
		a[ca] = 0;
	}
	if(ball[k] > b[cb-1])
	{
		b[cb] = ball[k];
		dfs(k+1,ca,cb+1);
		b[cb] = 0;
	}
	return;
}
int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		ans = 0;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(int i = 0;i<10;i++)
		{
			cin >> ball[i];
		}
		dfs(0,1,1);
		if(ans == 1)
		cout << "Yes" << endl;
		else
		cout << "No" << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;

int ball[10];

//ball[m]?????\????????±b,c???????????????ball???????????????left,right
bool dfs(int m,int left, int right){
    if(m==10) return true;
    if(ball[m]>left){
        return dfs(m+1,ball[m],right);
    }
    if(ball[m]>right){
        return dfs(m+1,left,ball[m]);
    }
    return false;
}

void solve(){
    for(int i=0;i<10;i++){
        cin>>ball[i];
    }
    if(dfs(0,0,0)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

int main(){
    int n;cin>>n;
    for(int i=0;i<2;i++){
        solve();
    }
    return 0;
}