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 Balls[10];

bool fork(int balls[], int i, int b, int c) {
    if (i == 10) return true;
    if (b > balls[i] && c > balls[i]) return false;
    if (b < balls[i]) fork(balls, i + 1, balls[i], c);
    if (c < balls[i]) fork(balls, i + 1, b, balls[i]);
}


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

    }
        return 0;
}

C++: 
#include <iostream>

using namespace std;

int main() {
	const bool debug = false;
	int N;
	cin >> N;

	int* balls = new int[N * 10];
	for (int i = 0; i < N * 10; i++) {
		cin >> balls[i];
	}

	for (int j = 0; j < N; j++) {
		bool isYes = true;
		int hole[2] = { 0,0 };
		for (int i = 0; i < 10; i++) {
			if (hole[0] < balls[i+j*10]) {
				hole[0] = balls[i + j * 10];
				if (debug)
					cout << "" << balls[i + j * 10] << "\n";
			} else if (hole[1] < balls[i + j * 10]) {
				hole[1] = balls[i + j * 10];
				if (debug)
					cout << "  " << balls[i + j * 10] << "\n";

			} else {
				if (debug)
					cout << "falure\n";
				isYes = false;
				break;
				
			}
		}
		cout << (isYes ? "YES" : "NO") << "\n";
	}
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
int n;
scanf("%d", &n);
for(int testcase = 0; testcase < n; ++testcase) {
bool yes = false;
int s = 10;
vector<int> x;
x.resize(s);
for(int i = 0; i < s; ++i)
scanf("%d", &x[i]);
for(int bit = 0; bit < (1 << s); ++bit) {
int count = 0;
for(int i = 0; i < s; ++i)
count += (bit >> i) & 1;
if(count != s / 2)
continue;
bool valid = true;
for(int lr = 0; lr < 2; ++lr) {
int prev = -100;
for(int i = 0; i < s; ++i) {
if((bit >> i) == lr) {
if(prev >= x[i]) {
valid = false;
break;
}
prev = x[i];
}
}
}
if(valid) {
yes = true;
break;
}
}
printf("%s\n", yes ? "YES" : "NO");
}
return 0;
}

C++: #include <iostream>
using namespace std;
int a[20];
int b,c;
int main(){
    int ti;
    cin>>ti;
    while(ti--){
        b=c=0;
        bool flag=1;
        for(int i=1;i<=10;i++){
            cin>>a[i];
        }
        for(int i=1;i<=10;i++){
            if(b>a[i]&&c>a[i]){
                cout<<"NO"<<endl;
                flag=0;
                break;
            }
            if(a[i]>b){
                b=a[i];
                continue;
            }
            if(a[i]>c){
                c=a[i];
                continue;
            }
        }
        if(flag){
            cout<<"YES"<<endl;
        }
    }
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find(all(v), i) != (v).end())
#define ERASE(v,i) (v).erase(remove(all(v), i), (v).end())
#define INDEX(v,i) (find(all(v), i) - (v).begin())
#define rep(i,n) for(int i = 0; i < (int)n; ++i)
#define debug(x) cerr << #x << " = " << (x) << endl;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

const int INF = 100000000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

int main() {
	int N; cin >> N;
	for(int rou = 0; rou < N; rou++) {
		vector<int> data(10);
		rep(i,10) cin >> data[i];
		bool ans = false;
		for(int i = 0; i < (1<<10); i++) {
			vector<int> b;
			vector<int> c;

			rep(j,10) {
				if(i & (1<<j)) {
					b.pb(data[j]);
				} else {
					c.pb(data[j]);
				}
			}

			bool f = true;
			int bp = 0;
			int cp = 0;
			for(int j = 0, n = b.size(); j < n; j++) {
				if(b[j] < bp) f = false;
				bp = b[j];
			}
			for(int j = 0, n = c.size(); j < n; j++) {
				if(c[j] < cp) f = false;
				cp = c[j];
			}
			if(f) {
				ans = true;
				break;
			}
		}
		cout << (ans ? "YES" : "NO") << endl;
	}
	return 0;
}

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

using namespace std;

int a[10];

bool dfs(int B, int C, int i)
{
    if(i == 10)
        return true;
    else if(B < a[i])
        return dfs(a[i], C, i + 1);
    else if(C < a[i])
        return dfs(B, a[i], i + 1);
    
    return false;
}

int main()
{
    int N;
    cin >> N;
    while(N--)
    {
        for(int i = 0; i < 10; i++)
            cin >> a[i];
        
        cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    while(n--) {
        int l = 0, r = 0;
        bool ok = true;
        for(int i=0; i<10; ++i) {
            int x;
            cin >> x;
            if(l < x && r < x) {
                if(l < r) {
                    r = x;
                } else {
                    l = x;
                }
            } else if(l < x) {
                l = x;
            } else if(r < x) {
                r = x;
            } else {
                ok = false;
            }
        }
        if(ok) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}

C++: #include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;

int main(){
	int b,c,m,n,s;
	cin>>m;
	for(int i=0;i<m;i++){
		b=0,c=-1,s=0;
		for(int j=0;j<10;j++){
			cin>>n;
			if(n>b&&n>c){
				if(b>c)b=n;
				else c=n;
			}
			else if(n>b)b=n;
			else if(n>c)c=n;
			else s=1;
		}
		if(s==0)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}