Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var num int
	fmt.Scan(&num)

	for i := 0; i < num; i++ {
		sc.Scan()
		line := sc.Text()

		insertCheck(line)
	}
}

func insertCheck(line string) {
	var B, C []int

	for _, v := range strings.Split(line, " ") {
		ball, _ := strconv.Atoi(v)
		switch {
		case len(B) == 0:
			B = append(B, ball)
		case B[len(B)-1] < ball:
			B = append(B, ball)
		case B[len(B)-1] >= ball:
			switch {
			case len(C) == 0:
				C = append(C, ball)
			case C[len(C)-1] < ball:
				C = append(C, ball)
			case C[len(C)-1] >= ball:
				fmt.Println("NO")
				return
			}
		}
	}
	fmt.Println("YES")
}

C++: #include<iostream>
#include<cstring>
using namespace std;
void dfs(int b[10],int c[10],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[10], int c[10], int m, int k, int t)
{
	int ma = m;
	int kb = k;
	int tc = t;
	int i;
	int x[10], y[10];             //用x,y去中间值，好进行回溯
	if (ma == 10)
		flag=1;
	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])
	{
		y[tc] = a[ma];
		ma++; tc++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
	}
	if (x[kb] < a[ma] && y[tc] > a[ma])
	{
		x[kb] = a[ma];
		ma++; kb++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
	}
	if (x[kb] < a[ma] && y[tc] < a[ma])
	{
		x[kb] = a[ma];
		ma++; kb++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
		ma--; kb--;
		y[tc] = a[ma];
		ma++; tc++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
		ma--; tc--;
	}
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<deque>
#define INF int(1e9)
using namespace std;
int read()
{
    int f=1,x=0;
    char c=getchar();
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
    while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
    return f*x;
}
bool flag;
int ball[11];
void DFS(int left,int right,int now)
{
	if(now>10)
	{
		flag=1;	
		return ;
	}
	if(ball[now]>left&&ball[now]>right) 
		return ;	
	if(ball[now]<left)
		DFS(ball[now],right,now+1);
	else
		DFS(left,ball[now],now+1);
	return ;
}
int main()
{
	int t=read();
	while(t!=0)
	{
		t--;
		flag=0;
		for(int i=10;i>=1;i--)
			ball[i]=read();
		DFS(INF,INF,1);
		if(flag==1)
			printf("YES\n");
		else
			printf("NO\n");
	}
    return 0;
}

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

int B[12], C[12], num[12], b, c;

bool dfs(int b, int c, int i){
    if(i == 10) return true;
    B[b+1] = num[i];
    C[c+1] = num[i];
    if(B[b]<num[i] && dfs(b+1, c, i+1)){
        return true;
    }
    if(C[c]<num[i] && dfs(b, c+1, i+1)){
        return true;
    }
    return false;
}

int main(void){
  int N;
  cin >> N;
  for(int j=0; j<N; j++){
  B[0] = 0;
  C[0] = 0;
  for(int i=0; i<10; i++){
    cin >> num[i];
  }
  if(dfs(0, 0, 0))  cout << "YES" << endl;
  else cout << "NO" << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <deque>

using namespace std;

typedef deque <int> Deq;

bool flag;
int ball[10], a;

void dfs(Deq B, Deq C, int deep)
{
	if (flag) return;
	if (deep == 10){
		// cout << "B : " << B.size() << " / ";
		// for (int i = 0; i < B.size(); i++){
		// 	cout << B[i] << " ";
		// }
		// cout << endl << "C : " << C.size() << " / ";
		// for (int i = 0; i < C.size(); i++){
		// 	cout << C[i] << " ";
		// }
		// cout << endl;
		bool bf = true, cf = true;
		for (int i = 0; i+1 < B.size(); i++){
			if (B[i] > B[i+1]) bf = false;
		}
		for (int i = 0; i+1 < C.size(); i++){
			if (C[i] > C[i+1]) cf = false;
		}
		flag |= (bf && cf);
		return;
	}

	B.push_back(ball[deep]);
	dfs(B, C, deep + 1);
	B.pop_back();

	C.push_back(ball[deep]);
	dfs(B, C, deep + 1);
	C.pop_back();
	return;
}

int main(void)
{
	int n;
	cin >> n;
	while (n--){
		for (int i = 0; i < 10; i++){
			cin >> ball[i];
		}

		flag = false;
		Deq B, C;
		dfs(B, C, 0);

		if (flag) cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;
}

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

int main() {
	int n, balls[10]; cin >> n;
    while(n--){
        for(int i = 0; i < 10; i++){
            cin >> balls[i];
        }
        
        bool sortable = false;
        stack<tuple<int, int, int> > states;
        
        states.push(make_tuple(0,0,0));
        while(!states.empty()){
        	tuple<int, int, int> now = states.top();
        	states.pop();
        	
        	int idx = get<0>(now);
        	if(idx < 10){
        		if(get<1>(now) < balls[idx]){
        			if(idx == 9){
        				sortable = true; break;
        			}
        			states.push(make_tuple(idx+1,balls[idx],get<2>(now)));
        		}
        		if(get<2>(now) < balls[idx]){
        			if(idx == 9){
        				sortable = true; break;
        			}
        			states.push(make_tuple(idx+1,get<1>(now),balls[idx]));
        		}
        	}        	
        }
         
        if(sortable) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n;
    cin >> n;
    while(n-- > 0){
        int b = 0, c = 0;
        bool ok = true;
        for(int i=0; i<10; ++i){
            int a;
            cin >> a;
            if(a > b && a > c){
                if(b > c)
                    b = a;
                else
                    c = a;
            }else if(a > b)
                b = a;
            else if(a > c)
                c = a;
            else
                ok = false;
        }
        if(ok)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}

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

int main(){
	int N,ball,B=0,C=0;
	cin>>N;
	for(int i=0;i<N;i++){
		for(int j=0;j<10;j++){
			cin>>ball;
			if(ball<B && ball<C){cout<<"NO"<<endl;goto x;}
			if(B<ball && C<B){B=ball;}
			else if(C<ball && B<C){C=ball;}
			else if(C<B){C=ball;}
			else 		{B=ball;}
		}	
		cout<<"YES"<<endl;
x:		B=C=0;
	}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
#define INF 40
using namespace std;

int ball[12];
int flag ;
stack<int> A, B;


void dfs(int s)
{
	if (s >= 10)
	{
		flag = 1;
		return;
	}
	else if (ball[s] < A.top() && ball[s] < B.top())
	{
		return;
	}
	else {
		if (ball[s] > A.top())
		{
			A.pop();
			A.push(ball[s]);
			dfs(ball[s + 1]);
		}
		if (ball[s] > B.top())
		{
			B.pop();
			B.push(ball[s]);
			dfs(ball[s + 1]);
		}
	}
}


int main()
{
	int n;
	A.push(0);
	B.push(0);
	while (~scanf("%d",&n))
	{
		while (n--)
		{
			flag = 0;
			memset(ball, 0, sizeof(ball));
			for (int i = 0;i < 10;i++)
			{
				scanf("%d", &ball[i]);
			}
			dfs(0);
			if (flag) printf("YES\n");
			else printf("NO\n");
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string.h>

using namespace std;

int N;
int balls[10];
bool dfs(int n, int a, int b){
if(n==10)return true;
if(balls[n]>a) return dfs(n+1,balls[n],b);
if(balls[n]>b) return dfs(n+1,a,balls[n]);
return false;
}
int main(){
cin>>N;
for(int i=0;i<N;i++){
for(int j=0;j<10;j++){
cin>>balls[j];
}
if(dfs(0,0,0))cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}