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 <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
long long MOD; template<class T> void mod(T &n){MOD=n;}
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long> 
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll


signed main(){
  int n; cin>>n;
  
  for(int c=0; c<n; c++){
    int a[15];
    for(int j=0; j<10; j++){
      cin>>a[j];
    }
    
    bool ans=false;
    for(int i=0; i<(1<<10); i++){
      vector<int> ve1,ve2;
      for(int j=0; j<10; j++){
        if(i&(1<<j)) ve1.push_back(a[j]);
        else ve2.push_back(a[j]);
      }
      

      bool no=false;
      for(int j=1; j<ve1.size(); j++){
        if(ve1[j]<ve1[j-1]){
          no=true;
          break;
        }
      }
      for(int j=1; j<ve2.size(); j++){
        if(ve2[j]<ve2[j-1]){
          no=true;
          break;
        }
      }
      if(!no){
        ans=true;
        break;
      }
      
    }
    
    if(ans) cout<<"YES"<<en;
    else cout<<"NO"<<en;
  }
}

C++: /*
* Filename:    aoj0033.cpp
* Desciption:  DFS
* Created:     2016-03-02
* Author:      JIngwei Xu [mail:xu_jingwei@outlook.com]
*
*/
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#define INT_MAX 2<<30
using namespace std;
//typedef long long ll;
int a[10],n;
int used[10];
bool ans=false;
bool check(){
	int ss=0;
	for (int i = 0; i < 10; i += 1)
	{
		if(used[i]==0){ss=a[i];break;}
	}
	if(ss==0)return true;
	for (int i = 0; i < 10; i += 1)
	{
		if(used[i]==0){
			if(a[i]<ss)return false;
			else ss=a[i];
		}
	}
	return true;
}
void dfs(int k,int rec){
	if(k==10){
		if(check())ans=true;
		return;
	}
	if(ans)return;
	if(a[k]>rec){
		used[k]=1;
		dfs(k+1,a[k]);
		if(ans)return;
		used[k]=0;
		dfs(k+1,rec);
		if(ans)return;
	}
	else{
		used[k]=0;
		dfs(k+1,rec);
	}
}
int main()
{
	scanf("%d",&n);
	for (int i = 0; i < n; i += 1)
	{
		for (int j = 0; j < 10; j += 1)
		{
			scanf("%d",&a[j]);
		}
		ans=false;
		for (int i = 0; i < 10; i += 1)
		{
			memset(used,0,sizeof(used));
			used[i]=1;
			dfs(i+1,a[i]);
			if(ans)break;
		}
		
		
		if(ans)printf("YES\n");
		else printf("NO\n");
		
	}
	return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  for(int i=0;i<n;i++) {
    int a=0;
    int b=0;
    bool failed = false;
    for(int i=0;i<10;i++) {
      int n;
      cin >> n;
      if(failed) {
        continue;
      }

      if(b <= a && a < n) {
        // cout << "1 " << a << ":" << b << ":" << n << endl;
        a = n;
      } else if (a < b && b < n) {
        // cout << "2 " << a << ":" << b << ":" << n << endl;
        b = n;
      } else if (b <= a && b < n) {
        // cout << "3 " << a << ":" << b << ":" << n << endl;
        b = n;
      } else if (a < b && a < n) {
        // cout << "4 " << a << ":" << b << ":" << n << endl;
        a = n;
      } else {
        // cout << "x " << a << ":" << b << ":" << n << endl;
        cout<<"NO"<<endl;
        failed = true;
        continue;
      }
      if(i==9) {
        cout<<"YES"<<endl;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)

int a[10];

//B:=B?????????????????° C*=C?????????????????° cnt:=??????????????°??????
bool dfs(int B, int C, int cnt){
	if(cnt == 10){
		return true;
	}
	if(B < a[cnt]){
		return dfs(a[cnt], C, cnt + 1);
	}
	if(C < a[cnt]){
		return dfs(B, a[cnt], cnt + 1);
	}
	if(B > a[cnt] && C > a[cnt]){
		return false;
	}
}
int main(void){
	int n; cin >> n;
	for (int i = 0; i < n; ++i){
		rep(j, 10) cin >> a[j];
		flag = false;
		dfs(0, 0, 0);
		if(flag) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

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

int a[10],l,r;

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

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		for(int i=0;i<10;i++)scanf("%d",a+i);
		if(dfs(0))printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++:     #include <iostream>
    using namespace std;
     
    int N, H[10];
     
    void solve()
    {
      int big=0, small=0;
      bool flag = true;
      for (int i = 0; i < 10; i++)
      {
        if (H[i] > big) big = H[i];
        else if (H[i] > small) small = H[i];
        else
        {
          flag = false;
          break;
        }
      }
      if (flag) cout << "YES" << endl;
      else cout << "NO" << endl;
    }
     
    int main()
    {
      cin >> N;
      for (int i = 0; i < N; i++)
      {
        for (int j = 0; j < 10; j++) cin >> H[j];
        solve();
      }
      return 0;
    }

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

int main() {
	int n, balls[10]; cin >> n;
    while(n--){
        for(int i = 0; i < 10; i++){
            cin >> balls[i];
        }
        
        bool sortable = false;
        stack<tuple<int, int, int> > states;
        
        states.push(make_tuple(0,0,0));
        while(!states.empty()){
        	tuple<int, int, int> now = states.top();
        	closed.insert(now);
        	states.pop();
        	
        	int idx = get<0>(now);
        	if(idx < 9){
        		if(get<1>(now) < balls[idx]){
        			if(idx + 1 == 9){
        				sortable = true; break;
        			}
        			states.push(make_tuple(idx+1,balls[idx],get<2>(now)));
        		}
        		if(get<2>(now) < balls[idx]){
        			if(idx + 1 == 9){
        				sortable = true; break;
        			}
        			states.push(make_tuple(idx+1,get<1>(now),balls[idx]));
        		}
        	}        	
        }
         
        if(sortable) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}