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 <vector>
#include <string>
#include <algorithm>
using namespace std;

bool check(vector<int>& s){
	int crt = 0;
	bool res = true;
	for(int i = 0;i < s.size();++i){
		if(s[i] > crt) crt = s[i];
		else{
			res = false;
			break;
		}
	}
	return res;
}

int main(){
	int n;cin >> n;
	cin.get();
	while(n--){
		vector<int> nums(10);
		for(int i = 0;i < 10;++i) cin >> nums[i];
		int size = 10;
		bool res = false;
		for(int i = 0;i < (1<<size);++i){
			vector<int> num1,num2;
			for(int j = 0;j < size;++j){
				if((i>>j)&1) num1.push_back(nums[j]);
				else num2.push_back(nums[j]);
			}
			if(check(num1) && check(num2)){
				res = true;
				break;
			}
		}
		if(res) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

int main() {
    int n, x;
    cin >> n;
    while (n--) {
        int a = 0, b = 0;
        bool ok = true;
        for (int j=0; j<10; ++j) {
            cin >> x;
            if (a < x && b < x) {
                if (a < b) {
                    b = x;
                } else {
                    a = x;
                }
            } else if (a < x) {
                a = x;
            } else if (b < x) {
                b = x;
            } else {
                ok = false;
                break;
            }
        }
        cout << (ok ? "YES" : "NO") << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int a[10];

bool dfs(int i, int left, int right){
	//cout << left << " " << right << " " << i << endl;
	if(i == 10) return true;
	bool answer = false;
	if(left < a[i]){
		answer = dfs(i+1, a[i], right);
	}
	if(right < a[i]){
		answer = dfs(i+1, left, a[i]);
	}

	return answer;
}


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

C++: #include <iostream>
#include <climits>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <vector>

#define ll long long
#define REP(i, n) for (int i=0;i<n;++i)
#define REP_1(i, n) for (int i=1;i<=n;++i)
#define REP_2(i, j, n, m) REP(i, n) REP(j, m)
#define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m)

#define JU_RAN(a,x,b) a<=x&&x<=b



using namespace std;

int v[15];
void solve(){
    int n;
    cin>>n;
    while (n--){
        REP_1(i,10)cin>>v[i];
        stack<int > a;
        stack<int > b;
        a.push(0);
        b.push(0);

        bool f=1;
        REP_1(i,10){
            if(a.top()>=b.top()){
                if(a.top()<v[i]){
                    a.push(v[i]);
                } else if(b.top()<v[i]){
                    b.push(v[i]);
                } else{
                    f=0;
                    break;
                }
            }
            else{
                if(b.top()<v[i]){
                    b.push(v[i]);
                } else if(a.top()<v[i]){
                    a.push(v[i]);
                } else{
                    f=0;
                    break;
                }
            }
        }

        if(f){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }

    }

}



int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    solve();



#ifdef LOCAL_DEFINE
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

C++: #include <cstdio>
using namespace std;
int n;
int a[11];
int main() {
    scanf("%d", &n);
    for (int t = 0; t < n; ++t) {
        int l = 0, r = 0;
        for (int i = 0; i < 10; ++i) scanf("%d", &a[i]);
        bool flag=false;
        for (int i = 0; i < 10; ++i) {
            if (r > l) {
                if (a[i] > r) r = a[i];
                else if (a[i] > l) l = a[i];
                else flag=true;
            } else {
                if (a[i] > l) l = a[i];
                else if (a[i] > r) r = a[i];
                else flag=true;
            }
        }
        if (flag) printf("NO\n");
        else printf("YES\n");

    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int num[10];
bool dfs(int start, int topl, int topr)
{
	if (start == 9)
	{
		if (num[start] > topl || num[start] > topr)
			return true;
		else
			return false;
	}
	else
	{
		bool b1 = false, b2 = false;
		if (num[start] > topl)
			b1=dfs(start + 1, num[start], topr);
		if (num[start] > topr)
			b2 = dfs(start + 1, topl, num[start]);
		return (b1 || b2);
	}
}
	
int main()
{
	int k;
	cin >> k;
	while (k--)
	{
		for (int i = 0; i <= 9; ++i)
			cin >> num[i];
		if (dfs(0,0,0))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

C++: #include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#define NUM_OF_BALLS 10
using namespace std;

int N;
queue<int> A;

//並べられるかどうかの判定とB,Cの値の更新
bool dfs(int B,int C){
	int ball;
	if(A.empty()) return true;
	else{
		ball = A.front();A.pop();
		if(ball <= min(B,C)){
			while(!A.empty())A.pop();
			return false;
		}
		if(ball > B)return dfs(ball,C);
		if(ball > C)return dfs(B,ball);

		printf("e\n");return false;
	}
}

void solve(){
	if(dfs(0,0))printf("YES\n");
	else printf("NO\n");
	return;
}

int main() {
	int tmp;
	scanf("%d",&N);

	for(int n = 0;n < N;n++){
		for(int i = 0;i < NUM_OF_BALLS;i++){
			scanf("%d",&tmp);
			A.push(tmp);
		}

		solve();
	}
   

    return 0;
}

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

int main(void){
	int c;
	cin >> c;
	for(int j = 0; j < c-1; j++){
		int data[10];
		for(int i = 0; i < 10; i++){
			cin >> data[i];
		}

		int B, C = 0;
		B = data[0];
		bool flag = 0;

		for(int i = 1; i < 10; i++){
			if(B+1 != data[i]){
				if(C == 0){
					C = data[i];
				}else if(C+1 != data[i]){
					cout << "NO" << endl;
					break;
				}else{
					C = data[i];
				}
			}else{
				B = data[i];
			}
			if(i == 9){cout << "YES" << endl;}
		}
	}

}

C++: #include <iostream>
#include <vector>
#include <string>
#include <queue>
#define INF 10000000
using namespace std;
typedef pair<int,int> P;

int n;
int ba[10];

bool all(int,int,int);

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

bool all(int end,int l,int r){
  if(end==10){
    return true;
  }
  if(ba[end]>l){
    return all(end+1,ba[end],r);
  }
  if(ba[end]>r){
    return all(end+1,l,ba[end]);
  }
  return false;
}