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>
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;
        for(int i = 0; i < (1 << 10); i++){
            int bit = i;
            bool ok = true;
             
            int top[2] = {0,0}; //top[0]: B, top[1]: C
            for(int j = 0; j < 10; j++){
                if(top[bit & 1] > balls[j]){
                    ok = false; break;
                }
                top[bit & 1] = balls[j];
                bit >>= 1;
            }
             
            if(ok) {
                sortable = true; break;
            }
        }

        cout << (sortable ? "YES" : "NO") << endl;
    }
}

C++: #include<cstdio>
#define NUM 10
using namespace std;
bool solve(int data[NUM], int id, int l, int r){
  if(id == NUM)
    return true;
  else if(data[id] > l && data[id] > r)
    return solve(data,id+1,data[id],r) || solve(data,id+1,l,data[id]);
  else if(data[id] < l){
    if(data[id] < r)
      return false;
    else
      return solve(data,id+1,l,data[id]);
  }
  return solve(data,id+1,data[id],r);
}
int main(){
  int N;
  scanf("%d",&N);
  int data[NUM];
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < NUM ; j++)
      scanf("%d",&data[j]);
    if(solve(data,0,0,0))
      printf("YES\n");
    else
      printf("NO\n");
  }
}

C++:  
 #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
  
 int main()
 {
   int N;
   while(cin>>N)
   {
     int arr[10];
     bool flag=true;
     for(int i=0;i<10;i++) cin>>arr[i];
     for(int i=0;i<8;i++)
     {
       if(arr[i]>arr[i+1]&&arr[i+1]>arr[i+2])
       {
         flag=false;
         break;                                      
       }        
     }     
     if(flag) cout<<"YES"<<endl;
     else cout<<"NO"<<endl;
   }
   //while(1);     
   return 0;  
 }

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

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

C++: main(){
	int topB,topC;
	int n,tmp;
	int valid;
	
	for (scanf("%d", &n); n--;){
		topB=topC=0;
		valid=1;
		for (int i=0; i<10; i++){
			scanf("%d", &tmp);
			if (tmp > topB) topB=tmp;
			else if (tmp > topC)topC=tmp;
			else {
				valid=0; break;
			}
		}
		printf("%s\n",valid?"YES":"NO");
	}
	return 0;
}

C++: #include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
    int N,pre,current,second_pre;
    bool NO_FLG;

    scanf("%d",&N);
    for(int i=0;i<N;i++){
        pre = -1;
        second_pre = -1;
        NO_FLG = false;
        for(int k = 0; k < 10; k++){
            scanf("%d",&current);
            if(k == 0){
                pre = current;
            }else{
                if(pre > current){
                    if(second_pre == -1){
                        second_pre = current;
                    }else{
                        if(second_pre > current){
                            printf("NO\n");
                            NO_FLG = true;
                            break;
                        }else{
                            second_pre = current;
                        }
                    }
                }else{
                	pre = current;
                }
            }
        }
        if(!NO_FLG)printf("YES\n");

    }
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
bool separate(int* A, int i, vector<int> vB, vector<int> vC)
{
	if (i == 10){
		return (5 == vB.size() && 5 == vC.size());
	}
	if (vB.size() < 5){
		vector<int> vTmpB(vB);
		if (vTmpB.empty() || (!vTmpB.empty() && vTmpB.back() < A[i])){
			vTmpB.push_back(A[i]);
			if (separate(A, i + 1, vTmpB, vC))
				return true;
		}
	}

	if (vC.size() < 5){
		vector<int> vTmpC(vC);
		if (vTmpC.empty() || (!vTmpC.empty() && vTmpC.back() < A[i])){
			vTmpC.push_back(A[i]);
			if (separate(A, i + 1, vB, vTmpC))
				return true;
		}
	}

	return false;
}
int main()
{
	int n;
	cin >> n;
	int A[10] = {};
	while(n--){
		for (int j = 0; j < 10; ++j)
			cin >> A[j];
		vector<int> vB, vC;
		if (separate(A, 0, vB, vC)) cout << "YES\n";
		else cout << "NO\n";
	}
	return 0;
}

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

int ball[10];

//ball[m]?????\????????±b,c???????????????ball???????????????left,right
bool dfs(int m,int left, int right){
    if(m==10) return true;
    if(ball[m]>left){
        if(dfs(m+1,ball[m],right)) return true;
    }
    if(ball[m]>right){
        if(dfs(m+1,left,ball[m])) return true;
    }
    return false;
}

void solve(){
    for(int i=0;i<10;i++){
        cin>>ball[i];
    }
    if(dfs(0,0,0)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

int main(){
    int n;cin>>n;
    for(int i=0;i<2;i++){
        solve();
    }
    return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int maxn = 100;
int cas_e;
int b[10],l[10]={0},r[10]={0};
void dfs(int x,int y,int z)
{
    if(x==10){cas_e=1;return;}
    if(cas_e){return;}
    if(b[x]>l[y]){l[y]=b[x];dfs(x+1,y+1,z);}
    if(b[x]>r[z]){r[z]=b[x];dfs(x+1,y,z+1);}
}
int main()
{
    int a;
    cin>>a;
    while(a--)
    {
        for(int i=0;i<10;i++)
        {
            cin>>b[i];
        }
        cas_e=0;
        dfs(0,0,0);
        if(cas_e){cout<<"YES"<<endl;}
        else{cout<<"NO"<<endl;}
    }
    return 0;
}