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 <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <vector>



int t;
std::vector<int> balls(10);


int dfs(int d,int a,int b)
{
  if(d==10)
    {
      return 1;
    }

  //

  if(balls[d] > a   )
    {
      if(dfs(d+1,balls[d],b) == 1 )
        return 1;
    }

  if(balls[d] > b)
    {
      if( dfs(d+1,a,balls[d]) == 1)
        return 1;
    }

  return 0;
}

int main(int argc,char* argv[])
{
  //freopen("in.txt","r",stdin);
  std::cin>>t;
  while(t--)
    {
      for(int i = 0 ; i < 10 ; i++)
        std::cin >> balls[i];
      if(dfs(0,0,0) == 1 )
        std::cout<<"YES"<<std::endl;
      else
        std::cout<<"NO"<<std::endl;
    }
  return 0;
}

C++: #include <stdio.h>
int main(void)
{
	int a,b,c[10]={0},d,e,f,g,h,i;
	int e=1;
	scanf("%d",&a);
	for (b=0;b<a;b++)
	{
		e=1;
		for (i=0;i<10;i++)
		{
			scanf("%d",&f);
			c[i]=f;
		}
		if (e==1)
		{
			for (g=1;g<8;g++)
			{
				if (c[g-1]<c[g]||c[g-1]<c[g+1])
				{
					e=0;
				}
				else 
				{
					e=1;
				}
			}
		}
		if (e==0)
		{
			printf("Yes\n");
		}
		if (e==1)
		{
			printf("NO\n");
		}
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  int a[10];
  int b[6];
  int c[6];
  int k=0;
  int k2=0;
  int out=0;
  cin>>n;
  b[0]=0;
  c[0]=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>a[j];
      if(b[k]<a[j] ){
	b[k+1]=a[j];
	k++;
      }
      else if(c[k2]<a[j]){
	c[k2+1]=a[j];
	k2++;
      }
      else{
	out=1;
	break;
      }
    }
    if(out==0) cout << "YES" << endl;    
    else if(out==1) cout << "NO" <<endl;
  }
}

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

int main(){
	int b, c, n, a, i, j;
	bool executable;
	cin >> n;
	for(i=0;i<n;i++){
		c=0;
		executable = true;
		cin>>a;
		b=a;
		for(j=1;j<10;j++){
			if(a-b < 0){
				if(a-c < 0){
					executable = false;
					break;
				}else{
					c = a;
				}
			}else{
				if(a-c < 0){
					b = a;
				}else{
					if(a-b < a-c){
						b = a;
					}else{
						c = a;
					}
				}
			}
			cin>>a;
		}
		if(executable){
			cout << "YES\n";
		}else{
			cout << "NO\n";
		}
	}
	return 0;
}

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

using namespace std;
const int maxn = 11;

int num[maxn];

int main()
{
    int ite=0;
    scanf("%d", &ite);
    while(ite--)
    {
        bool flag = true;
        for(int i=0; i<10; ++i)
        {
            scanf("%d", &num[i]);
        }

        stack<int> a, b;

        a.push(num[0]);
        int i = 1;
        while(i<10 && num[i]>a.top()){
            a.push(num[i++]);
        }
        if(i+1<10) b.push(num[i++]);
        for(; i<10; ++i){
            int dif1 = num[i] - a.top(), dif2 = num[i]-b.top();
            if(dif1<0 && dif2<0) {
                flag = false;
                break;
            }
            else if(dif1>0 && dif2>0){
                if(a.top()<b.top()) b.push(num[i]);
                else a.push(num[i]);
            }
            else{
                if(dif1>0) a.push(num[i]);
                else b.push(num[i]);
            }
        }
        if(flag)  printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

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

int n;
queue<int> q;

int main(){
	cin >> n;
	int tmp;
	for(int I=0;I<n;I++){
		q = queue<int>();
		int a = 0;
		for(int i = 0; i < 10; i++){
			cin >> tmp;
			if(a<tmp){
				a = tmp;
			}
			else{
				q.push(tmp);
			}
		}
		a = 0;
		bool f = false;
		while(q.size() > 0){
			tmp = q.front(); q.pop();
			if(a < tmp){
				a = tmp;
			}
			else{
				f = true;
				break;
			}
		}
		if(f){
			cout << "NO" << endl;
		}
		else{
			cout << "YES" << endl;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<fstream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<complex>
#include<set>
#include<map>
#include<list>
#include<vector>
#include<deque>
using namespace std;
typedef long long ll;
typedef vector<int>vec;
typedef vector<vec>mat;
const int INF = 0x3f3f3f3f;
const int Mod = 1e9 + 7;
const double eps = 1e-7;
int main() {
	int a[10];
	int n = 0;
	cin >> n;
	while (n--) {
		int flag = 0;
		memset(a, 0, sizeof(a));
		for (int i = 0; i < 10; i++)
			cin >> a[i];
		for (int cnt = 0; cnt < 1024; cnt++) {//cnt :number of choices
			deque<int> B; deque<int> C;
			for (int i = 0; i < 10; i++) {
				if ((cnt >> i) & 1)B.push_front(a[i]);
				else C.push_front(a[i]);
			}
			reverse(B.begin(), B.end()); reverse(C.begin(), C.end());
			if (is_sorted(B.begin(), B.end()) && is_sorted(C.begin(), C.end())) {
				flag = 1;
				break;
			}
		}
		if (flag)puts("YES");
		else puts("NO");
	}
	//system("pause");
	return 0;
}

C++: #include<cstdio>

int a[10];

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

bool solve(){
    for(int i=0;i<10;i++){
        scanf("%d",a+i);
    }
    return dfs(0,0,0);
}

int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        if(solve()) printf("YES\n");
        else printf("NO\n");
    }
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
//	cut here before submit 
//	freopen ("testcase.Ball", "r", stdin );
	int n;
	scanf ("%d", &n );
	rep (i, n ){
		vector<int> ball(10, 0 );
		rep (j, 10 ){
			scanf ("%d", &ball[j] );
		} // end rep
		stack<int> A, B;
		A.push (ball[0] );
		B.push (0 );
		bool ok = true;
		for (int i = 1; i < 10; i++ ){
			if (A.top() < ball[i] ){
				A.push (ball[i] );
			}else
			if (B.top() < ball[i] ){
				B.push (ball[i] );
			}else{
				ok = false;
				break;
			} // end if
		} // end for
		if (ok ){
			printf ("YES\n" );
		}else{
			printf ("NO\n" );
		} // end if
	} // end loop
		
	return 0;
}