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;
int main(){
  int t;
  cin >> t;
  int n[10];
  int b[10]={0};
  int c[10]={0};
  int bcount=0,ccount=0,h=0;
  for(int i=0;i<t;i++){
    for(int j=0;j<10;j++) cin >> n[j];
    for(int j=0;j<10;j++){
      if(b[0]==0) b[bcount] = n[j];
      else if(b[bcount]>c[ccount]&&b[bcount]<n[j]){
    bcount++;
    b[bcount] = n[j];
      }
      else if(c[ccount]>b[bcount]&&c[ccount]<n[j]){
    if(c[ccount]!=0) ccount++;
    c[ccount] = n[j];
      }
      else if(b[bcount]>c[ccount]&&b[bcount]>n[j]&&c[ccount]<n[j]){
    if(c[ccount]!=0) ccount++;
    c[ccount] = n[j];
      }
      else if(c[ccount]>b[bcount]&&c[ccount]>n[j]&&b[bcount]<n[j]){
    bcount++;
    b[bcount] = n[j];
      }
      else if(b[bcount]>n[j]&&c[ccount]>n[j]){
    cout << "NO" << endl;
    h = 1;
    break;
      }
    }
    if(h==0) cout << "YES" << endl;
    for(int i=0;i<10;i++){
      b[i] = 0;
      c[i] = 0;
    }
      bcount = 0;
      ccount = 0;
      h = 0;
  }
  return 0;
}

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

int main(){
	int n,a,flag;
	stack<int> b,c;
	cin >> n;
	for (int i = 0; i < n; i++){
		while (b.size()) b.pop();
		while (c.size()) c.pop();
		flag = 0;
		b.push(0);
		c.push(-1);
		for (int j = 0; j < 10; j++) {
			cin >> a;
			if (b.top() > c.top()){
				if (c.top() > a) flag = 1;
				else if (b.top() > a) c.push(a);
				else b.push(a);
			}
			else {
				if (b.top() > a) flag = 1;
				else if (c.top() > a) b.push(a);
				else c.push(a);
			}
		}
		if (flag) cout << "NO" << endl;
		else cout << "YES" << endl;
	}
}

C++: #include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <iostream>
using namespace std;
int n;
int a[15],b[15],c[15];
bool dfs(int i,int j)
{
    if(i + j == 10)
        return true;
    if(a[i] > b[i - 1]){
        b[i] = a[i];
        dfs(i + 1,j);
    }
    else
    {
        if(a[j] > c[j - 1]){
            c[j] = a[i];
            dfs(i,j + 1);
        }
    }
}
int main()
{
    while(~scanf("%d",&n))
    {
        while(n --){
            for(int i = 0; i < 10; i++)
                scanf("%d",&a[i]);
            memset(b,0,sizeof(b));
            memset(c,0,sizeof(c));
            int ans = dfs(0,0);
            if(ans == true)
                printf("YES\n");
            else
                printf("NO\n");
        }
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define INF INT_MAX/3
#define vc vector<int>
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define ll long long
#define eps 1e-14
int dx[] = { 1,-1,0,0,0 };
int dy[] = { 0,0,1,-1,0 };


int x[10];
vc ans;
void solve() {
	int left, r;
	left = x[0];
	r = 0;
	//?????¨?????§??§??????????????§?????¶??????????????´???????????\??????
	for (int i = 1; i < 10; i++) {
		//???????????¶??????????????????
		if (left > x[i] && r > x[i]) {
			//cout << "NO" << endl;
			ans.push_back(0);
			return;
		}
		//?????????????????¶????????????
		if (x[i] < left && r < x[i]){
			r = x[i];
			continue;
		}
		else if (x[i] < r&&left < x[i]) {
			left = x[i];
			continue;
		}
		else { //???????????????????????´???
			if (r < left) {
				left = x[i];
				continue;
			}
			else {
				r = x[i];
				continue;
			}
		}
		
	}
	//cout << "Yes" << endl;
	ans.push_back(1);
}

int main() {
	int n;
	cin >> n;
	REP(i, n) {
		REP(j, 10)
			cin >> x[j];
		solve();
	}
	for (int i = 0; i < ans.size(); i++) {
		if (ans[i] == 0)
			cout << "NO" << endl;
		else
			cout << "YES" << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int N;
  cin>>N;
  while(N--){
    int B,C=0,i=0,b[10];
    bool f=true;
    cin>>b[0]>>b[1]>>b[2]>>b[3]>>b[4]>>b[5]>>b[6]>>b[7]>>b[8]>>b[9];
    while(i<10){
      if(b[i]<B&&b[i]<C){
	f=false;break;
      }else if(B<b[i]){
	if(B<C&&C<b[i])C=b[i];
	else B=b[i];
      }else if(C<b[i]){
	C=b[i];
      }
      i++;
    }
    cout<<(f?"YES":"NO")<<endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
int a,b,temp,n;
int main()
{
    int n;
    cin>>n;
    while(n--){
        int flag=1;
        a=0,b=0;
        queue<int>que;
        //while(que.size())que.pop();
        for(int i=0;i<10;i++){
            cin>>temp;
            que.push(temp);
        }
        while(que.size()){
            temp=que.front();
            que.pop();
            if(temp<=a&&temp<=b){
                cout<<"NO\n";
                flag=0;
                break;
            }
            else if(temp<=a&&temp>b)b=temp;
            else if(temp<=b&&temp>a)a=temp;
            else {
                if(a>=b)a=temp;
                else b=temp;
            }
        }
        if(flag)cout<<"YES\n";
    }

    return 0;
}

C++: //-*-coding:utf-8-*-
//----------------------------------------------------------
// module: main
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0033
//----------------------------------------------------------
#include <algorithm>
#include <vector>
#include <deque>
#include <map>

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

const int MAXL = 10;

int numbers[MAXL];

bool solve(){
    int a = -1;
    int b = -1;
    for (int i = 0; i < 10; ++i)
        {
            if (a > b && b > 0) {
                if (numbers[i] > a) { a = numbers[i]; }
                else if (numbers[i] > b) { b = numbers[i]; }
                else return false;
            }
            else if (b > a && a > 0){
                if (numbers[i] > b) { b = numbers[i]; }
                else if (numbers[i] > a) { a = numbers[i]; }
                else return false;
            }
                
            if(a < 0){a = numbers[i]; continue; };
            if(b < 0){b = numbers[i]; continue; };
        }
    return true;
};

int main(int argc, char *argv[])
{
    int c;
    scanf("%d", &c);
    for (int i = 0; i < c; ++i)
        {
            scanf("%d %d %d %d %d %d %d %d %d %d", &numbers[0], &numbers[1], &numbers[2], &numbers[3], &numbers[4], &numbers[5], &numbers[6], &numbers[7], &numbers[8], &numbers[9]);
            bool result = solve();
            if ( solve() ){ printf("YES\n"); }
            else { printf("NO\n"); }
        }
    return 0;
}