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<cstring>
using namespace std;
int ball[10];
int l,r;
bool flag;
void dfs(int num,int l,int r){
	if(num==10) return ;
	if(flag) return ;
	if(ball[num]>l) dfs(num+1,ball[num],r);
	else if(ball[num]>r) dfs(num+1,l,ball[num]);
	else{
		flag=true;
		return ;
	}
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			cin>>ball[j];
		}
		l=0,r=0;
		flag=false;
	    dfs(0,l,r);
		if(flag){
			cout<<"NO"<<endl;
		}else{
			cout<<"YES"<<endl;
		} 
	}
}

C++: #include <iostream>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  cin>>n;
  while(n--){
    int a[10],b[2][11]={0},b1=1,b2=1,k=0;
    r(i,10)cin>>a[i];
    r(i,10){
      if(a[i]>b[1][b1-1])b[1][b1++]=a[i];
      else b[0][b2++]=a[i];
    }
    r(i,b1-1){if(b[1][i]>b[1][i+1])k++;}
    r(i,b2-1){if(b[0][i]>b[0][i+1])k++;}
    if(k)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
  }
}

C++: #include<stdio.h>
#include <queue>
using namespace std;

bool flag = true;

void solve(queue<int> left, queue<int> right, queue<int> all) {
	if (all.size() > 0) {
		if (left.size() > 0) {
			if (all.front() > left.back()) {
				left.push(all.front());
				all.pop();
				solve(left, right, all);
			}
			else {
				if (right.size() > 0) {
					if (all.front() > right.back()) {
						right.push(all.front());
						all.pop();
						solve(left, right, all);
					}
					else if(all.size() == 0){
					
					}
					else {
						flag = false;
					}
				}
				else {
					right.push(all.front());
					all.pop();
					solve(left, right, all);
				}
			}
		}
		else {
			left.push(all.front());
			all.pop();
			solve(left, right, all);
		}
	}
}

int main() {

	int n;
	scanf("%d", &n);
	for (; n > 0; n--) {
		queue<int> all;
		queue<int> left;
		queue<int> right;
		for (int i = 0; i < 10; i++) {
			int temp;
			scanf("%d", &temp);
			all.push(temp);
		}
		solve(left, right, all);
		if (flag)
			printf("YES\n");
		else
			printf("NO\n");
	}	
	return 0;
}

C++: #include <stdio.h>

int a[11];

bool dfs(int i, int R, int L){
    if (i == 10) return true;
    if (dfs(i+1, a[i], L) && a[i] > R)
		return true;
    if (dfs(i+1, R, a[i]) && a[i] > L)
		return true;
    return false;
}

void solve(){
	for (int i=0; i<10; ++i){
		scanf("%d", &a[i]);
	}
	printf("%sn", dfs(0, 0, 0)?"YES":"NO");
}

int main (){
	int t;
	scanf("%d", &t);
	while (t --){
		solve();
	}
	return 0;
}

C++: #include<cstdio>

int main(){
	int n;
	int b,c;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		b = c = 0;
		int t;
		for(int j = 0; j < 10; j++){
			scanf("%d", &t);
			if(b < t){
				b = t;
			}else{
				if(c < t){
					c = t;
				}else{
					t = 11;
					break;
				}
			}
		}
		if(t - 11){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}

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

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];
		stack<int> B, C;
		B.push(A[0]);
		for (int j = 1; j < 10; j++) {
			if (B.top() < A[j])B.push(A[j]);
			else if (C.empty() == 1 || C.top() < A[j])C.push(A[j]);
			else {
				cout << "NO" << endl;
				break;
			}
			if (j == 9)cout << "YES" << endl;
		}
	}

	return 0;
}

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

int a[15], b[2], flag[2];

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int is_yes = 1;
        b[0] = b[1] = 0;
        for(int i = 0; i < 10; i++)
            cin >> a[i];
        for(int i = 0; i < 10; i++)
        {
            flag[0] = flag[1] = 0;
            for(int j = 0; j < 2; j++)
            {
                //cout << "a[i]" << a[i] << endl;
                if(b[j] == 0)
                {
                    b[j] = a[i];
                    break;
                }
                else if(b[j] < a[i])
                {
                    b[j] = a[i];
                    break;
                }
                flag[j] = 1;
            }
            //for(int j = 0; j < 2; j++)
                //cout << "b[" << j <<"] = " << b[j] << endl;
            if(flag[1] && flag[0])
            {
                cout << "NO" << endl;
                is_yes = 0;
                break;
            }
        }
        if(is_yes)
            cout << "YES" << endl;
    }


    return 0;
}

C++: #include<iostream>
using namespace std;
#define RIGHT 1
#define LEFT 0
#define BALL 10
#define BAD 1

int main()
{
    int n;
    int num[BALL];
    int siden[BALL];
    cin >> n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<BALL;++j) {cin >> num[j]; }

        int temp,ans =0;
        unsigned int side;
        for(side=0;side<=4050;++side)
        {
            ans = 0;
            for(int j = 0;j<BALL;++j)
            {
                if(((side>>j)&1) ){siden[j] = RIGHT;}
                else {siden[j] = LEFT;}
            }
            int before = -1;
            for(int j=0;j<BALL;++j)
            {
                if(siden[j]==RIGHT)
                {
                    if(before > -1)
                    {
                        if(num[before]>num[j])ans = BAD;
                    }
                    before = j;
                }
            }
            before = -1;

            for(int j=0;j<BALL;++j)
            {
                if(siden[j]==LEFT)
                {
                    if(before > -1)
                    {
                        if(num[before]>num[j])ans = BAD;
                    }
                    before = j;
                }
            }
            if(ans==0)break;
        }
        if(ans==BAD) cout << "NO" << endl;
        else cout << "YES" << endl;

    }
    return 0;
}

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

using namespace std;

int main(){
        int n;
        cin >> n;
        for(int i = 0; i < n; i++){
                int num[10];
                for(int j = 0; j < 10; j++){
                        cin >> num[j];
                }

                // 深さ優先探索?
                int a, b;
                int j;
                a = b = 0;
                for(j = 0; j < 10; j++){
                        if(a < num[j]){
                                a = num[j];
                                continue;
                        }
                        if(b < num[j]){
                                b = num[j];
                                continue;
                        }
                        break;
                }

                if(j != 10){
                        cout << "NO" << endl;
                } else {
                        cout << "YES" << endl;
                }
        }

        return 0;
}