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++: /* 
 author:hdsdogge 
 begin: 
 end: 
 cost: 
 */
#include<iostream>
#include<string>
#include<queue>
#include<map>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<vector>
#include<bitset>
#include<cstdlib>
#include<list>
#include <sstream>
#include<ctype.h>
using namespace std;
const int maxn=100+10;
typedef pair<int,int> P;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
int T,n,m;
int a[maxn];
bool ans;
void dfs(int l,int r,int cnt){
    if(cnt==10)
        ans=true;
    if(a[cnt]>l)
        dfs(a[cnt],r,cnt+1);
    if(a[cnt]>r)
        dfs(l,a[cnt],cnt+1);
}
int main() {
    //freopen("test","r",stdin);
    //freopen("out","w",stdout);
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cin>>T;
    while(T--){
        for(int i=0;i<10;i++)
            cin>>a[i];
        ans=false;
        dfs(0,0,0);
        if(ans)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

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

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 && a < c) {
                ok = false;
                break;
            } else if (a < b) {
                c = a;
            } else if (a < c) {
                b = a;
            } else if (b > c) {
                b = a;
            } else {
                c = a;
            }
        }
        cout << (ok ? "YES" : "NO") << endl;
    }
    return 0;
}

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

using namespace std;

int pou[12] = {0};


int dfs(int nau,int b,int c){
  if(nau == 11) return 1;
  if(pou[nau-1] > b){
    if( dfs(nau+1,pou[nau-1],c) == 1){
      return 1;
    }
  }

  if(pou[nau-1] > c){
    if( dfs(nau+1,b,pou[nau-1])==1){
      return 1;
    }
  }

  return 0;
}



int main(){

  int n=0;

  scanf("%d",&n);

  for(int i = 0;i < n;i++){

    for(int j = 0;j < 10;j++){
      scanf("%d",&pou[j]);
    }

    if(dfs(1,0,0) == 1){
      printf("YES\n");
    }else{
      puts("NO");
    }
  }
  return 0;
}

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


int main() {
  int n;
  int data[10];
   while ( cin >> n ) {
     int flag = 1;
     for ( int i = 0; i < 10; i++ ) cin >> data[i];
     for ( int i = 0; i < 8; i++ ) {
       if ( data[i] > data[i+1] && 
	    data[i] > data[i+2] ) {
	 flag = 0;
       }
     }
     if ( flag ) cout << "YES" << endl;
     else cout << "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(a.top() < ball){
                b.push(ball);
            }else{
                flag=1;
            }
        }
        if(flag==0){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}

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

int main(){
	int n;
	std::cin >> n;
	while (n){
		std::vector<int> ball(10);
		for (int i = 0; i < 10; ++i)std::cin >> ball[i];
		int b = 0, c = 0;
		for (int i = 0; i < 10; ++i){
			if (b < c){
				std::swap(b, c);
			}
			else if (b < ball[i]){
				b = ball[i];
			}
			else if (c < ball[i]){
				c = ball[i];
			}
			else {
				std::cout << "NO" << std::endl;
				break;
			}
			if(i==9){
				std::cout << "YES" << std::endl;
				break;
			}
		}
		n--;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
 
int balls[10];
 
bool dfs(int idx, int b, int c){
    if(idx > 9) return true;
     
    bool ok = false;
    if(b < balls[idx]) ok = dfs(idx+1, balls[idx], c);
    if(c < balls[idx]) ok = dfs(idx+1, b, balls[idx]);
    return ok;
}
 
int main() {
    int n; cin >> n;
    while(n--){
        for(int i = 0; i < 10; i++) cin >> balls[i];
	cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
    }
}

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

bool dfs(vector<int> que, int index, int left, int right) {
    if (index == que.size()) {
        return true;
    } else {
        bool res = false;
        if (que[index] > left) res |= dfs(que, index+1, que[index], right); 
        if (que[index] > right) res |= dfs(que, index+1, left, que[index]); 
        return res;
    }
}

int main() {
    int T; cin >> T;
    string s;
    getline(cin, s);
    for (int i = 0; i < T; i++) {
        vector<int> v;
        getline(cin, s);
        stringstream ss(s);
        int t;
        while (ss >> t) v.push_back(t);

        cout << (dfs(v, 0, 0, 0) ? "YES" : "NO") << endl;
    }
}

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

int n;
int a[10];


bool dfs(int i, int left, int right) {
    if (i == 9) return a[i] > left || a[i] > right;
    if (a[i] > left && dfs(i+1, a[i], right)) return true;
    if (a[i] > right && dfs(i+1, left, a[i])) return true;
    return false;
}

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

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

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

int Balls[10];

bool dfs(int i, int R, int L)
{
	if(i == 10) return true;

	if(dfs(i+1, Balls[i], L) && Balls[i] > R) return true;

	if(dfs(i+1, R, Balls[i]) && Balls[i] > L) return true;

	return false;
}

void 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\n";
		else cout << "NO\n";
	}
}

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

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

		int ca = 0, cb = 0;
		va[0] = d[0];
		ca++;
		if (d[1] > va[0]) {
			va[1] = d[1];
			ca++;
		}

		else {
			vb[0] = d[1];
			cb++;
		}

	for (int j = 2; j < 10; j++) {

			if (d[j] > va[ca-1]) {
				va[ca] = d[j];
				ca++;
			}

			else if (d[j] > vb[cb-1]) {
				vb[cb] = d[j];
				cb++;
			}

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

		}
		cout << "YES" << endl;

		for (int i = 0; i < 10; i++) {
			va[i] = 0;
		}
		for (int i = 0; i < 10; i++) {
			vb[i] = 0;
		}
	}
	return 0;
}