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<stdio.h>
main(){
    int x[10],y[10],z[10],i,j,n,cz,cy,tmp;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        tmp=0;
        cy=0;cz=0;
        for(j=0;j<10;j++){
        scanf("%d",&x[j]);
        z[j]=0;y[j]=0;
        }
        for(j=0;j<10;j++){
        if(x[j]>=y[cy-1*(cy>0)])
        y[cy++]=x[j];
        else if(x[j]>=z[cz-1*(cz>0)])
        z[cz++]=x[j];
        else
        tmp=1;
        }
        if(tmp==1)
        printf("NO\n");
        else
        printf("YES\n");
    }
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
#include <complex>
#include <climits>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define EPS 1e-8

int main(){
	int t,data[10],A,B;
	scanf("%d",&t);
	while(t--){
		rep(i,10)scanf("%d",data+i);
		A = B = 0;
		int j;
		bool f = true;
		for(j=0; j<10; j++){
			if( A<data[j] && B<data[j] ){
				if( A<B ){
					B = data[j];
				}else{
					A = data[j];
				}
			}else if( A<data[j] ){
				A = data[j];
			}else if( B<data[j] ){
				B = data[j];
			}else{
				f = false; break;
			}
		}
		puts(f ? "YES" : "NO" );
	}
	return 0;
}

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

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

C++: //
// Created by Tnecesoc on 2017/3/22.
//

#include <cstdio>

const int MAX_N = 10 + 10;

int a[MAX_N];

int cur1, cur2;
int b1[MAX_N], b2[MAX_N];

bool dfs(int n) {

    if (n >= 10) {
        return true;
    } else {

        if (cur1 == -1 || b1[cur1] < a[n]) {
            b1[++cur1] = a[n];
            if (dfs(n + 1)) {
                return true;
            }
        }

        if (cur2 == -1 || b2[cur2] < a[n]) {
            b2[++cur2] = a[n];
            if (dfs(n + 1)) {
                return true;
            }
        }

        return false;
    }

}

int main() {

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

        printf("%s\n", dfs(0) ? "YES" : "NO");
    }

    return 0;
}

C++: #include <iostream>
using namespace std;
int ball[11];

bool bfs(int b, int c, int sum){
    if(sum == 10){
        return true;
    }
    if(b < ball[sum]){
        return bfs(ball[sum], c, sum+1);
    }
    if(c < ball[sum]){
        return bfs(b, ball[sum], sum + 1);
    }
    if(c > ball[sum] && b > ball[sum]){
        return false;
    }
}
int main(void){
    int n;
    cin >> n;
    for(int i=0; i<n ;i++){
        for(int j=0;j<10;j++){
            cin >> ball[j];
        }
        if(bfs(0, 0, 0)){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

C++: #include <iostream>

using namespace std;
const int kBalln = 10;
int main(){
  int n;
  int ball;
  int b, c;
  cin >> n;
  for (int j = 0; j < n; ++j)
    {
      b = 0; c = 0;
      for (int i = 0; i < kBalln; ++i)
        {
          cin >> ball;
          if (b < ball)
            {
              b = ball;
            }
          else if (c < ball)
            {
              c = ball;
            }
          else
            {
              cout << "NO" << endl;
              break;
            }
        }
      cout << "YES"  << endl;
    }
  return 0;
}

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

int main() {
int a[10],b[11],c[11];
int n;
cin>>n;
for (int jjj=1;jjj<=n;jjj++){
	for(int kk=0;kk<10;kk++) cin>>a[kk];
int bb=0,cc=0;
b[0]=0;
c[0]=0;
for (int k=0;k<10;k++){
	if(a[k]>b[bb] && b[bb]>=c[cc]){
		b[bb+1]=a[k];
		bb=bb+1;
	}
	else{
		c[cc+1]=a[k];
		cc=cc+1;
	}
}
	int l=0,m=0;
	for(int i=1;i<=bb;i++){
		if(b[i]-b[i-1]<0){
			l=2;
		}
	}
	for(int j=1;j<=cc;j++){
		if(c[j]-c[j-1]<0){
			m=2;
		}
	}
	if(l+m==0){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
	
}

	return 0;
}

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

array<int, 10> ary;
vector<int> lf, rt;

int main(){
	bool dfs(int );
	
	
	int n;
	scanf("%d", &n);
	for(int i  = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			int t;
			scanf("%d", &t);
			ary[j] = t;
		}
		lf.clear();
		rt.clear();
		if(dfs(0)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
} 

bool dfs(int i){
	if(i == 9){
		if(lf.size() == 0 || rt.size() == 0) return true;
		else if(ary[i] > *lf.rbegin() || ary[i] > *rt.rbegin()) return true;
		else return false;
	}
	lf.push_back(ary[i]);
	if(lf.size() == 1 || lf[lf.size() - 1] > lf[lf.size() - 2]) return dfs(i+1);
	lf.pop_back();
	rt.push_back(ary[i]);
	if(rt.size() == 1 || rt[rt.size() - 1] > rt[rt.size() - 2]) return dfs(i+1);
	return false;
}

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

int balls[10];

bool dfs(int left, int right, int currentID){
	if(currentID > 9) return true;
	
	bool ok = false;
	if (left < balls[currentID]){
		ok = dfs(balls[currentID], right, currentID+1);
	}
	if (right < balls[currentID]){
		ok = dfs(left, balls[currentID], currentID+1);
	}
	return ok;
}

int main() {
	int n; cin >> n;
	
	while(n--){
		for (int i = 0; i < 10; i++) cin >> balls[i];
		cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
	}
}

C++: #include<cstdio>
#include<cstring>
const int MAX_N = 15;
int x[MAX_N],l[MAX_N],r[MAX_N];
int kase;
void dfs(int i,int j,int k)
{
	if(i>10)
	{
		kase=1;
		return;
	}
	if(kase)
	{
		return;
	}
	if(x[i]>l[j-1])
	{
		l[j]=x[i];dfs(i+1,j+1,k);
	}
	if(x[i]>r[k-1])
	{
		r[k]=x[i];dfs(i+1,j,k+1);
	}
}
int main()
{
	int t; 
	scanf("%d",&t);
	while(t--)
	{
		for(int i=1;i<=10;++i)
		{
			scanf("%d",&x[i]);
		}
		kase=0;
		dfs(1,1,1);
		if(kase)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	return 0;
}

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

int main(){
	int N;
	int A[10];
	int cnt1=0;
	cin>>N;
	while(1){
		
		if(cnt1==N){
			break;
		}
		cnt1++;
		for(int i=1;i<=10;i++){
			cin>>A[i];
		}
		int B=A[1];
		int C=0;
		int cnt2=0;
		int cnt3=2;
		for(int i=2;i<=10;i++){
			if(B+1==A[i]){
				B=A[i];
				cnt2++;
			}
			else if(C<A[i]){
				C=A[i];
				cnt2++;
			}
			
			cnt3++;	
		}
		if(cnt2==9){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}
	return 0;	
}