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

int main() {
	int n;
	deque<int> b,c;
	cin >> n;
	for ( int i = 0; i < n; i++ ){
		int dummy;
		cin >> dummy;
		b.push_back( dummy );
		cin >> dummy;
		c.push_back( dummy );
		for ( int j = 0; j < 8; j++ ){
			cin >> dummy;
			if ( dummy > b[b.size()-1] )	b.push_back( dummy );
			else if ( dummy > c[c.size()-1] )	c.push_back( dummy );
			else {
				cout << "NO" << endl;
				goto END;
			}
		}
		cout << "YES" << endl;
END:;
	}
	
	return 0;
}

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

using namespace std;

int caseCnt, numbers[10], curNum;
stack<int> Left, Right;

bool used[10], result;

void clear_stack(){
    while( !Left.empty())  Left.pop();
    while(!Right.empty()) Right.pop();
}

bool dfs(int index, int left_or_right){
    if(!left_or_right){
        if(Left.empty() || numbers[index] > Left.top()){
            Left.push(numbers[index]);
        }else{
            //cout << "false\n";
            return false;
        }
    }else{
        if(Right.empty() || numbers[index] > Right.top()){
            Right.push(numbers[index]);
        }else{
            //cout << "false\n";
            return false;
        }
    }
    if(index == 9){
        //cout << "true\n";
        return true;
    }else if(dfs(index+1, 0)){
        //cout << "true\n";
        return true;
    }else if (dfs(index+1, 1)){
        //cout << "true\n";
        return true;
    }else{
        //cout << "false\n";
        return false;
    }
}

int main(){
    cin >> caseCnt;

    while(caseCnt--){
        result = false;
        clear_stack();

        for(int i=0; i<10; ++i) cin >> numbers[i];

        result = dfs(0, 0);
        if(result){
            cout << "YES\n";
            continue;
        }

        result = dfs(0, 1);
        if(result) cout << "YES\n";
        else       cout << "NO\n";
    }
    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

int main(){
    int n,b,B=0,C=0;
    
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        B=0;C=0;
        for(int j=0;j<10;j++){
            scanf("%d",&b);
            if(min(B,C)<b){
                if(B>C && B<b)B=b;
                else C=b;
            }else{
                B=11;C=11;
            }
        }
        if(B==10 || C==10)
            puts("YES");
        else
            puts("NO");
    }
    return 0;
}

C++: #include<iostream>
#include<string.h>

using namespace std;

int N;
int balls[10];
bool dfs(int n, int a, int b){
if(n==10)return true;
if(balls[n]>a) return dfs(n+1,balls[n],b);
if(balls[n]>b) return dfs(n+1,a,balls[n]);
return false;
}
int main(){
cin>>N;
for(int i=0;i<N;i++){
for(int j=0;j<10;j++){
cin>>balls[j];
}
if(dfs(0,0,balls[0]))cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}

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

using namespace std;

int main() {
    int N;
    cin >> N;
    while(N--) {
        vector<int> v(10);
        for(int i = 0; i < 10; ++i) cin >> v[i];
        bool ok = false;
        for(int pat = 0; pat < (1<<10); ++pat) {
            bool sorted = true;
            int prev = -1;
            for(int i = 0; i < 10; ++i) {
                if(pat & (1<<i)) {
                    if(v[i] < prev) {
                        sorted = false;
                        break;
                    }
                    prev = v[i];
                }
            }
            prev = -1;
            for(int i = 0; i < 10; ++i) {
                if(~pat & (1<<i)) {
                    if(v[i] < prev) {
                        sorted = false;
                        break;
                    }
                    prev = v[i];
                }
            }
            if(sorted) {
                ok = true;
                break;
            }
        }

        cout << (ok?"YES":"NO") << endl;
    }
    return 0;
}

C++: #include<stdio.h>

int arr[10];
int b[10],c[10];
int visited[10]; 
int dfs(int n,int nb,int nc)
{
	int sign=0,sign1=0;
	if(n==10)
		return 1;	
	else
	{
		if(nb==0)
		{
			b[nb]=arr[n];
			sign=dfs(n+1,nb+1,nc);
			
		}
		else 
		{	
			if(arr[n]>b[nb-1])
			{
				b[nb]=arr[n];
				sign=dfs(n+1,nb+1,nc);
				
			}
		}
		if(nc==0)
		{
			c[nc]=arr[n];
			sign1=dfs(n+1,nb,nc+1);
			
		}
		else
		{
			if(arr[n]>c[nc-1])
			{
				c[nc]=arr[n];
				sign1=dfs(n+1,nb,nc+1);
			
			}
		}
	}
	return sign||sign1;
}
int main()
{
	int N;
	scanf("%d",&N);
	while(N--)
	{
		int i,sign=0;
		for(i=0;i<10;i++)
			scanf("%d",&arr[i]);
		sign=dfs(0,0,0);
		if(sign)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n; cin >> n ;
	for(int i=0;i<n;i++){
		int a[10] ;
		for(int j=0;j<10;j++) cin >> a[j] ;
		int stackA[10]={a[0],0}; int stackB[10]={0};
		int na=0;int nb=0;int flag=0;
		for(int j=1;j<10;j++){
			if(flag==1) break;
			if(a[j]>stackA[na-1]) stackA[na++]=a[j];
			else if(nb==0) stackB[nb++]=a[j];
			else if(a[j]>stackB[nb-1]) stackB[nb++]=a[j];
			else flag=1;
		};
		if(flag==1) cout << "NO\n" ;
		else cout << "YES\n" ;
	};
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#define INF 1000000000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define all(x) (x).begin(),x.end()
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

int main(){
  int n,x;
  cin>>n;
  rep(i,n){
    bool ok=true;
    int right,left=-INF;
    cin>>right;
    REP(i,1,10){
      //cout<<right<<" "<<left<<endl;
      cin>>x;
      if(right>x){
	if(left<x){
	  left=x;
	}else{
	  //cout<<x<<endl;
	  ok=false;
	  break;
	}
      }else{
	right=x;
      }
      
    }
    if(ok)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}

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

int d[10];

bool dfs(int left, int right, int i)
{
    if(i==10){
        return true;
    }
    bool res=false;
    if(d[i]>left)res=res | dfs(d[i], right, i+1);
    if(d[i]>right)res=res | dfs(left, d[i], i+1);
    return res;
}

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++)cin>>d[j];
        if(dfs(-1, -1, 0))cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}