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>
using namespace std;

bool ball(int left, int right, int i, vector<int> &stack) {
    if (i == 10)
        return true;

    if (stack[i] > left)
        return ball(stack[i], right, i + 1, stack);

    if (stack[i] > right)
        return ball(left, stack[i], i + 1, stack);

    return false;
}

int main()
{
    int n;
    cin >> n;
    vector<int> stack(10);

    while (n--) {
        for (int i = 0; i < 10; i++)
            cin >> stack[i];
        cout << (ball(0, 0, 0, stack) ? "YES" : "NO") << endl;
    }

    return 0;
}

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

int num[10];
int left_num[10], right_num[10];
int l, r;

bool dfs(int i) {
	if (i == 10) {
		return true;
	}
	if (i == 0) {
		left_num[l] = num[i];
		return dfs(i + 1);
	}
	if (left_num[l] < num[i]) {
		l++;
		left_num[l] = num[i];
		return dfs(i + 1);
	}
	if (right_num[r] < num[i]) {
		if (r == 0) {
			right_num[r] = num[i];
			return dfs(i + 1);
		} else {
			r++;
			right_num[r] = num[i];
			return dfs(i + 1);
		}
	}
	return false;
}

int main(void) {
	int i, N;
	cin >> N;

	while (N--) {
		l = 0, r = 0;
		for (i = 0; i < 10; i++) {
			cin >> num[i];
			left_num[i] = 0;
			right_num[i] = 0;
		}
		if (dfs(0)) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}

	return 0;
}

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

int balls[10];

bool dfs(int i, int a, int b)
{
	if (i == 10) return true;
	bool ans = false;
	if (a < balls[i]) ans = dfs(i + 1, balls[i], b);
	if (b < balls[i]) ans = dfs(i + 1, a, balls[i]);
	return ans;
}

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

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

using namespace std;

	int a[10];
	stack<int> B,C;


bool dfs(int n){
	if(n==10){

		return true;
	}

	if(B.empty() || B.top()<a[n]){
		B.push(a[n]);
		if( dfs(n+1) )return true;
	}else{
		B.pop();
		return false;
	}

	if(C.empty() || C.top()<a[n]){
		C.push(a[n]);
		if( dfs(n+1) )return true;
	}else{
		C.pop();
		return false;
	}
}



int main(){
	int n;
	cin>>n;

	for(int T=0;T<n;T++){
		for(int i=0;i<10;i++){
			cin>>a[i];
		}

		while(B.size()){
			B.pop();
		}
		while(C.size()){
			C.pop();
		}

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

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 1000000000;
using namespace std;
int main() {
  int n, s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a = 0, b = 0;
    bool key = 1;
    for (int j = 0; j < 10; j++) {
      cin >> s;
      if (s > a)
        a = s;
      else if (s > b)
        b = s;
      else
        key = 0;
    }
    cout << (key ? "YES" : "NO") << endl;
  }
  return 0;
}

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

bool solver(queue<int> q, int a, int b){
    bool result = false;
    if(q.empty()) return true;
    int tmp = q.front();
    if(tmp > a){
        q.pop();
        result = solver(q, tmp, b);
        q.push(tmp);
    }
    tmp = q.front();
    if(tmp > b){
        q.pop();
        result = solver(q, a, tmp);
        q.push(tmp);
    }
    return result;
}
int main(){
    int n;
    cin >> n;

    for(int i=0; i<n; i++){
        queue<int> q;
        for(int j=0; j<10; j++){
            int tmp;
            cin >> tmp;
            q.push(tmp);
        }
        cout << (solver(q,0,0)?"YES":"NO") << endl;
    }
    return 0;
}

C++: #include <stdio.h>

#include <stack>

int main(void){
    using namespace std;
    stack<int> a,b;
    int n,j,i,ball,flag;
    scanf("%d",&n);
    for(j=0; j<n; j++){
        flag=0;
        for(i=0; i<10; i++){
            scanf("%d",&ball);
            if(a.empty()){
                a.push(ball);
            }else if(a.top() < ball){
                a.push(ball);
            }else if(b.empty()){
                b.push(ball);
            }else if(b.top() < ball){
                b.push(ball);
            }else{
                flag=1;
            }
        }
        while(!a.empty()){
            a.pop();
        }
        while(!b.empty()){
            b.pop();
        }
        printf("\n");
        if(flag==0){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
  int n, num, right, left;
  bool flag;

  cin >> n;

  for(int i = 0; i < n; i++){
    right = 0;
    left = 0;
    flag = true;

    for(int j = 0; j < 10; j++){
      cin >> num;

      if(right < num){
        right = num;
      }else if(left < num){
        left = num;
      }else{
        flag = false;
        break;
      }
    }

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

  return 0;
}

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

int main(){
    int x;
    std::cin>>x;
    for(int i=0;i<x;++i){
        std::vector<int> vec(10);
        for(int l=0;l<10;++l){
            std::cin>>vec[l];
        }
        std::vector<std::vector<int> > vec2(2);
        vec2[0].push_back(vec[0]);
        for(int l=1;l<vec.size();++l){
            if(l==1){
                if(vec2[0][0]<vec[1]){
                    vec2[0].push_back(vec[1]);
                }else vec2[1].push_back(vec[1]);
            }else{
                if(vec[l]>vec2[0][vec2[0].size()-1]){
                    if(vec2[1].size()!=0&&vec2[1][vec2[1].size()-1]>vec[l]){
                        if(vec2[0][vec2[0].size()-1]>vec2[1][vec2[1].size()-1])vec2[0].push_back(vec[l]);
                        else vec2[1].push_back(vec[l]);
                    }else{
                        vec2[0].push_back(vec[l]);
                    }
                }else{
                    if(vec2[1].size()!=0?vec[l]>vec2[1][vec2[1].size()-1]:true){
                        vec2[1].push_back(vec[l]);
                    }else{
                        std::cout<<"NO"<<std::endl;
                        goto cont;
                    }
                }
            }
        }
        std::cout<<"YES"<<std::endl;
    cont:;
    }
    return 0;
}

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

using namespace std;

int main(){
	int n,tempb,tempc,ch;
	int a[11];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++) scanf("%d",&a[j]);
		tempb = a[0];
		tempc = a[1];
		ch = 0;
		for(int j=2;j<10;j+=2){
			if(tempb>a[j]||tempc>a[j+1]){
				ch = 1;
				break;
			}
			tempb=a[j];
			tempc=a[j+1];
		}
		if(ch==1)
		printf("NO\n");
		else
		printf("YES\n");
	}
}