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 <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)

int a[10];

//B:=B?????????????????° C*=C?????????????????° cnt:=??????????????°??????
bool dfs(int B, int C, int cnt){
    if(cnt == 10){
        return true;
    }
    if(B < a[cnt]){
        return dfs(a[cnt], C, cnt + 1);
    }
    if(C < a[cnt]){
        return dfs(B, a[cnt], cnt + 1);
    }
    if(B > a[cnt] && C > a[cnt]){
        return false;
    }
}
int main(void){
    int n; cin >> n;
    for (int i = 0; i < n; ++i){
        rep(j, 10) cin >> a[j];
        if(dfs(0, 0, 0)) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

C++: #include<cstdio>
#include<iostream>
int mitaball(int n,int Bn,int Cn);
int ball[10],B[10]={0},C[10]={0};
int judge;
int a;
int x;
int main(){
    scanf("%d",&x);
    for(int j=0;j<x;j++){
        judge=0;
        for(int i=0;i<10;i++)
            scanf("%d",&ball[i]);
        mitaball(0,0,0);
        if(judge==1)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}
int mitaball(int n,int Bn,int Cn){
    if(judge==0){
        if(n==10){
            for(int i=0;i<Bn-1;i++){
                if(B[i]>B[i+1])
                    break;
                judge=1;
            }
            for(int i=0;i<Cn-1;i++){
                if(C[i]>C[i+1]||judge==0)
                    break;
                judge=1;
            }
        }
        else{
            B[Bn]=ball[n];
                mitaball(n+1,Bn+1,Cn);
            B[Bn]=0;
            C[Cn]=ball[n];
                mitaball(n+1,Bn,Cn+1);
            C[Cn]=0;
        }
    }
}

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

#define SIZE 300005
#define MOD 1000000007LL
#define INF INT_MAX / 3
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef valarray<int> Array;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i];if(i==a.size()-1)cout<<endl;else cout<<" ";}}
int gcd(int a,int b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
int lcm(int a,int b){return a==0||b==0?0:a*b/gcd(a,b);}

int a[10];

bool dfs(int l,int r, int num)
{
  if(num == 10) return true;
  bool ans = false;
  if(a[num] > l) ans = dfs(a[num],r,num+1);
  else if(a[num] > r) ans = dfs(l,a[num],num+1);
  return ans;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  REP(v,n)
  {
    REP(i,10) cin >> a[i];
    cout << (dfs(0,0,0)?"YES":"NO") << "\n";
  }
  return 0;
}

C++: #include <iostream>
#include <stack>
#include <vector>

using namespace std;

int N;
int A_bottle[10];

stack<int> B_bottle,C_bottle;

bool dfs(int i){
	//A????????????i???????????°?????????????????????
	if (i==10){
		//?????????????????????????????????????????????
		return true;
	}

	if (B_bottle.empty() || B_bottle.top()<A_bottle[i]){
		//B????????????????????????
		B_bottle.push(A_bottle[i]);
		if (dfs(i+1)) return true;
		B_bottle.pop();
	}
	if (C_bottle.empty() || C_bottle.top()<A_bottle[i]){
		//C????????????????????????
		C_bottle.push(A_bottle[i]);
		if (dfs(i+1)) return true;
		C_bottle.pop();
	}
	return false;
}

int main(){
	vector<bool> out;
	cin>>N;
	for (int i=0;i<N;i++){
		for (int j=0;j<10;j++){
			cin>>A_bottle[j];
		}
		out.push_back(dfs(0));
	}
	for (vector<bool>::iterator ite=out.begin();ite!=out.end();ite++){
		cout<<(*ite ? "YES" : "NO")<<endl;
	}
	return 0;
}

C++: 

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>

using namespace std;
typedef long long ll;
int mod(ll a){
    int c=a%1000000007;
    if(c>=0)return c;
    else return c+1000000007;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/

/////////////////////////////////


int a[10];
stack<int>b,c;
bool flag=false;
void dfs(int k){
    if(k==10){
        flag=true;
        return;
    }
    if(b.top()<a[k]){
        b.push(a[k]);
        dfs(k+1);
        b.pop();
    }
    if(c.top()<a[k]){
        c.push(a[k]);
        dfs(k+1);
        c.pop();
    }
    return;
}


int main(){
    int n;cin>>n;
    while(n--){
        flag=false;
        for(int i=0;i<=9;i++)scanf("%d",&a[i]);
        b.push(a[0]),c.push(0);
        dfs(1);
        if(flag==true)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

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

int main() {
	int n, x;
	cin >> n;
	for (int lop = 0, a = 0, b = 0; lop < n; lop++) {
		bool f = true;
		for (int i = 0; i < 10; i++) {
			cin >> x;
			if (f) {
				if (a < x && b < x) {
					if (a < b) {
						b = x;
						continue;
					}
					a = x;
					continue;
				}
				if (a < x) {
					a = x;
					continue;
				}
				if (b < x) {
					b = x;
					continue;
				}
				f = false;
			}
		}
		cout << (f ? "YES" : "NO") << endl;
	}
	return 0;
}

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

#define MAX 10	// ÊÌ

int main()
{
	stack<int> B, C;
	int A;
	int n;
	int i;
	int flag;

	cin>>n;
	for (i = 0; i < n; i++) {
		while(B.size()) B.pop();
		while(C.size()) C.pop();
		flag = 1;
		while (B.size()+C.size() < MAX) {
			cin>>A;

			if (B.size()==0) {
				B.push(A);
				continue;
			}
			else if (C.size()==0) {
				C.push(A);
				continue;
			}

			if (B.top() >= C.top()) {
				if (B.top() < A) {
					B.push(A);
				} else if (C.top() < A) {
					C.push(A);
				} else {
					cout<<"NO"<<endl;
					flag = 0;
					break;
				}
			} else {
				if (C.top() < A) {
					C.push(A);
				} else if (B.top() < A) {
					B.push(A);
				} else {
					cout<<"NO"<<endl;
					flag = 0;
					break;
				}
			}
		}
		if (flag) cout<<"YES"<<endl;
	}

	return 0;
}