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>

using namespace std;

bool flag;
void Search(int a[], int pos, int b, int c)
{
	if(pos == 10)
	{
		flag = true;
	}
	if(b > a[pos] && c > a[pos])
	{
		return;
	}
	if(b < a[pos])
	{
		Search(a, pos + 1, a[pos], c);
	}
	if(c < a[pos])
	{
		Search(a, pos + 1, b, a[pos]);
	}
}

void solve()
{
	int N;
	cin >> N;
	while(N--)
	{
		flag = false;
		int A[10];
		for(int i = 0; i < 10; ++i)
		{
			cin >> A[i];
		}
		int B = 0, C = 0;
		Search(A, 0, B, C);
		if(flag)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
int N, acnt, bcnt;
int x[10], A[10], B[10];

bool dfs(int cnt) {
    if (cnt == 10) return true;
    // Aに入れる
    if (A[acnt] < x[cnt]) {
        A[++acnt] = x[cnt];
        return dfs(cnt+1);
    }
    // Bに入れる
    else if (B[acnt] < x[cnt]) {
        B[++bcnt] = x[cnt];
        return dfs(cnt+1);
    }
    return false;
}

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

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

stack<int> array1,array2;
int Balls[10];

bool DFS(int number,stack<int> s1,stack<int> s2){
  if(number > 9) return true;
  if(s1.top() < Balls[number]){
    s1.push(Balls[number]);
    if(DFS(number+1,s1,s2)){
      return true;
    }
    s1.pop();
  }
  if(s2.top() < Balls[number]){
    s2.push(Balls[number]);
    if(DFS(number+1,s1,s2)){
      return true;
    }
    s2.pop();
  }
  return false;
  /*if(number > 9) return;
  if(firstarray){
    if(array1.top() < Balls[number]){
      array1.push(Balls[number]);
      DFS(number+1,false);
      DFS(number+1,true);
    }
    else if(second){
      return;
    }
    else{
      DFS(number,false,true);
    }
  }
  else{
    if(array2.top() < Balls[number]){
      array2.push(Balls[number]);
      DFS(number+1,false);
      DFS(number+1,true);
    }
    else if(second){
      return;
    }
    else{
      DFS(number,true,true);
    }
  }*/
}

int main(){

    int N;

    cin >> N;

    for(int i=0;i<N;i++){
      for(int i=0;i<10;i++){
        cin >> Balls[i];
      }
      array1.push(0);
      array2.push(0);

      if(DFS(0,array1,array2)){
        cout << "YES" << endl;
      }
      else{
        cout << "NO" << endl;
      }
      while (!array1.empty()) {
        array1.pop();
      }
      while (!array2.empty()) {
        array2.pop();
      }
    }
    return 0;
}

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

using namespace std;


int q;
int Ball[10];
bool flag;
vector<string> log;

bool is_satisfies(vector<int> a) {
    vector<int> copy = a;
    sort(a.begin(), a.end());
    return a == copy;
}

void bfs(int i, vector<int> B, vector<int> C) {
    if (i == 9) {
        if (is_satisfies(B) && is_satisfies(C))
            flag = true;
        else
            flag = flag == true ? true : false;
    } else {
        vector<int> temp;

        temp = B;
        temp.push_back(Ball[i]);
        bfs(i + 1, temp, C);

        temp = C;
        temp.push_back(Ball[i]);
        bfs(i + 1, B, temp);
    }
}

void solve() {
    vector<int> B, C;
    flag = false;

    bfs(0, B, C);

    if (flag)
        log.push_back("YES");
    else
        log.push_back("NO");
}

int main() {
    cin >> q;
    for (int i = 0; i < q; ++i) {
        for (int j = 0; j < 10; ++j)
            scanf("%d", &Ball[j]);

        solve();
    }

    for (int i = 0; i < log.size(); ++i) {
        cout << log[i] << endl;
    }
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;

int pow(int a,int n){
	if(n <= 0){
		return 1;
	}
	return a * pow(a,n - 1);
}

int main(){
	int n;
	int a[10];
	int ans1 = 0;
	int ans2 = 0;
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		ans1 = 0;
		ans2 = 0;
		for(int j = 0; j < 10; j++){
			scanf("%d",&a[j]);
		}
		for(int j = 0; j < 10; j++){
			if(ans1 >= ans2 && ans1 < a[j]){
				ans1 = a[j];
			}else if(ans2 > ans1 && ans2 < a[j]){
				ans2 = a[j];
			}else if(ans1 < a[j]){
				ans1 = a[j];
			}else if(ans2 < a[j]){
				ans2 = a[j];
			}else{
				printf("NO\n");
				break;
			}
			if(j == 9){
				printf("YES\n");
			}
		}
	}
	///////////////////////////////////
	//Sleep(200000);///////////////////// 提出するときは必ず外す！
	///////////////////////////////////
	return 0;

}

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

#define size 10

bool dfs(int a[],int i,int b,int c){
  if(i==0)return 1;

  bool flag=0;

  if(a[size-i]>b){
    flag += dfs(a,i-1,a[size-i],c);
  }
  if(a[size-i]>c){
    flag += dfs(a,i-1,b,a[size-i]);
  }

  return flag;
}

int main(){
  int n;
  cin >> n;
  while(n>0){
    int a[size];

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

    if(dfs(a,size,0,0)){
      cout << "YES\n";
    }else{
      cout << "NO\n";
    }

    n--;
  }

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
 
#define REP(i,b,n) for(int i=b;i<n;++i)
#define REPR(i,b,n) for(int i=n-1;i>=b;--i)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n>>b) & 1)
#define PI acos(-1.0)

using namespace std;

static const double EPS = 1e-9;
typedef pair<int, int> pii;
typedef long long ll;

int ball[10];

bool issorted(vector<int> v){

	if(v.size() < 2)
		return true;
	
	for(int i = 0 ; i < v.size()-1; ++i){
	
		if(v[i] > v[i+1])
			return false;
	}
	
	return true;
}

string solve(){
	
	for(int i=0; i < (1<<10); ++i){
		
		vector<int> lft, rgt;
		
		for(int j=0; j<10; ++j){
			
			if(BIT(i,j))
				lft.push_back(ball[j]);
			else
				rgt.push_back(ball[j]);
		}
		
		if(issorted(lft)&& issorted(rgt)){
			return "YES";
		}
	}
	
	return "NO";
}		

int main(){
		
	int n;
	cin >> n;
	
	for(int k=0; k<n; ++k){
	
		for(int i=0; i<10; ++i){
			cin >> ball[i];
		}
		
		cout << solve() << endl;
	}
	
	return 0;
}