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 a[20],b[20],c[20];
    int n;
    cin >> n;
    while (n--)
    {
        bool judge = true;
        for (int i = 1; i <= 10; ++i)
            cin >> a[i];
        int cb = 1,cc = 1;
        b[cb++] = a[1],c[cc++] = a[2];
        for (int i = 3; i <= 10; ++i)
        {
            int cha1 = a[i] - b[cb-1];
            int cha2 = a[i] - c[cc-1];
            if (cha1 < 0 && cha2 < 0)
            {
                judge = false;
                break;
            }
            if (cha1 < 0)
                c[cc++] = a[i];
            if (cha2 < 0)
                b[cb++] = a[i];
            if (cha1 < cha2)
                b[cb++] = a[i];
            else c[cc++] = a[i];
        }
        if (judge) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: /******************************************
    > File Name: Aoj_0033.cpp
    > Author: universal42
    > Mail: universal42@163.com 
    > Created Time: 2019年05月03日 星期五 16时38分31秒
 ******************************************/

#include<bits/stdc++.h>
#define ll long long int
#define inf 0x3f3f3f3f
#define LOCALa
using namespace std;
const int maxn=1e5+5;
int n;
int arr[10],a[10],b[10];
int flag=0;
void dfs(int i,int j){
	if(flag){
		return;
	}
	if(i+j==10){
		for(int p=0;p<i-1;p++){
			if(a[p]>a[p+1]){
				return;
			}
		}
		for(int p=0;p<j-1;p++){
			if(b[p]>b[p+1]){
				return;
			}
		}
		flag=1;
		return;
	}
	a[i]=arr[i+j];
	dfs(i+1,j);
	b[j]=arr[i+j];
	dfs(i,j+1);
}
void solve(){
	scanf("%d",&n);
	while(n--){
		flag=0;
		for(int i=0;i<10;i++){
			scanf("%d",&arr[i]);
		}
		dfs(0,0);
		if(flag){
			puts("YES");
		}
		else{
			puts("NO");
		}
	}
}
int main(){
#ifdef LOCAL
    freopen("in.in","r",stdin);
#endif
    solve();
    return 0;
}

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

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

	for (int i = 0; i++ < n;) {
		int hole[2] = { 0 };
		for (int j = 0; j < 10; j++) {
			cin >> x;

			if (hole[0] < x) {
				hole[0] = x;
			}else if (hole[1] < x) {
				hole[1] = x;
			} else {
				cout << "NO";
				break;
			}

			if (j == 9) {
				cout << "YES";
			}
		}
		cout << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int arr[10],used[10];
void DFS(int pre,int cur)
{
   if(cur<10&&arr[pre]<arr[cur])
   {
	   used[cur]=1;
	   DFS(cur,cur+1);
   }
   else if(cur<10&&arr[pre]>=arr[cur])
	   DFS(pre,cur+1);
}
int main()
{
   int T,pre;
   bool judge;
   cin>>T;
   while(T--)
   {
     for(int i=0;i<10;i++)
		 cin>>arr[i];
	 for(int i=0;i<10;i++)
	 {
		 memset(used,0,sizeof(used));
		 used[i]=1;
	     DFS(i,i+1);
		 judge=false;
		 pre=0;
	     for(int j=0;j<10;j++)
		    if(used[j]==0)
				if(pre>=arr[j])
			{
				judge=true;
				break;
			}else pre=arr[j];
		 if(!judge)
		 {
			 cout<<"YES"<<endl;
			 break;
		 }
	 }
	 if(judge)cout<<"NO"<<endl;
   }

}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

int a[10];

bool dfs(int n, int l, int r) {
  if (n >= 10) return true;
  if (l < a[n]) if (dfs(n+1, a[n], r)) return true;
  if (r < a[n]) if (dfs(n+1, l, a[n])) return true;
  return false;
};

int main() {
  int N;
  cin >> N;
  rep(i, 0, N) {
    rep(j, 0, 10) {
      cin >> a[j];
    }
    if (dfs(0, -1, -1)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }

  return 0;
};

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

int main(){
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		int a=0, b=0, c[15]={0};
		int flag = 0;
		int tmp = 0;
		for(int k =0;k<10;k++){
			cin >> c[k];
		}
		for(int k =0;k<10;k++){
			if(c[k]>a){
				if(c[k]>b){
					b=c[k];
				}
				else{
					a=c[k];
				}
			}
			else{
				flag = 1;
				break;
			}	
		}
		if(flag)cout << "NO"<<endl;
		else cout << "YES"<<endl;
		
	}
	
}

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;
    int j;
    for( j = 0; j < 10; j++){
      cin >> t;
      if(B >= t && C >= t) 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;
      //      cout << B << " ";
    }
    if(j == 10) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<queue>
using namespace std;
int main(void){
	int num;
	queue<int> qu;
	int a,b;
	int n;

	cin>>n;
	while(n--){
		for(int i=0;i<10;i++){//ツボツーツδ仰づーツ詰ツづ淞づゥ
			cin>>num;
			qu.push(num);
		}
		a=0;
		b=0;
		while(1){
			if(a < qu.front()){
				a=qu.front();
			}else if(b < qu.front()){
				b=qu.front();
			}else{
				cout<<"NO"<<endl;
				break;
			}
			qu.pop();
			if(qu.empty()==true){
				cout<<"YES"<<endl;
				break;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

const int MAX_N = 10;
int a[MAX_N];

bool dfs(int idx, int end1, int end2) {
    if (idx+1 == MAX_N) return true;
    if (a[idx] < end1 && a[idx] < end2) return false;
    if (a[idx] > end1 && a[idx] > end2) return dfs(idx+1, a[idx], end2) || dfs(idx+1, end1, a[idx]);
    if (a[idx] > end1) return dfs(idx+1, a[idx], end2);
    if (a[idx] > end2) return dfs(idx+1, end1, a[idx]);
    return false;
}

int main() {
    int T;
    cin >> T;
    while (T--) {
        for (int i = 0; i < MAX_N; i++)
            cin >> a[i];
        bool flag = dfs(0, 0, 0);
        if (flag) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}