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;
#define rep(i,n) for(int i=0;i<n;i++)
 
int a[10];
int n;
 
bool dfs(int i,int left,int right){
    if(i==10) return true;
    if(a[i]>left){
        return dfs(i+1,a[i],right);
    }
    if(a[i]>right){
        return dfs(i+1,left,a[i]);
    }
    return false;
}
 
void solve(){
    rep(i,10) cin >> a[i];
    if(dfs(0,0,0)) cout << "YES" << endl;
    else cout << "NO" << endl;
    return;
}
 
int main(){
    cin >> n;
    rep(i,n){
        solve();
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <climits>
#include <utility>

#define PRINT(STR) cout << STR << endl;
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define SPACE " "

typedef long long ll;

using namespace std;

int nextInt() { int n = -1; cin >> n; return n; }
double nextDouble() { double d = -1; cin >> d; return d; }
ll nextll() { ll n = -1; cin >> n; return n; }
string nextString() { string str; cin >> str; return str; }

int INF = 1LL << 25;
double EPS = 1e-9;
int numofbits(int bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

// BEGIN //////////////////////////////////////////////////////////////
int main() {
  int N = nextInt();
  REP(i, N) {
    stack<int> bs, cs;
    bool flag = true;
    bs.push(0);
    cs.push(0);
    REP(j, 10) {
      int a = nextInt();
      if (bs.top() < a) {
        if (cs.top() < a) {
          if (bs.top() > cs.top()) {
            bs.push(a);
          } else {
            cs.push(a);
          }
        } else {
          bs.push(a);
        }
      } else if (cs.top() < a) {
        cs.push(a);
      } else {
        flag = false;
        break;
      }
    }
    if (flag) {
      PRINT("YES");
    } else {
      PRINT("NO");
    }
  }
	return 0;
}
// END   //////////////////////////////////////////////////////////////

C++: #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

int main(){
    int n,b,B=0,C=0;
    
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        B=0;C=0;
        for(int j=0;j<10;j++){
            scanf("%d",&b);
            if(B==0 || B==b-1)
                B=b;
            else if(C==0 || C==b-1)
                C=b;
            else{
                B=0;C=0;
                break;
            }
        }
        if(B==10 || C==10)
            puts("YES");
        else
            puts("NO");
    }
}

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

using namespace std;

int main() {
	int A[10];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++)
			cin >> A[j];
		stack<int> B, C;
		string ans = "YES";
		for (int j = 0; j < 10; j++) {
			int k = A[j];
			if (B.empty() == true && C.empty() == true)
				B.push(k);
			else if (B.empty() != true && C.empty() == true) {
				if (B.top() < k)
					B.push(k);
				else
					C.push(k);
			}
			else {
				if (B.top() > k && C.top() > k) {
//					cout << k << " " << B.top() << " " << C.top() << endl;
					ans = "NO";
					break;
				}
				else if (B.top() > C.top())
					B.push(k);
				else
					C.push(k);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
bool canbe = false;
string inp;

void dfs(int b, int c, int depth){
    if (depth >= 9){ canbe = true; return; }
    if (inp[depth] - '0' < b && inp[depth] - '0' < c) return;

    if (inp[depth] - '0' > b) dfs(inp[depth] - '0', c, depth+1);
    if (inp[depth] - '0' > c) dfs(b, inp[depth] - '0', depth+1);
}


int n;
int main(){
    cin >> n;
    for (int i = 0; i < n; i++){
	canbe = false;
	inp = "";
	string g;
	for (int j = 0; j < 10; j++){
	    cin >> g;
	    inp += g;	    
	}
	dfs(0, 0, 0);

	if (canbe) cout << "YES" << endl;
	else cout << "NO" << endl;
    }
}

C++: #include <stdio.h>

int
main(void)
{
	char line[80];

	int b[10];

	int n;
	
	if (fgets(line, sizeof line, stdin) == NULL) {
		return 0;
	}
	if (sscanf(line, "%d", &n) != 1) {
		return 0;
	}

	while (n--) {
		fgets(line, sizeof line, stdin);
		sscanf(line, "%d %d %d %d %d %d %d %d %d %d",
			   &(b[0]), &(b[1]), &(b[2]), &(b[3]), &(b[4]), &(b[5]),
			   &(b[6]), &(b[7]), &(b[7]), &(b[9]));

		bool f = true;
		int s0 = 0;
		int s1 = 0;
		for (int t : b) {
			if (t > s0 && t > s1) {
				if (t - s0 <= t - s1) {
					s0 = t;
				} else {
					s1 = t;
				}
			} else 	if (t > s0) {
				s0 = t;
			} else 	if (t > s1) {
				s1 = t;
			} else {
				f = false;
				break;
			}
		}
		printf("%s\n", (f ? "YES" : "NO"));
	}

	return 0;
}

C++: #include<iostream>
main(){
int n,i,A,B,C,f;
for(std::cin>>n;n-->0;puts(f?"NO":"YES"))
 for(B=C=f=i=0;i++<10;){
  std::cin>>A;
  if(B<A)B=A;else C<A?C=A:f=1;
 }
}

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

int B[11]={0};
int C[11]={0};

bool DFS(int *a,int i=0,int b=1,int c=1)
{
	bool judge=true;

	if(i==10)
		return judge;

	judge=false;

	if(B[b-1]<a[i]){
		B[b]=a[i];
		judge=DFS(a,i+1,b+1,c);
		
	}
	if(C[c-1]<a[i]){
		C[c]=a[i];
		judge=DFS(a,i+1,b,c+1);
		
	}

	return judge;
}        

int main()
{
        int N;
	int i=0;
        cin>>N;

		while(i<N){
			int A[10]={0};
			for(int i=0;i<10;i++)
				cin>>A[i];

            ??????????????????if(DFS(A)==true)
                ????????????????????????cout<<"YES"<<endl;
            ??????????????????else
		????????????????????????cout<<"NO"<<endl;

	????????????????????????i++;
        }
                
	
        return 0;
}

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

using namespace std;

int main(){
  int f;
  int n;
  int in,b,c;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    f=b=c=0;
    for(int j=0;j<10;j++){
      scanf("%d",&in);
      if(!f){
	if(in<=min(b,c)){
	  f=1;
	}
	if((b>=c && b<in)||(b<c && c>in))b=in;
	else c=in;
      }
    }
    if(f)printf("NO\n");
    else printf("YES\n");
  }
}

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

int arr[10];
bool flag;

void dfs(int num, int l, int r) {
  if(num==10) {
    flag = true;
    return;
  }

  if(arr[num] > l) dfs(num+1, arr[num], r);
  if(arr[num] > r) dfs(num+1, l, arr[num]);
  return;
}

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

    flag = false;
    dfs(0,0,0);
    if(flag)
      printf("YES\n");
    else
      printf("NO\n");
  }
}