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 count;
     cin >> count;
     while(count--) {
          int num[10];
          for (int i = 0; i < 10; i++) cin >> num[i];
          int max = num[0];
          num[0] = 0;
          for (int i = 1; i < 10; i++) {
               if (num[i] > max) {
                    max = num[i];
                    num[i] = 0;
               }
          }
          max = 0;
          int flag = 1;
          for (int i = 0; i < 10; i++) {
               if (max <= num[i]) max = num[i];
               else if (num[i] != 0) {
                    cout << "NO" << endl;
                    flag = 0;
                    break;
               }
          }
          if (flag) cout << "YES" << endl;
     }

     return 0;
}

C++: #include <iostream>

using namespace std;

int main(void) {
    int N, a, b, c, x[10];
    cin >> N;
    for (; N--; ) {
        bool ok = true;
        for (int i = 0; i < 10; i++) {
            cin >> x[i];
        }
        b = c = 0;
        for (int i = 0; i < 10; i++) {
            a = x[i];
            if (a < b && a < c) {
                ok = false;
                break;
            } else if (a < b) {
                c = a;
            } else if (a < c) {
                b = a;
            } else if (b < c) {
                c = a;
            } else {
                b = a;
            }
        }
        if (ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

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

using namespace std;

int ball[12];
int n;

bool dfs(int i,int b,int c){
    if(i==11) return true;
    if(ball[i]>b){
        if(dfs(i+1,ball[i],c)) return true;
    }
    if(ball[i]>c){
        if(dfs(i+1,b,ball[i])) return true;
    }
    return false;
}

void solve(){
    int l=0,r=0;
    for(int i=1;i<=10;i++){
        if(ball[i]>l&&ball[i]>r){
            if(l>r) l=ball[i];
            else r=ball[i];
        }
        else{
            if(ball[i]<l&&ball[i]<r){
                printf("NO\n"); return;
            }
            else{
                if(ball[i]>r) r=ball[i];
                else l=ball[i];
            }

        }
    }
    printf("YES\n");
}


int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=10;j++)
            scanf("%d",&ball[j]);
        solve();
    }
    return 0;
}

C++: //C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> P;
int in[10];
bool dfs(int n,vector<int> l,vector<int> r){
  if(n==10)return true;
  if(l.size()==0 or in[n]>l[l.size()-1]) 
  {
    l.push_back(in[n]);
    return dfs(n+1,l,r);
  }
  if(r.size()==0 or in[n]>r[r.size()-1] ){
    r.push_back(in[n]);
    return dfs(n+1,l,r);
  }
  return false;
  }
int main(){
  int d;
  cin>>d;
  for(int dd=0;dd<d;dd++){
    for(int i=0;i<10;i++){
      cin>>in[i];
    }
    vector<int> l,r;
    if(dfs(0,l,r )) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
  
  }
  return 0;
}

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

int main() {
	int n;
	int a;
	vector<int>d;
	vector<int>va = {};
	vector<int>vb = {};
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> a;
			d.push_back(a);
		}
		va.push_back(d[0]);		

		for (int j = 1; j < 10; j++) {
			int b = va.size();
			int c = vb.size();

			if (d[j] > va[b-1]) {
				va.push_back(d[j]);
			}
			else if (d[j] > vb[c-1]) {
				vb.push_back(d[j]);
			}
			else {
				cout << "NO" << endl; 
				goto FINLOOP;
			}
		}
		cout << "YES" << endl;
			FINLOOP:
		;
	}
	return 0;
}

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

int main(){

int N,x,y,n;

scanf("%d",&N);

for(int i=0;i<N;i++){
x=n=0;
y=-1;
	for(int j=0;j<10;j++){
		scanf("%d",&n);
		if(x>n && y>n){
			printf("NO\n");
			break;
		}
		else if((x>n && n>y)||(n>y && y>x))
			y=n;
		else if((y>n && n>x)||(n>x && x>y))
			x=n;
		if(j==9)
			printf("YES\n");
	}			
}
return 0;
}

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

using namespace std;



int main()
{
        int num = 0, tmp_right, tmp_left, ispush = 0, i, j;
        std::array< int, 10 > ar;
        std::vector< int > right, left;
        cin >> num;

        for ( j = 0 ; j < num ; j = j + 1 )
        {
                for ( i = 0 ; i < 10 ; i = i + 1 )
                {
                        cin >> ar[i];
                        ispush = 0;
                        if ( right.size() == 0 )
                        {
                                ispush = 1;
                                right.push_back( ar[i] );
                        }
                        else if ( right.size() != 0 )
                        {
                                tmp_right = right.back();
                                if ( tmp_right < ar[i] )
                                {
                                        right.push_back( ar[i] );
                                        ispush = 1;
                                }
                        }

                        if ( ispush == 0 )
                        {
                                if ( left.size() == 0 )
                                {
                                        ispush = 1;
                                        left.push_back( ar[i] );
                                }
                                else if ( left.size() != 0 )
                                {
                                        tmp_left = left.back();
                                        if ( tmp_left < ar[i] )
                                        {
                                                ispush = 1;
                                                left.push_back( ar[i] );
                                        }
                                }
                        }

                        if ( ispush == 0 )
                        {
                                cout << "NO" << endl;
                                break;
                        }
                        else
                        {
                                ispush = 0;
                        }
//                      cout << i << endl;
                        if ( i == 9 )
                        {
                                cout << "YES" << endl;
                        }


                }
                right.clear();
                left.clear();

        }


        return 0;
}