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 <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int ball[10];
bool can = false;

void search(int r,int l,int n){
  //  cout << n << endl;
  if(n>=10) {
	can = true;
	return;
  }
  if(r<ball[n]) search(ball[n],l,n+1);
  if(l<ball[n]) search(r,ball[n],n+1);

}
 
int main(){
  int n;
  cin >> n;
  REP(i,n){
	REP(i,10) cin >> ball[i];
	int right=0;
	int left=0;
	can = false;
	search(right,left,0);
	if(can) cout << "Yes" << endl;
	else cout << "No" << endl;
  }

}

C++: #include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>

using namespace std;

vector<int> ball(10);

int dfs(int cnt, int l, int r){ 
    ++cnt;
    if(cnt == 10) return 1;
    if(ball[cnt] > r){ 
        if(dfs(cnt,l,ball[cnt])) return 1;
    }   
    else if(ball[cnt] > l){ 
        if(dfs(cnt,ball[cnt],r)) return 1;
    }   
    return 0;
}
int main(int argc, void *argv[]){
    int n;
    int tmp;
    
    scanf("%d", &n);
    while(n--){
        for(int i=0;i<10;i++){
            scanf("%d",&tmp);
            ball[i] = tmp;
        }   
        if(dfs(-1,0,0)) printf("YES\n"); else printf("NO\n");
    }   
}

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

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

bool dfs(const std::vector<int> &balls, std::vector<int> l, std::vector<int> r, int i){
	if(i == balls.size()){
		return true;
	}
	if(!l.empty() && l.back() > balls[i] && !r.empty() && r.back() > balls[i]){
		return false;
	}
	bool is_success = false;

	if(l.empty() || l.back() < balls[i]){
		l.push_back(balls[i]);
		is_success = dfs(balls, l, r, i + 1);
	}
	if(is_success){ 
		return true;
	}
	else if(r.empty() || r.back() < balls[i]){
		r.push_back(balls[i]);
		is_success = dfs(balls, l, r, i + 1);
	}
	if(is_success){ return true; }


	return false;
}

int main(int argc, char **argv){
	int n;
	std::vector<int> balls(10);

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif

	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
#if INPUT_FROM_FILE
			ifs >> balls[j];
#else
			std::cin >> balls[j];
#endif
		}

		std::vector<int> l, r;
		if(dfs(balls, l, r, 0)){
			std::cout << "YES" << std::endl;
		}
		else{
			std::cout << "NO" << std::endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

bool dfs(queue<int> a, stack<int> b, stack<int> c)
{
	if (a.empty()) return true;

	bool f1 = false, f2 = false;

	int item = a.front(); a.pop();

	if (b.top() < item) {
		b.push(item);
		f1 = dfs(a, b, c);
		b.pop();
	}

	if (c.top() < item) {
		c.push(item);
		f2 = dfs(a, b, c);
		c.pop();
	}

	return f1 || f2;
}

int main()
{
	int n; cin >> n;

	while (n--) {
		queue<int> a;
		stack<int> b, c;

		b.push(0);
		c.push(0);

		for (int i = 0; i < 10; ++i) { int v; cin >> v; a.push(v); }

		cout << (dfs(a, b, c) ? "YES" : "NO") << endl;
	}
}

C++: #include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<algorithm>
#include<functional>
using namespace std;

int n;
int l=0;
int r=0;
int a=0;
int s=0;

int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{

	for(int j=0;j<10;j++)
	{
		cin>>a;
	if(a>l)l=a;
	else if(a>r)r=a;
	else break;
	s++;
	}

	if(s==10)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	
	}



	return 0;
}

C++: #include<iostream>
#include<cstdio>
#define Max_N 10

using namespace std;

int decide(int *a){
    int i = 1;
    int flag;
    int b[10]= {0};
    int c[10]= {0};
    b[0] = a[0];
    int i_b =1;
    int i_c =1;
    while(i < 10){
        if(b[i_b-1] > a[i] && c[i_c-1] > a[i]){
            flag = 1;
            break;
        }

        else if(b[i_b-1] > a[i] && c[i_c-1] < a[i]){
            c[i_c] = a[i];
            i_c++;
            flag = 0;
        }

        else if(b[i_b-1] < a[i] && c[i_c-1] > a[i]){
            b[i_b] = a[i];
            i_b++;
            flag = 0;
        }

        else{
            int minus_b = a[i]-b[i_b-1];
            int minus_c = a[i]-c[i_c-1];
            if(minus_b > minus_c){
                c[i_c] = a[i];
                i_c++;
            }
            else{
                b[i_b] = a[i];
                i_b++;
            }
            flag = 0;
        }
        i++;
    }
    return flag;
}

int main(){
    //input
    int a[Max_N];
    int n,m,k;
    scanf("%d", &n);
    int ans[n];
    for(m =0 ; m < n;m++){
        scanf("%d %d %d %d %d %d %d %d %d %d\n", &a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);
        ans[m] = decide(a);
    }
    for(m = 0; m < n; m++){
        if(ans[m] == 0){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
    return 0;
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		int a[9]={};
		int b[9]={};
		int dat,o=1,s=1;
		for(int j=0;j<=10;j++){
			cin>>dat;
		 	if(j==0){
				a[0]=dat;
			}
			else if(dat>a[s-1]){
				a[s]=dat;
				s++;
			}
			else if(dat>b[o-1]){
				b[o]=dat;
				o++;}
			else {
				cout<<"NO"<<endl;
			break;
			}
			if(j==10){
				cout<<"YES"<<endl;
				break;
						}

		}
	}
	return 0;
}