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 i=0;i<10;i++){
			cin>>ball[i];
		}
		l=0,r=0;
		flag=false;
	    dfs(i,l,r);
		if(flag){
			cout<<"NO"<<endl;
		}else{
			cout<<"YES"<<endl;
		} 
	}
}

C++: #include <stdio.h>

int main(void){
	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;
				for (;i<10;i++) scanf("%d", &tmp);
				break;
			}
		}
		printf("%s\n",valid?"YES":"NO");
	}
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<vector>

using namespace std;

int main(){
    int n;
    bool flag = true;
    vector<int> b, c;
    b.push_back(0);
    c.push_back(0);
    vector<int> ::iterator b_it=b.begin(), c_it=c.begin();

    cin>> n;
    while(n--, n!=-1){
        for(int i=0; i<10; i++){
            if(flag){
                int num;
                cin>> num;
                if(num>*b_it){
                    b.push_back(num);
                    b_it = b.end()-1;
                }else if(num>*c_it){
                    c.push_back(num);
                    c_it = c.end()-1;
                }else{
                    flag = false;
                }
            }
        }
        if(flag){
            cout<< "YES"<< endl;
        }else{
            cout<< "NO"<< endl;
        }
    }
    return 0;
}

C++: #include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int n;
int array[10];

void solve() {
    int B=0;
    int C=0;
    rep(i,10) cin>>array[i];
    B = array[0];
    C = array[1];

    rep(i,10) {
        if(i==0 || i==1) continue;
        int t1 = array[i] - B;
        int t2 = array[i] - C;
        // cout<<t1<<","<<t2<<endl;
        if(t1<=0 && t2<=0) {
            cout<<"NO"<<endl;
            return;
        }
        else if(t1 > t2) {
            C = array[i];
        }
        else {
            B = array[i];
        }
    }

    cout<<"YES"<<endl;

}

int main() {
    cin>>n;
    rep(i,n) solve();
    return 0;
}

C++: #include <bits/stdc++.h>
 
using namespace std;
 
int n, ball[10];
 
bool solve(int idx, int l, int r) {
 
    if(idx >= 10) return true;
 
    bool ret = false;
    if(ball[idx] > l) ret = ret || solve(idx + 1, ball[idx], r);
    if(ball[idx] > r) ret = ret || solve(idx + 1, l, ball[idx]);
    return ret;
 
}
 
int main() {
 
    cin >> n;
 
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < 10; ++j) {
            cin >> ball[j];
        }
        cout << solve(0, 0, 0) ? "YES" : "NO" << endl;
    }
 
}

C++: #include <iostream>

using namespace std;

int main(void) {
    int N, a, b, c;
    cin >> N;
    for (; N--; ) {
        b = c = 0;
        bool ok = true;
        for (int i = 0; i < 10; i++) {
            cin >> a;
            if (a > b) {
                b = a;
            } else if (a > c) {
                c = a;
            } else {
                ok = false;
                break;
            }
        }
        if (ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

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

using namespace std;

int main() {

	stack<int> B, C;
	int n,ball;

	cin >> n;

	for(int j=0;j<n;j++){
		for (int i = 0; i < 10; i++) {
			cin >> ball;

			if (i == 0)
				B.push(ball);

			else if (B.top() > ball)

				if (C.empty())
					C.push(ball);

				else if (C.top() < ball)
					C.push(ball);

				else {
					cout << "NO" << endl;
					break;
				}

			else {
				if (B.top() < ball)
					B.push(ball);
				else {
					cout << "NO" << endl;
					break;
				}
			}

			if (i == 9)
				cout << "YES" << endl;
		}
		while (1) {
			B.pop();
			if (B.empty())
				break;
		}
		while (1) {
			C.pop();
			if (C.empty())
				break;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
int main(){
	int N, i;
	int num[11];
	cin >> N;
	while( N-- > 0 ){
		for( i = 0; i < 10; i++ ){
			cin >> num[i];
		}
		stack<int> st1;
		stack<int> st2;
		for( i = 0; i < 10; i++ ){
			if( st1.empty() ){
				st1.push(num[i]);
				continue;
			}else if( st2.empty() ){
				if( st1.top() < num[i] ){
					st1.push(num[i]);
					continue;
				}else{
					st2.push(num[i]);
					continue;
				}
			}
			if( st1.top() > num[i] ){
				if( st2.top() > num[i] ){
					cout << "NO" << endl;
					break;
				}else{
					st2.push(num[i]);
				}
			}else{
				if( st2.top() < num[i] ){
					if( st1.top() > st2.top() ){
						st1.push(num[i]);
					}else{
						st2.push(num[i]);
					}
				}
			}
		}
		if( i == 10 ) cout << "YES" << endl;
	}
}