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++: 
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>
#include <climits>
#include <set>
#include <numeric>

using namespace std;

double sq(double x){return x*x;}

int main(){
	int t;
	cin>>t;
	while(t--){
		int a[10];
		bool t[10];
		for (int i = 0; i < 10; i++)
		{
			cin>>a[i];
		}
		memset(t,0,10);
		int b;
		for (int i = 0; i < 2; i++)
		{
			b = 0;
			for (int j = 0; j < 10; j++)
			{
				if(t[j])continue;
				if(b < a[j]){
					b = a[j];
					t[j] = true;
				}
			}
		}
		int s = accumulate(t,t+10,0);
		if(s == 10)
			puts("YES");
		else 
			puts("NO");
	}

	return 0;
}

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

vector<int> l, r, balls;
int lp, rp;

bool search(int n){
	bool isl = false, isr = false;
	if( n==10 ) return true;
	if( balls[n] > l[lp] ){
		l[++lp] = balls[n];
		isl = search(n+1);
		lp--;
	}
	if( balls[n] > r[rp] && !isl ){
		r[++rp] = balls[n];
		isr = search(n+1);
		rp--;
	}
	return isl || isr;
}

int main(){
	int n;
	cin >> n;
	l.resize(10); r.resize(10);
	balls.resize(10);
	for( int i=0; i<n; i++ ){
		lp = rp = 0;
		for( int j=0; j<10; j++ ){
			int b;
			cin >> b;
			balls[j] = b;
		}
		cout << (search(0)?"YES":"NO") << endl;
	}
	return 0;
}

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

using namespace std;

int main() {
	vector<int> left;
	vector<int> right;
	vector<int> all;

	bool flag = true;

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else  if (all.size() == (i+1)*(j+1)) {

						}
						else {
							flag = false;
						}			  						
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}

		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
		flag = true;
	}

	return 0;
}

C++: ??£??????
#include<iostream>
#include<memory.h>
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;

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int a[10];
bool ans;

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

   int val = a[idx];
   if (l < val) dfs(idx+1, val, r);
   if (r < val) dfs(idx+1, l, val);
}

int main() {
   int N;
   cin >> N;
   while (N--) {
      for (int i = 0; i < 10; i++) cin >> a[i];
      ans = false;
      dfs(0, -1, -1);
      puts(ans ? "YES" : "NO");
   }

   return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
signed main(void){
	ios::sync_with_stdio(false);
	int T,in[10],a,b,flag;
	cin>>T;
	while(T--){
		a=b=flag=0;
		for(int i=0;i<10;i++)
			cin>>in[i];
		for(int i=0;i<10;i++){
			int x=in[i];
			if(x>a&&x>b){
				if(a>b)	a=x;
				else	b=x;
			}
			else if(x<a&&x<b){
				flag=1;
				break;	
			}
			else if(x>a)
				a=x;
			else if(x>b)
				b=x;
		}
		if(flag)	cout<<"NO"<<endl;
		else 		cout<<"YES"<<endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
int n,i,j,j1,j2,a,k;
cin>>n;
for(i=0;i<n;i++){
j1=j2=0;a=1;
for(k=0;k<10;k++){
cin>>j;
if(j1<j&&j2<j){if(j1<j2)j2=j;else j1=j;}
else if(j1<j)j1=j;
else if(j2<j)j2=j;
else a=0;
}
if(a==1)cout<<"YES"<<endl;else cout<<"NO"<<endl;
}
return 0;
}

C++: // AojTemplete.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include "stdafx.h"
#include<iostream>
#include<vector>
using namespace  std;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		bool flag = false;
		int prev;
		int in[10];
		int used[10];
		for (int j = 0; j < 10; j++)
		{
			cin >> in[j];
		}
		prev = in[0];
		vector<int> B;
		vector<int> C;
		for (int j = 0; j < 10; j++)
		{
			if (prev > in[j])
			{
				C.push_back(in[j]);
				used[j] = false;
				continue;
			}
			else
			{
				prev = in[j];
				B.push_back(in[j]);
				used[j] = true;
			}
		}
		prev = C[0];
		for (int j = 0; j < C.size(); j++)
		{
			if (prev > C[j])
			{
				flag = true;
				break;
			}
			else
			{
				prev = C[j];
			}
		}
		if (flag) cout << "NO" << endl;
		else cout << "YES" << endl;
	}
	return 0;
}

C++: #include<iostream>
#include <stack> 
using namespace std;
int ar[10];
stack<int> a,b;
bool dfs(int i)
{
	bool aflag = false,bflag = false;
	if(i!=9)
	{
		if(a.empty()||a.top()<ar[i])
		{
			a.push(ar[i]);
			aflag = dfs(i+1);
		}
		if(b.empty()||b.top()<ar[i])
		{
			b.push(ar[i]);
			bflag = dfs(i+1);
		}
		return aflag|bflag;
	}
	if(i==9)
	{
		if(a.empty()||a.top()<ar[i])
		{
			a.push(ar[i]);
			aflag = true;
		}
		if(b.empty()||b.top()<ar[i])
		{
			b.push(ar[i]);
			bflag = true;
		}
		return aflag|bflag;
	}
}
int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		for(int i = 0;i<10;i++)
			cin >> ar[i]; 
		cout<<(dfs(0)?"YES":"NO")<<endl;
	}
 }

C++: #include<cstdio>

int main(){
	int n, b, c, t;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		b = c = 0;
		for(int j = 0; j < 10; j++){
			scanf("%d", &t);
			if(b < t){
				b = t;
			}else{
				if(c < t){
					c = t;
					if(b < c){
						t = b;
						b = c;
						c = t;
					}
				}else{
					t = 0;
					j += 10;
				}
			}
		}

		if(t){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}