Go: package main

import "fmt"

func isOrdered(a []int) bool {
	if len(a) <= 1 {
		return true
	}
	for i := 0; i+1 < len(a); i++ {
		if a[i] > a[i+1] {
			return false
		}
	}
	return true
}

func main() {
	// ボールの数がせいぜい10個しかないので、全てのボールの落とし方を全探索することが可能
	// Bit全探索を行う。右から見てj番目のビットが立っているときには左側の筒、立っていない時は右側の筒にいれる物とする。
	// 全てのボールを落とし終わった後に、それぞれの筒で昇順に並んでいるか調べることにする。
	var t int
	fmt.Scan(&t)
	ans := make([]bool, t)
	for i := 0; i < t; i++ {
		balls := make([]int, 10)
		for i := range balls {
			fmt.Scan(&balls[i])
		}
		ans[i] = false
		for bits := 0; bits < (1 << uint(10)); bits++ {
			pipeB := make([]int, 0)
			pipeC := make([]int, 0)
			for j := 0; j < 10; j++ {
				if (bits & (1 << uint(j))) != 0 {
					pipeB = append(pipeB, balls[j])
				} else {
					pipeC = append(pipeC, balls[j])
				}
			}
			if isOrdered(pipeB) && isOrdered(pipeC) {
				// fmt.Printf("test case %d - OK pattern - pipeB %v, pipec %v\n", i, pipeB, pipeC)
				ans[i] = true
				break
			}
		}
	}
	for i := range ans {
		if ans[i] {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

C++: //0033
//include-------------------------------------
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<stack>

using namespace std;

//typedef--------------------------------------
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define MP make_pair

//repetition-----------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

//constant-------------------------------------
const double PI = acos(-1.0);

//cout,cin-------------------------------------
#define COUT(x) cout<<(x)<<endl;
#define CIN(x) cin>>(x);


int main(){
	int n;
	int x[10];
	bool ans;

	CIN(n);

	REP(i, n){
		
		REP(j, 10) CIN(x[j]);
		stack<int> B, C;
		B.push(0);
		C.push(0);

		REP(j, 10){
			if ((B.top() > x[j]) && (C.top() > x[j])){
				ans = false;
				break;
			}
			else { 
				if ((B.top() >= C.top()) && (B.top() < x[j])) B.push(x[j]);
				else C.push(x[j]);
			}

		}
		COUT(ans==false?"NO":"YES");
		
	}

	return 0;

}

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

int main() {
	int n;
	for (cin >> n; n; --n) {
		int a = 0;
		int b = 0;
		bool result = true;
		for (int i = 0; i < 10; ++i) {
			int ball;
			cin >> ball;
			if (ball > a) {
				a = ball;
			}
			else if (ball > b) {
				b = ball;	
			}
			else if (result) {
				result = !result;
			}
		}
		cout << (result ? "YES" : "NO") << endl;
	}
	return 0;
}

C++: #include <stdio.h>

int ball[10];

bool can(int n,int left,int right){
	bool flag;
	
	if(n==10) return true;
	if(ball[n]>right && can(n+1,left ,ball[n])) return true;
	if(ball[n]>left  && can(n+1,ball[n],right)) return true;
	
	return false;
}


int main(){
	
	int N;
	
	scanf("%d",&N);
	
	for(int i=0;i<N;i++){
		for(int j=0;j<10;j++){
			scanf("%d",&ball[j]);
		}
		
		printf(can(0,0,0)?"YES":"NO");
		
		
	}
}

C++: #include<cstdio>
#include<stack>
using namespace std;
int a[10],flag;
stack<int>s1,s2;
void dfs(int i){
	if(i==10){flag=1;return ;}
	if(a[i]>s1.top()){
		s1.push(a[i]);
		dfs(i+1);
		s1.pop();
	}
	if(a[i]>s2.top()){
		s2.push(a[i]);
		dfs(i+1);
		s2.pop();
	}
	return ;
}
int main(void){
	int T;scanf("%d",&T);
	while(T--){
		while(!s1.empty())s1.pop();
		while(!s2.empty())s2.pop();
		flag=0;
		for(int i=0;i<10;i++)
			scanf("%d",a+i);
		s1.push(0),s2.push(0);
		dfs(0);
		printf(flag?"YES\n":"NO\n");
	}
}

C++: #include <iostream>
using namespace std;
int a[10];
bool dfs(int i,int b,int c){
	if(i<10){
		if(a[i] > b) {
			if(dfs(i+1,a[i],c)){
				return true;
			}
		}
		else if(a[i] > c) {
			if(dfs(i+1,b,a[i])) {
				return true;
			}
		}
		return false;
	}
	return true;
}
int main(){
	int i,n;
	while(cin >> n && n){
		for(i=0;i<n;i++){
			for(int j = 0;j<10;j++){
				cin >> a[j];
			}
			if(dfs(0,0,0)) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int a[10];

void solve() {
    int min1 = INT_MIN, min2 = INT_MIN;
    for(int i = 0;i < 10; i++) {
        if(a[i] > min1 && a[i] > min2) {
            if(min1 > min2) {
                min1 = a[i];
            } else {
                min2 = a[i];
            }
        } else if(a[i] > min1) {
            min1 = a[i];
        } else if(a[i] > min2) {
            min2 = a[i];
        } else {
            printf("NO\n");
            return ;
        }
    }
    printf("YES\n");
    return ;
}

int main() {
    int num;
    scanf("%d", &num);
    while(num--) {
        for(int i = 0;i < 10; i++) {
            scanf("%d", &a[i]);
        }
        solve();
    }
}

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

int main(){
	int ball[10];
	int cell[2][10]={0};
	int n,i,k,cell_1=1,cell_2=1,flag[1000]={0};
	
	scanf("%d",&n);
	
	for(k=0;k<n;k++){
		for(i=0;i<10;i++)scanf("%d",&ball[i]);
		
		cell[0][0]=0;
		cell[1][0]=0;

		for(i=0;i<10;i++){
			if(cell[0][cell_1-1] < ball[i]){
				cell[0][cell_1]=ball[i];
				cell_1++;
			}
			else if(cell[1][cell_2-1] < ball[i]){
				cell[1][cell_2]=ball[i];
				cell_2++;
			}
			else flag[k]=1;
		}	
	}
	
	cell_1=1;
	cell_2=1;
	
	for(i=0;i<n;i++){
		if(flag[i]==0)printf("YES\n");
		else printf("NO\n");
	}
	
	return 0;
}

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

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

	for (int i = 0; i < n; i++){
		queue<int> ball;
		int num;
		for (int j = 0; j < 10; j++){
			cin >> num;
			ball.push(num);
		}

		int b = 0, c = 0;
		for (int j = 0; j < 10; j++){
			int p_ball = ball.front();
			if (b < p_ball){
				b = p_ball;
				ball.pop();
			}
			else if (c < p_ball){
				c = p_ball;
				ball.pop();
			}
			else {
				cout << "NO" << endl;
				break;
			}
		}

		if (ball.empty()){
			cout << "YES" << endl;
		}
	}

	return (0);
}

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

bool solver(queue<int> q, int a, int b){
    bool result = false;
    if(q.empty()) {
        return true;
    }
    int tmp = q.front();
    if(tmp > a){
        a = tmp;
        q.pop();
        result = solver(q, a, b);
        q.push(tmp);
    }
    if(result) return true;
    tmp = q.front();
    if(tmp > b){
        b = tmp;
        q.pop();
        result = solver(q, a, b);
        q.push(tmp);
    }
    if(result) return true;
    return false;
}

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

    for(int i=0; i<n; i++){
        queue<int> q;
        for(int j=0; j<10; j++){
            int tmp;
            cin >> tmp;
            q.push(tmp);
        }
        cout << (solver(q,0,0)?"YES":"NO") << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int ball[10];

bool dfs(int,int,int);

int main(){
	int n;
	cin>>n;
	for (int i = 0; i < n; i++) {
		for (int& j : ball) cin>>j;
		if(dfs(0,0,0))puts("YES");
		else puts("NO");
	}
	return 0;
}

bool dfs(int b,int c,int m){
	if(m == 9)return (b<ball[m] || c<ball[m]) ? true : false;
	bool res = false;
	if(b<ball[m])res = max(res,dfs(ball[m],c,m+1));
	if(c<ball[m])res = max(res,dfs(b,ball[m],m+1));
	return res;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int a[10];

bool dfs(int i, int left, int right){
	cout << left << " " << right << " " << i << endl;
	if(i == 10) return true;
	bool answer = false;
	if(left < a[i]){
		answer = dfs(i+1, a[i], right);
	}
	if(right < a[i]){
		answer = dfs(i+1, left, a[i]);
	}

	return answer;
}


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