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<cstring>
using namespace std;

int n;
int a[1000];
int a1[1000];
int a2[1000];
void dfs(int s,int s1, int s2){
    if(s==10){
        return ;
    }
    if(s1==0 && s2==0){
        a1[s1]=a[s];
        dfs(s+1,s1+1,s2);
    }else{
        if(s1==0){
            if(a2[s2-1]<a[s]){
                a2[s2] = a[s];
                dfs(s+1,s1,s2+1);
            }else{
                a1[s1] = a[s];
                dfs(s+1,s1+1,s2);
            }
        }else if(s2==0){
            if(a1[s1-1]<a[s]){
                a1[s1] = a[s];
                dfs(s+1,s1+1,s2);
            }else{
                a2[s2] = a[s];
                dfs(s+1,s1,s2+1);
            }
        }else{
            if(a1[s1-1]<a[s]){
                a1[s1] = a[s];
                dfs(s+1,s1+1,s2);
            }else if(a2[s2-1]<a[s]){
                a2[s2] = a[s];
                dfs(s+1,s1,s2+1);
            }else{
                return ;
            }
        }
    }
}
int main(){
    while(~scanf("%d",&n)){
        while(n--){
            for(int i=0;i<10;i++){
                scanf("%d",&a[i]);
            }
            memset(a1,-1,sizeof(a1));
            memset(a2,-1,sizeof(a2));
            dfs(0,0,0);
            int i=0,j=0;
            for(;;i++){
                if(a1[i]==-1){
                    break;
                }
            }
            for(;;j++){
                if(a2[j]==-1){
                    break;
                }
            }
            if(i+j==10){
                printf("YES\n");
            }else{
                printf("NO\n");
            }
        }
    }
}

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

using namespace std;

int main() {
	int A[10];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++)
			cin >> A[j];
		stack<int> B, C;
		string ans = "YES";
		for (int j = 0; j < 10; j++) {
			int k = A[j];
			if (B.empty() != true && C.empty() != true) {
				if (B.top() > k && C.top() > k) {
//					cout << k << " " << B.top() << " " << C.top() << endl;
					ans = "NO";
					break;
				}
				else if (B.top() > C.top())
					B.push(k);
				else
					C.push(k);
			}
			else if (B.empty() == true)
				B.push(k);
			else if (B.top() < k)
				B.push(k);
			else if (B.top() > k)
				C.push(k);
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>

//#define PI 3.141592653589

using namespace std;

int tama[10];

bool dfs(int i, int left, int right)
{
	if (i == 10) return true;
	
	bool ans = false;
	if (left < tama[i])
	{
		ans = dfs(i+1, tama[i], right);
	}
	if (right < tama[i])
	{
		ans = dfs(i+1, left, tama[i]);
	}
	
	return ans;
}

int main()
{
	int N;
	
	cin >> N;
	for (int i=0; i<N; i++)
	{
		for (int j=0; j<10; j++)
		{
			cin >> tama[j];
		}
		cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
	}
	
	return 0;
}

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

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

int N;
bool flag;
int a[10];

void dfs(int idx, int l, int r) {
   if (idx == 10) {
      flag = 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];
      flag = false;
      dfs(0, -1, -1);
      puts(flag ? "YES" : "NO");
   }
   return 0;
}

C++: #include <iostream>

using namespace std;

int A[10];

bool dfs(int n, int a, int b)
{
	if (n == 10)
	{
		return true;
	}

	if (a < A[n])
	{
		if (dfs(n + 1, A[n], b) == true) { return true; }
	}
	
	if (b < A[n])
	{
		if (dfs(n + 1, a, A[n]) == true) { return true; }
	}

	return false;
}

int main()
{
	const int DATASETS = 1000;

	int N;

	bool check[DATASETS];

	cin >> N;

	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			cin >> A[j];
		}

		check[i] = dfs(0, 0, 0);
	}

	for (int i = 0; i < N; i++)
	{
		cout << (check[i] ? "YES" : "NO") << endl;
	}

	return 0;
}

C++: #include <iostream>

using namespace std;

bool judge(int num){
	int i, n, q[2]={0,0};

	for (i=0; i<num; i++) {
		cin >> n;
		if (q[0]<n)
			q[0] = n;
		else if (q[1]<n)
			q[1] = n;
		else
			break;
	}

	return ((i==num)? true: false);
}

int main(){
	int i, n;

	cin >> n;
	for (i=0; i<n; i++)
		cout << (jedge(10)? "YES": "NO") << endl;

	return 0;
}

C++: //AOJ0033
#include<iostream>
using namespace std;
int table[10];

bool ok(int i,int left,int right){
	if(i>=10){
		return true;
	}
	if(left<table[i]){
		if(ok(i+1,table[i],right))return true;
	}
	
	if(right<table[i]){
		if(ok(i+1,left,table[i]))return true;
	}
	return false;
}
int main(){
	int n;
	cin>>n;
	for(int set=0;set<n;set++){
		for(int i=0;i<10;i++)cin>>table[i];
		if(ok(0,0,0))cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	
	}
	return 0;
}

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

vector<int> data;
vector<int> tube_B;
vector<int> tube_C;

const int MAX = 10;

int dfs(int count){
    
    if (count == MAX) return 1;

    int ret = 0;

    int b = tube_B.size() - 1;
    int c = tube_C.size() - 1;

    if (data[count] > tube_B[b]){
        tube_B.push_back(data[count]);
        ret = max(ret, dfs(count + 1));
        tube_B.pop_back();
    }

    if (data[count] > tube_C[c]){
        tube_C.push_back(data[count]);
        ret = max(ret, dfs(count + 1));
        tube_C.pop_back();
    }

    return ret;
}

int main(void){

    int n;
    cin >> n;
    tube_B.push_back(-1);
    tube_C.push_back(-1);

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

        int s = dfs(0);

        if (s == 1){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }

        data.erase(data.begin(), data.end());
        tube_B.erase(tube_B.begin(), tube_B.end());
        tube_C.erase(tube_C.begin(), tube_C.end());
    }




}