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 <string>
#include <vector>
#include <algorithm>

using namespace std;


int q;
int Ball[10];
bool flag;
vector<string> log_vec;

bool is_satisfies(vector<int> a) {
    vector<int> copy = a;
    sort(a.begin(), a.end());
    return a == copy;
}

void bfs(int i, vector<int> B, vector<int> C) {
    if (i == 9) {
        if (is_satisfies(B) && is_satisfies(C))
            flag = true;
        else
            flag = flag == true ? true : false;
    } else {
        vector<int> temp;

        temp = B;
        temp.push_back(Ball[i]);
        bfs(i + 1, temp, C);

        temp = C;
        temp.push_back(Ball[i]);
        bfs(i + 1, B, temp);
    }
}

void solve() {
    vector<int> B, C;
    flag = false;

    bfs(0, B, C);

    if (flag)
        log_vec.push_back("YES");
    else
        log_vec.push_back("NO");
}

int main() {
    cin >> q;
    for (int i = 0; i < q; ++i) {
        for (int j = 0; j < 10; ++j)
            scanf("%d", &Ball[j]);

        solve();
        cout << log_vec[i] << endl;
    }

    //for (int i = 0; i < log_vec.size(); ++i) {
    //    cout << log_vec[i] << endl;
    //}
}

C++: #include<iostream>
int main()
{
	int N;
	std::cin >> N;
	for (int i = 0; i < N; i++)
	{
		int b_back = 0, c_back = 0;
		bool is_OK = true;
		for (int j = 0; j < 10; j++)
		{
			int num;
			std::cin >> num;
			if (num < b_back && num < c_back)
			{
				is_OK = false;
				break;
			}
			else if (num > b_back && num < c_back)
			{
				b_back = num;
			}
			else if (num < b_back && num > c_back)
			{
				c_back = num;
			}
			else
			{
				if (b_back > c_back)
				{
					b_back = num;
				}
				else
				{
					c_back = num;
				}
			}
		}
		std::cout << (is_OK ? "YES" : "NO") << std::endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
void dfs(int b[10],int c[10],int m,int k,int t);//a中，b中，c中游标
int a[10];
int flag;
int main()
{
	int N;
	cin >> N;
	while (N--)
	{
		for (int i = 0; i < 10; i++)
			cin >> a[i];
		int b[10];
		int c[10];
		b[0] = 0;
		c[0] = 0;
		flag = 0;
		dfs(b, c, 0, 0, 0);
		if (flag== 1)
			cout << "YES" << endl;
		else 
			cout << "NO" << endl;
	}
	return 0;
}
void dfs(int b[10], int c[10], int m, int k, int t)
{
	int ma = m;
	int kb = k;
	int tc = t;
	int i;
	int x[10], y[10];             //用x,y去中间值，好进行回溯
	if (ma == 10)
		flag=1;
	for (i = 0; i <=kb; i++)
	{
		x[i] = b[i];	
	}
	for (i = 0; i <= tc; i++)
	{
        y[i] = c[i];
	}
	/*if (x[kb] > a[ma] && y[tc] > a[ma])  //两个都大  不要直接return 应该返回 找其他的枝丫
		return 0;*/
	if (x[kb] > a[ma] && y[tc] < a[ma])
	{
		y[tc] = a[ma];
		ma++; tc++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
	}
	if (x[kb] < a[ma] && y[tc] > a[ma])
	{
		x[kb] = a[ma];
		ma++; kb++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
	}
	if (x[kb] < a[ma] && y[tc] < a[ma])
	{
		x[kb] = a[ma];
		ma++; kb++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
		ma--; kb--;
		y[tc] = a[ma];
		ma++; tc++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
		ma--; tc--;
	}
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<deque>
#define INF int(1e9)
using namespace std;
int read()
{
    int f=1,x=0;
    char c=getchar();
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
    while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
    return f*x;
}
bool flag;
int ball[11];
void DFS(int left,int right,int now)
{
	if(now>10)
	{
		flag=1;	
		return ;
	}
	if(ball[now]>left&&ball[now]>right) 
		return ;	
	if(ball[now]<left)
		DFS(ball[now],right,now+1);
	else
		DFS(left,ball[now],now+1);
	return ;
}
int main()
{
	int t=read();
	while(t!=0)
	{
		t--;
		flag=0;
		for(int i=10;i>=1;i--)
			ball[i]=read();
		DFS(INF,INF,1);
		if(flag==1)
			printf("YES\n");
		else
			printf("NO\n");
	}
    return 0;
}

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

int B[12], C[12], num[12], b, c;

bool dfs(int b, int c, int i){
    if(i == 10) return true;
    B[b+1] = num[i];
    C[c+1] = num[i];
    if(B[b]<num[i] && dfs(b+1, c, i+1)){
        return true;
    }
    if(C[c]<num[i] && dfs(b, c+1, i+1)){
        return true;
    }
    return false;
}

int main(void){
  int N;
  cin >> N;
  for(int j=0; j<N; j++){
  B[0] = 0;
  C[0] = 0;
  for(int i=0; i<10; i++){
    cin >> num[i];
  }
  if(dfs(0, 0, 0))  cout << "YES" << endl;
  else cout << "NO" << endl;
  }
  return 0;
}

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

using namespace std;

typedef deque <int> Deq;

bool flag;
int ball[10], a;

void dfs(Deq B, Deq C, int deep)
{
	if (flag) return;
	if (deep == 10){
		// cout << "B : " << B.size() << " / ";
		// for (int i = 0; i < B.size(); i++){
		// 	cout << B[i] << " ";
		// }
		// cout << endl << "C : " << C.size() << " / ";
		// for (int i = 0; i < C.size(); i++){
		// 	cout << C[i] << " ";
		// }
		// cout << endl;
		bool bf = true, cf = true;
		for (int i = 0; i+1 < B.size(); i++){
			if (B[i] > B[i+1]) bf = false;
		}
		for (int i = 0; i+1 < C.size(); i++){
			if (C[i] > C[i+1]) cf = false;
		}
		flag |= (bf && cf);
		return;
	}

	B.push_back(ball[deep]);
	dfs(B, C, deep + 1);
	B.pop_back();

	C.push_back(ball[deep]);
	dfs(B, C, deep + 1);
	C.pop_back();
	return;
}

int main(void)
{
	int n;
	cin >> n;
	while (n--){
		for (int i = 0; i < 10; i++){
			cin >> ball[i];
		}

		flag = false;
		Deq B, C;
		dfs(B, C, 0);

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

	return 0;
}

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

int main() {
	int n, balls[10]; cin >> n;
    while(n--){
        for(int i = 0; i < 10; i++){
            cin >> balls[i];
        }
        
        bool sortable = false;
        stack<tuple<int, int, int> > states;
        
        states.push(make_tuple(0,0,0));
        while(!states.empty()){
        	tuple<int, int, int> now = states.top();
        	states.pop();
        	
        	int idx = get<0>(now);
        	if(idx < 10){
        		if(get<1>(now) < balls[idx]){
        			if(idx == 9){
        				sortable = true; break;
        			}
        			states.push(make_tuple(idx+1,balls[idx],get<2>(now)));
        		}
        		if(get<2>(now) < balls[idx]){
        			if(idx == 9){
        				sortable = true; break;
        			}
        			states.push(make_tuple(idx+1,get<1>(now),balls[idx]));
        		}
        	}        	
        }
         
        if(sortable) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}