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 <stdio.h>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <string.h>
#include <set>
#include <queue>
#include <cmath>
#include <algorithm>

using namespace std;

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

int input[20];

int main()
{
	int i , j , mask , n;
	while (scanf("%d" , &n) != EOF)
	{
		for (i = 0;i < n;i ++)
		{
			bool ok = false;

			for (j = 0;j < 10;j ++)
				scanf("%d" , &input[j]);

			for (mask = 0;mask < (1 << 10);mask ++)
			{
				vector<int> v1 , v2;
				for (j = 0;j < 10;j ++)
				{
					if (mask & (1 << j))
						v1.push_back(input[j]);
					else
						v2.push_back(input[j]);
				}
				if (check(v1) && check(v2))
				{
					ok = true;
					break;
				}
			}

			if (ok)
				printf("YES\n");
			else
				printf("NO\n");
		}
	}
	return 0;
}

C++: #include <stdio.h>
int a[10];
int dfs(int l,int r,int i){
  if(i==10)return 1;
  if(a[i]>l&&dfs(a[i],r,i+1))return 1;
  if(a[i]>r&&dfs(l,a[i],i+1))return 1;
  return 0;
}
int main(){
  int n;
  scanf("%d",&n);
  for(;n;n--){
    scanf("%d %d %d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);
    dfs(0,0,0)?printf("YES\n"):printf("NO\n");
  }
  return 0;
}

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

int main()
{
	int n, ball;
	queue<pair<int, int> > qu;

	cin >> n;

	for (int i=0; i<n; i++){
		bool flag = false;
		int rem;

		cin >> ball;
		qu.push(make_pair(ball, 0));

		for (int j=0; j<9; j++){
			cin >> ball;

			while (!qu.empty() && ball != qu.front().first && ball != qu.front().second)
			{
				if(qu.front().first < ball){
					qu.push(make_pair(ball, qu.front().second));
					//cout << ball << ',' << qu.front().second << ' ';	//debug
				}
				else if(qu.front().second < ball){
					qu.push(make_pair(qu.front().first, ball));
					//cout << qu.front().first << ',' << ball;	//debug
				}

				//cout << endl; //debug
				
				qu.pop();
				//if(qu.empty())	break;
			}

			if(qu.empty()){
				rem = j+1;
				break;
			}
			if(j==8 && !qu.empty()){
				rem = 9;
				flag = true;
			}
		}

		for(; rem < 9; rem++)	cin >> ball;

		if(flag)	cout << "YES" << endl;
		else		cout << "NO" << endl;
		
		while (!qu.empty()) qu.pop();
	}

	return 0;
}

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

signed main(void)
{
  stack<int> b, c;
  int n;
  int B, C = 0;

  cin >> n;

  for (int j = 0; j < n; j++){
    bool frag = true;
    int a[10];
    for (int k = 0; k < 10; k++) cin >> a[k];
   
    for (int i = 0; i < 10; i++){
      if (i == 0) {
        B = a[i];
        b.push(a[i]);
      }
      else if (B > a[i] && C < a[i]) {
        C = a[i];
        c.push(a[i]);
      }
      else if (B < a[i]) {
        B = a[i];
        b.push(a[i]);
      }
      else {
        frag = false;
        break;
      }
    }
    if (frag) puts("YES");
    else puts("NO");
  }

  return 0;
}

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

int main() {
	int n, balls[10]; cin >> n;
    while(n--){
        for(int i = 0; i < 10; i++){
            cin >> balls[i];
        }
        
        bool sortable = false;
        stack<tuple<int, int, int> > states;
        
        states.push(make_tuple(0,0,0));
        while(!states.empty()){
        	tuple<int, int, int> now = states.top();
        	states.pop();
        	
        	int idx = get<0>(now);
        	if(idx < 9){
        		if(get<1>(now) < balls[idx]){
        			if(idx + 1 == 9){
        				sortable = true; break;
        			}
        			states.push(make_tuple(idx+1,balls[idx],get<2>(now)));
        		}
        		if(get<2>(now) < balls[idx]){
        			if(idx + 1 == 9){
        				sortable = true; break;
        			}
        			states.push(make_tuple(idx+1,get<1>(now),balls[idx]));
        		}
        	}        	
        }
         
        if(sortable) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

C++: #include <iostream>
using namespace std;
int main(void){
  int n;
  cin>>n;
  while(n--){
    int ans=1;
    for(int i=0,a,p=0,q=0;i<10;++i){
      cin>>a;
      if(ans){
	      if(p>=a&&q>=a) ans=0;
	      else{
	      	if(p>q) (p<a)?p=a:q=a;
	      	else (q<a)?q=a:p=a;
	      }
      }
    }
    cout<<(ans?"YES":"NO")<<endl;
  }
  return 0;
}

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

using namespace std;

#define N 10

int main(){
  int tc; //test case
  cin >> tc;

  while(tc-->0){
    //maximun 1024 pattern. try all

    int n[10];
    for(int i=0; i<N; i++){ scanf("%d", &n[i]); }

    int b, c; //tube
    bool ans = false;
    for(int i=0; i<(1<<N); i++){
      int bit=i; b=c=0;
      for(int j=0; j<N; j++){
	if(bit%2==0){ // to B
	  if(b < n[j]) b=n[j];
	  else break;
	} else { // to C
	  if(c < n[j]) c=n[j];
	  else break;
	}
	if(j==N-1){
	  ans=true;
	  goto OUT;
	}
	bit /= 2;
      }
    }

  OUT:
    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;

  }
}

C++: #include<iostream>


using namespace std;

int data[11],N;
int a[11],b[11];
int na,nb;

bool dfs(int a[],int b[],int k)
{
	if(k==11)
	  return true;
	if(data[k]>a[na])
	{
		na++;
		a[na] = data[k];
		
		if(dfs(a,b,k+1))
		 return true;
		a[na] = 0;
		na--;
	}
	if(data[k]>b[nb])
	{
		nb++;
		b[nb] = data[k];
	    if(dfs(a,b,k+1))
	     return true;
		b[nb]=0;
		nb--;
	}
	
	return false;
	
}
int main()
{
	cin>>N;
	int time=1;
	while(time++<=N)
	{
		for(int i=1;i<=10;i++)
		{
		cin>>data[i];
		a[i]=0;
		b[i]=0;
		}
		na = nb = 0;
		
		if(dfs(a,b,1)==true)
		cout<<"YES"<<endl;
		else
		 cout<<"NO"<<endl;
	}
}