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++: #include <cstdio>
#include <stack>
using namespace std;

int main(void)
{
    int n;
    scanf("%d", &n);
    
    for (int i = 0; i < n; i++){
        stack < int > b, c;
        int j;
        
        b.push(0);
        c.push(0);
        
        int ball[10];
        for (int i = 0; i < 10; i++){
            scanf("%d", &ball[i]);
        }
        
        for (j = 0; j < 10; j++){
            if (b.top() < ball[j]){
                if (c.top() < ball[j]){
                    if (c.top() < b.top()){
                        b.push(ball[j]);
                    }
                    else {
                        c.push(ball[j]);
                    }
                }
                else {
                    b.push(ball[j]);
                }
            }
            else if (c.top() < ball[j]){
                c.push(ball[j]);
            }
            else {
                break;
            }
        }
        
//        printf("%d\n", j);
        
        if (j == 10){
            printf("YES\n");
        }
        else {
            printf("NO\n");
        }
    }
    
    return (0);
}

C++: #include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
int a[10];
bool ans;
void dfs(int i,int r,int l){
	if(i==10)ans=1;
	if(a[i]<r&&a[i]<l)return;
	if(ans)return;
	if(r<a[i])dfs(i+1,a[i],l);
	if(l<a[i])dfs(i+1,r,a[i]);

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

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int a[10];
int n;

bool dfs(int i,int left,int right){
	if(i==10) return true;
	if(a[i]>left){
		return dfs(i+1,a[i],right);
	}
	if(a[i]>right){
		return dfs(i+1,left,a[i]);
	}
	return false;
}

void solve(){
	rep(i,10) cin >> a[i];
	if(dfs(0,0,0)) cout << "YES" << endl;
	else cout << "NO" << endl;
	return;
}

int main(){
	cin >> n;
	rep(i,n){
		solve();
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
#define N 10
int flag;
int shunxu[N+5];
void dfs(int x1,int y1,int x2,int y2,int ans) {
	if (x2 < x1 || y2 < y1)
		return;
	if (ans == 10) {
		flag = 1;
		return;
	}
	dfs(x2, y1, shunxu[ans], y2, ans + 1);
	dfs(x1, y2, x2, shunxu[ans], ans + 1);
}
int main()
{
	int n;
	cin >> n;
	while (n--) {
		for (int i = 0; i < N; i++) {
			cin >> shunxu[i];
		}
		flag = 0;
		dfs(0, 0, 0, 0, 0);
		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

int b[10];

bool dfs(int idx, int left, int right)
{
	if (idx == 10) return true;

	if (b[idx] > left && dfs(idx + 1, b[idx], right)) return true;
	if (b[idx] > right && dfs(idx + 1, left, b[idx])) return true;

	return false;
}

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

		cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
	}
}

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

bool ans;
int a[10];

void dfs(int idx, int l, int r) {
   if (idx == 10) {
      ans = true;
      return;
   }

   int val = a[idx];
   if (l < val) dfs(idx+1, val, r);
   if (r < val) dfs(idx+1, l, val);
}

int main() {
   int N;
   cin >> N;
   while (N--) {
      for (int i = 0; i < 10; i++) cin >> a[i];
      ans = false;
      dfs(0, -1, -1);
      puts(ans ? "YES" : "NO");
   }

   return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int a[10];
bool dfs(int d, int l, int r){
    if(d == 10) return true;
    if(a[d] > l && dfs(d + 1, a[d], r))
      return true;
    if(a[d] > r && dfs(d + 1, l, a[d]))
       return true;
    return false;
}
int main(){
    int n;
    cin >> n;
    for(int k = 0; k < n; k++){
        for(int i = 0; i < 10; i++)
          cin >> a[i];
        if(dfs(0, 0, 0))
          puts("YES");
        else
          puts("NO");
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std ;
int a[50] ,flag , l , r  ;
void dfs(int x , int l , int r)
{
    if(x==11) return ;
    if(a[x]>l) dfs(x+1,a[x],r);
    else if(a[x]>r) dfs(x+1,l,a[x]);
    else
    {
        flag = 1 ;
        return;
    }
}
int main()
{
    int t ;
    cin>>t;
    while(t--)
    {
        flag = 0 ;
        for(int i = 1 ; i<=10;i++)
        {
            cin>>a[i];
        }
        dfs(1,0,0);
        if(flag) printf("NO\n");
        else printf("YES\n");
    }
    return 0 ;
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
	int a,b;
	int n;
	int g;
	bool check;
	vector<int> ball;

	while(cin >> n){
		a = b = 0;
		check = true;
		rep(i,10){
			cin >> g;
			ball.insert( ball.begin(), g);
		}
		rep(i,10){
			if(a < ball.back()){
				a = ball.back();
				ball.pop_back();
			}else if(b < ball.back()){
				b = ball.back();
				ball.pop_back();
			}else{
				check = false;
			}
		}
		if(check) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(void)
{
    int bo[11],n,B[11],C[11],b1=0,c1=0,A=0,k=0,l=1;
    cin>>n;
    for(int i=0;i<n;i++){
            C[0]=11;k=0;l=0;B[0]=0;b1=0;c1=0;C[1]=13;
        for(int j=0;j<10;j++){
            cin>>bo[j];
        }
        for(int j=1;;j++){
                cout<<bo[j]<<" ";
            if(j==1)B[0]=bo[0];
        if(C[0]==11&&j==2){
            C[0]=bo[j];
            k++;
            cout<<"6\n";
        }else if(C[1]==13&&j>3&&C[0]<bo[j]){
            C[1]=bo[j];
            k++;
            c1=1;
            cout<<"7\n";
        }else if(B[l]<bo[j]){
            b1=1;
            B[l+1]=bo[l];
            l++;
            cout<<"1\n";
        }else if(C[0]==11){
            C[0]=bo[j];
            k++;
            cout<<"2\n";
        }else if(C[k-1]<bo[j]){
            c1=1;
            C[k+1]=bo[j];
            cout<<"3\n";
        }else if(B[l]<bo[j+1]){
            C[k+1]=bo[j];
            k++;
            cout<<"5\n";
        }else{
            B[l+1]=bo[j];
            l++;
            cout<<"4\n";
        }
        if(j==9||(b1==1&&c1==1))break;
    }
    if(b1==1&&c1==1)cout<<"YES\n";
    else cout<<"NO\n";
    for(int j=0;j<10;j++){
        B[j]=0;C[j]=0;
    }

}
}