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++: /*
 * AOJ 0033: Ball
 * ?¢????????????????1-10???10???????????????????????????????????\2????????????????????????????????\??????????????????????¢????????????????????????¨???
 * ?±???????DFS
 * ?????????????????????????????\??§???????????¶???????´????????????\??°?????\????????¶??§????????????
 */

#include <cstdio>
#include <iostream>

using namespace std;

int a[10], b[2][10];
int len[2];
bool ans;


void dfs(int step) {
  if (ans) return;
  if (step == 10) {
    ans = true;
    return;
  }
  for (int i = 0; i < 2; ++i) {
    if (len[i] == 0 || a[step] > b[i][len[i] - 1]) {
      b[i][len[i]++] = a[step];
      dfs(step + 1);
      --len[i];
    }
  }
}

void solve() {
  ans = false;
  for (int i = 0; i < 10; ++i) {
    cin >> a[i];
  }
  dfs(0);
}

int main() {
  int T;
  cin >> T;
  while (T--) {
    solve();
    cout << (ans ? "YES" : "NO") << endl;
  }
  return 1;
}

C++: #include<iostream>
#include<cstring>
#include<stack>
using namespace std;
int a[15],t;
int map[2][15];
stack<int>s[2];
void dfs(int g){
	if(g==10){
		t=1;
		return;
	}
	if(t==1)
	return;
	for(int i=0;i<2;i++){
		if(s[i].size()==0||s[i].top()<a[g]){
			s[i].push(a[g]);
			dfs(g+1);
			s[i].pop();
		}
	}
}
int main(){
	int loop;
	cin>>loop;
	while(loop--){
		for(int i=0;i<10;i++)
		cin>>a[i];
		t=0;
		for(int i=0;i<2;i++)
		while(!s[i].empty())
		s[i].pop();
		dfs(0);
		for(int i=0;i<2;i++)
		while(!s[i].empty())
		s[i].pop();
		if(t==1)
		cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

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

using namespace std;

int n;
int a[1000][11];
int stock[2][11];
int usea[11];

int dfs(int num, int r_num, int l_num) {
	int res = 0;

	if (usea[num] > stock[0][r_num]) {
		if (num == 9)
			return 1;
		stock[0][r_num + 1] = num;
		res = dfs(num + 1, r_num + 1, l_num);
		stock[0][r_num + 1] = -1;
		return res;
	}
	else if (usea[num] > stock[1][l_num]) {
		if (num == 9)
			return 1;
		stock[1][l_num + 1] = num;
		res = dfs(num + 1, r_num, l_num + 1);
		stock[1][l_num + 1] = -1;
		return res;
	}
	else {
		return 0;
	}
}


int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> a[i][j];
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			usea[j] = a[i][j];
		}
		stock[0][0] = -1;
		stock[0][1] = usea[0];
		stock[1][0] = -1;
		if (dfs(0, 1, 0)) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
		stock[0][0] = -1;
		stock[0][1] = -1;
		stock[1][0] = -1;
	}

	return 0;
}

C++: #include<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
bool sorted(vector<int> a){
	for(int x=0;x<a.size()-1;++x){
		if(a[x]>a[x+1])return false;
	}
	return true;
}
int main(){
	int n;
	cin>>n;
	for(int x=0;x<n;++x){
		vector<int> a,b;
		for(int x=0;x<10;++x){
			int j;cin>>j;
			if(x%2==0){
				a.push_back(j);
			}else{
				b.push_back(j);
			}
		}
		if(sorted(a) && sorted(b)){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}		
	}
	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>
#include<cstdlib>
#include<cmath>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;

int N;

int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };

int ball[10];

int B = 0, C = 0;

int bfs(int n) {
	if (n = 9) {
		return true;
	}

	if (B < ball[n]) {
		return bfs(n + 1);
	}
	if (C < ball[n]) {
		return bfs(n + 1);
	}
	
	return false;

}

void input(void) {
	for (int i = 0; i < 10; i++) {
		CI ball[i];
	}
	return;
}


int main(void) {
	CI N;

	for (int i = 0; i < N; i++) {
		input();
		if (bfs(0)) {
			CO "YES" E
		}
		else {
			CO "NO" E
		}
	}
	
	return 0;
}

C++: #include <iostream>

using namespace std;

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

C++: #include<cstdio>
/*
2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
3 5 4 6 1 2 7 8 9 10
4 5 6 7 8 9 1 2 3 10
*/
int n;
int a[12];

int  dsf(int x, int num){
    //将所在数字???-1
    a[x] = -1;
    //向后遍?数?，?足条件?将num???当前数字，并且?用本方法。

    int flag2 = 0;

    for(int i = x; i < 10; i++){

        if(a[i] == num + 1){

            num = a[i];
            dsf(i,num);

            flag2 ++;//只要?行??条件，????1
        }
    }
    if(flag2 == 0)//?明数?中元素不符合条件
             return 0;
    if(flag2 > 2)
             return 0;
    return 1;
}
int main(){

    scanf("%d",&n);
    int i=1;
    while(i <= n){
        int flag = 1;

        //存数据
        for(int x = 0; x < 10; x++){
            scanf("%d",&a[x]);
        }

        //?用方法，将?足条件的数字改?-1
        for(int x = 0; x < 10; x++){
            if(a[x] != -1)
                if(dsf(x,a[x]) == 0)                     //只要??数?中有一个元素不符合条件，?跳出，避免将所有数据?入并???-1
                    break;
        }

        //遍?数?的数?是否都?-1
        for(int x = 0; x < 10; x++){

            if(a[x] != -1)
                flag = 0;
        }
        //判断并?出?果
        if(flag == 1) printf("YES\n");
            else printf("NO\n");

        i++;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int A[15];
int L[15];int R[15];
int n;

bool dfs(int i, int j, int k)
{
	
	if(i==10) return true;
	if(A[i] > L[j-1])
	{
		L[j] = A[i];
		if(dfs(++i,++j,k))
			return true;
	}
	if(A[i] > R[k-1])
	{
		R[k] = A[i];
		if(dfs(++i,j,++k))
			return true;	
	}	
	return false;
}
void solve()
{

	if(dfs(0,1,1))
		cout << "YES"<<endl;
	else
		cout <<"NO"<<endl;
}

int main()
{
	
	cin >>n;
	while(n--)
	{
		for(int i =0; i<10; i++)
			cin >> A[i];
		L[0] = R[0] = 0;		
		solve();
	}
}