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,ball,tp[2],con,bad;
	
	cin >> n;
	
	for(; n > 0; n--){
		
		tp[0] = tp[1] = 0;
		
		for(int i = 0; i < 10; i++){
			cin >> ball;
			
			if(tp[0] > tp[1]){
				con = 0;
			}else{
				con = 1;
			}
			
			if(ball > tp[con]){
				tp[con] = ball;
			}else if(ball > tp[!con]){
				tp[!con] = ball;
			}else{
				cout << "NO" << endl;
				cin.ignore(64, "\n");
			}
			
			if(i == 9){
				cout << "YES" << endl;
			}
		}
	}
	
	return 0;
}

C++: #include <iostream>

using namespace std;

bool ballTest(int *balls, int *b, int numB, int *c, int numC, int num)
{
        if (num <= 0) {
                return true;
        }
        if (balls[0] > b[numB - 1]) {
                b[numB] = balls[0];
                if (ballTest(&balls[1], b, numB + 1, c, numC, num - 1)) {
                        return true;
                }
        }
        if (balls[0] > c[numC - 1]) {
                c[numC] = balls[0];
                if (ballTest(&balls[1], b, numB, c, numC + 1, num - 1)) {
                        return true;
                }
        }
        return false;
}


int main(int argc, char **argv)
{
        int num;

        cin >> num;

        for (int i = 0; i < num; i++) {
                int balls[11];
                int b[10], c[10];
                int numB, numC;

                b[0] = c[0] = 0;
                numB = numC = 1;
                cin >> balls[1] >> balls[2] >> balls[3] >> balls[4] >> balls[5] >> balls[6] >> balls[7] >> balls[8] >> balls[9] >> balls[10];
                if (ballTest(&balls[1], b, 1, c, 1, 10)) {
                        cout << "YES\n";
                } else {
                        cout << "NO\n";
                }
        }
        return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n,a[10];
	cin>>n;
	for(int i=0;i<n;i++){
		bool t=true;
		for(int j=0;j<10;j++)
			cin>>a[i];
		int b,c;
		if(a[0]>a[1]){
			b=a[0];
			c=a[1];
		}
		else{
			b=a[1];
			c=a[0];
		}
		for(int j=2;j<10;j++){
			if(c>a[j])
				t=false;
			if(c<a[j]&&b>a[j])
				c=a[j];
			if(b<a[j])
				b=a[j];
		}
		if(t==true)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {

	int a, b=0, i, N, x[10], end=0;

	cin >> N;
	for(; N!=0; N--) {
		for(i=0; i<10; i++)
			cin >> x[i];
		for(i=0; i<10; i++) {
			if(i==0) {
				a=x[i];
				i++;
			}
			if(a>x[i]&&b>x[i]) {
				end++;
				break;
			}
			if(a>x[i]) {
				if(b<x[i])
					b=x[i];
			}
			else {
				if(b>x[i])
					a=x[i];
				else
					a>b ? a : b =x[i];
			}
		}

		if (end!=0)
			cout << "NO" << endl;
		else
			cout << "YES" << endl;
		end=0;
	}

	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
            return false;
    }else{
        if(Right.empty() || numbers[index] > Right.top())
            Right.push(numbers[index]);
        else
            return false;
    }
    if(index == 9)return true;
    else if(dfs(index+1, 0))return true;
    else if(dfs(index+1, 1)) return true;
    else 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 <cstring>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std;
int ball[15];
int leftFront, rightFront;
bool isOK;
void DFS(int depth)
{
    if(depth == 10 || isOK)
    {
        isOK = true;
        return;
    }

    if(ball[depth] > leftFront)
    {
        leftFront = ball[depth];
        DFS(depth + 1);
    }

    if(ball[depth] > rightFront)
    {
        rightFront = ball[depth];
        DFS(depth + 1);
    }

    return;
}
int main(void)
{
	int n;
	scanf("%d", &n);

	while(n--)
    {
        for(int i = 0; i < 10; i++)
            scanf("%d", &ball[i]);

        isOK = false;
        leftFront = 0;
        rightFront = 0;

        DFS(0);

        if(isOK)
            printf("YES\n");
        else
            printf("NO\n");
    }

	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(void){
	int n,a,b,c;
	bool f;
	cin>>n;
	for(int i=0;i<n;i++){
		f=true;b=0;c=0;
		for(int j=0;j<10;j++){
			cin>>a;
			if(b>a&&c>a){
				f=false;
				break;
			}else if(b<a && c<a){
				if(b>=c)b=a;
				else c=a;
			}else if(b<a){
				b=a;
			}else if(c<a){
				c=a;
			}
		}
		if(f)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

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

int main(){
	int n, a, b, in;
	cin >> n;
	for(int i=0;i<n;i++){
		a = 0;
		b = 0;
		for(int j=0;j<10;j++){
			cin >> in;
			if(in>a){
				a = in;
			}
			else if(in>b){
				b = in;
			}
			else{
				cout << "NO" << endl;
				break;
			}
			if (j==9){
				cout << "YES" << endl;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;
#define FOR(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
int num[10];
int B[10];
int C[10];
bool flag;
void solve(int, int, int);

int main(void){
	int N;
	cin >> N;
	for(int k = 0; k < N; k++){
		flag = false;
		fill_n(B , 10, -1);
		fill_n(C , 10, -1);
		for(int i = 0; i < 10; i++){
			cin >> num[i];
		}
		solve(0, 0, 0);
		if(flag){cout << "YES" << endl; continue;}
		cout << "NO" << endl;
	}

	return 0;
}

void solve(int cnt,int right, int left){
	if(cnt == 10){
		flag = true;
		return;
	}
	if(num[cnt] > right) solve(cnt+1, num[cnt], left);
	if(num[cnt] > left) solve(cnt+1, right, num[cnt]);
}