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>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;
#define FOR(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;

int main(void){
	queue <int> rque, lque;
	int N;
	cin >> N;
	for(int k = 0; k < N; k++){
		int have[10];
		for(int j = 0; j < 10; j++){
			cin >> have[j];
		}
		int set = have[9];
		have[9] = -1;
		for(int i = 8; i >= 0; i--){
			if(set > have[i]){
				set = have[i];
				have[i] = -1;
			}
		}
		for(int i = 8; i >= 0; i--){
			if(have[i] != -1){
				set = have[i];
				have[i] = -1;
				break;
			}
		}
		for(int i = 8; i >= 0; i--){
			if(have[i] != -1 && set > have[i]){
				set = have[i];
				have[i] = -1;
			}
		}
		for(int i = 0; i < 10; i++){
			if(have[i] != -1){
				cout << "NO" << endl;
				break;
			}else{
				cout << "YES" << endl;
				break;
			}
		}

	}

	return 0;	
}

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

int main(){
  int N,t,B,C;
  cin >> N;
  for(int i = 0 ; i < N ; i++){
    B = C = 0;
    for(int j = 0; j < 10; j++){
      cin >> t;
      if(B > t && C > t){
	cout << "NO" << endl;
	break;
      }
      else if(B < t && C < t){
	if(B < C) C = t;
	else B = t;
      }
      else if(B < t) B = t;
      else if(C < t) C = t;
      if(j == 9) cout << "YES" << endl;
    }
  }
  return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)


int main(){
	
	int n;
	cin>>n;
	
	rep(loop, n){
		int m=10;
		int in[10];
		bool ans = false;
		rep(i,m)cin>>in[i];
		rep(i,(1<<m)){
			vector<int> a;
			vector<int> b;
			rep(j,m){
				if((i&(1<<j))>0)a.push_back(in[j]);
				else b.push_back(in[j]);
			}
			
			bool ok=true;
			rep(j,a.size()-1)if(a[j]>a[j+1])ok=false;
			rep(j,b.size()-1)if(b[j]>b[j+1])ok=false;
			if(ok)ans=true;
		}
		if(ans)puts("YES");
		else puts("NO");
	}
	
}

C++: #include <iostream>
using namespace std;
int d[10];
int l;
int r;

bool choose(int i, bool b);

int main() {
  int n;
  cin >> n;

  for (int i=0; i<n; i++) {
    for (int j=0; j<10; j++) {
      cin >> d[j];
    }
    l = r = 0;
    if (choose(0, true)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }

}

bool choose(int i, bool b) {
  int old;
  int *p;
  if (b) p = &l;
  else p = &r;
  if (d[i] > *p) {
    if (i == 9) return true;
    old = *p;
    *p = d[i];
    if (choose(i+1, true)) return true;
    if (choose(i+1, false)) return true;
    *p = old;
    return false;
  } else {
    return false;
  }
}

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

int num[10];
int left_num[10], right_num[10];
int l, r;

bool dfs(int i) {
	if (i == 10) {
		return true;
	}
	if (i == 0) {
		left_num[l] = num[i];
		return dfs(i + 1);
	}
	if (left_num[l] < num[i]) {
		l++;
		left_num[l] = num[i];
		return dfs(i + 1);
	}
	if (right_num[r] < num[i]) {
		if (r == 0) {
			right_num[r] = num[i];
			return dfs(i + 1);
		} else {
			r++;
			right_num[r] = num[i];
			return dfs(i + 1);
		}
	}
	return false;
}

int main(void) {
	int i, N;
	scanf("%d", &N);

	while (N--) {
		l = 0, r = 0;
		for (i = 0; i < 10; i++) {
			scanf("%d", &num[i]);
			left_num[i] = 0;
			right_num[i] = 0;
		}
		if (dfs(0)) {
			printf("YES\n");
		} else {
			printf("NO\n");
		}
	}

	return 0;
}

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

int main(void)
{
	int N,ball,B = 0,C = 0;
	bool ans;
	cin >> N;
	for (int i = 0; i < N; i++) {
		C = 0;
		cin >> B;
		ans = true;
		for (int j = 1;j < 10; j++) {
			cin >> ball;

			int b = ball - B;
			int c = ball - C;

			if (b < 0 && c < 0 || !ans) {
				ans = false;
				continue;
			}
			else {
				if (b > 0 && c < 0 || b > 0 && c > 0 && b < c) {
					B = ball;
				}
				else if (b < 0 && c > 0 || b > 0 && c > 0 && b > c) {
					C = ball;
				}
			}
		}
		cout << (ans ? "YES" : "NO") << endl;
	}
	if (N == 0) {
		cout << endl;
	}
}

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

int main()
{
	int n,t,a,b,f;

	cin >> n;
	while(n--)
	{
		a=b=f=0;
		for(int i=0; i<10; i++)
		{
			cin >> t;

			if(t-a<0 && t-b<0)
			{
				f=1; break;
			}
			else if(t-a<0)		b=t;
			else if(t-b<0)		a=t;
			else if(t-a<t-b)	a=t;
			else				b=t;
		}
		cout << (f?"NO":"YES") << endl;
	}
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>

int N;
int M = 10;
int **inData;
int *lTube;
int *rTube;

bool dfs(int n, int i, int l, int r)
{
	if (i==M)
		return true;

	//left tube
	if (l==-1 || inData[n][i]>lTube[l]) {
		lTube[l+1] = inData[n][i];
		if (dfs(n, i+1, l+1, r)) return true;
	}

	//right tube
	if (r==-1 || inData[n][i]>rTube[r]) {
		rTube[r+1] = inData[n][i];
		if (dfs(n, i+1, l, r+1)) return true;
	}

	//failed
	return false;
}

int main()
{
	int n, i, j;

	while (1) {

		//input & allocate memory
		if (scanf("%d ", &N) == EOF) break;

		inData = (int **)calloc(N, sizeof(int *));
		for (i=0; i<N; i++) {
			inData[i] = (int *)calloc(M, sizeof(int));
			
			for (j=0; j<M; j++)
				scanf("%d ", &(inData[i][j]));
		}

		lTube = (int *)calloc(M, sizeof(int));
		rTube = (int *)calloc(M, sizeof(int));

		for (n=0; n<N; n++) {
			for (i=0; i<M; i++)
				lTube[i] = rTube[i] = 0;

			//dfs & output
			if (dfs(n, 0, -1, -1))
				printf("YES\n");
			else
				printf("NO\n");
/*			
			printf("Left:\n");
			for (i=0; i<M; i++)
				printf("%d ", lTube[i]);
			puts("");
			printf("Right:\n");
			for (i=0; i<M; i++)
				printf("%d ", rTube[i]);
			puts("");
			printf("------------------\n");
*/
		}
/*
		for (i=0; i<N; i++) {
			for (j=0; j<M; j++)
				printf("%d ", inData[i][j]);
			puts("");
		}
*/
		//free memory
		for (i=0; i<N; i++)
			free(inData[i]);
		free(inData);
		free(lTube);
		free(rTube);
	}

	return 0;
}