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 N;
int order[10];
int l[11];
int r[11];

bool dfs(int i, int b, int c){
    
    if(i == 10)
        return true;
    
    if(order[i] > l[b-1]){
        l[b] = order[i];
        return dfs(i+1, b+1, c);
    }
        
    if(order[i] > r[c-1]){
        r[c] = order[i];
        return dfs(i+1, b, c+1);
    }  
    
    return false;
}

int main(){
    scanf("%d", &N);
    while(N--){
        
        for(int i = 0; i < 10; i++){
            scanf("%d",&order[i]);
            l[i] = -1;
            r[i] = -1;
        }
        
        if(dfs(0, 1, 1))
            printf("YES\n");
 
        else
            printf("NO\n");
    }
    return 0;
}

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

using namespace std;

const int BALL_NUM = 10;

int ball[BALL_NUM];

bool dfs(int i, int left, int right) {
    if (i == BALL_NUM) { return true; }
    bool ans = false;
    if (left < ball[i]) {
        ans = dfs(i + 1, ball[i], right);
    }
    if (right < ball[i]) {
        ans = dfs(i + 1, left, ball[i]);
    }
    return ans;
}

int main() {
    long n;
    scanf("%ld", &n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < BALL_NUM; j++) {
            scanf("%d", &ball[j]);
        }
        if (dfs(0, 0, 0)) { printf("%s\n", "YES"); }
        else { printf("%s\n", "NO"); }
    }

    return 0;
}

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

int n;
int a[10];
int r, l;

// bool dfs(int i) {
//     if (i == 9) return a[i] > r || a[i] > l;
//     if (a[i] > r) {
//         r = a[i];
//     }
//     if (a[i] > l) {
//         l = a[i];
//     }
//     if (dfs(i+1)) return true;
//     return false;
// }

bool dfs(int i, int r, int l) {
	if (i == 9) return a[i] > r || a[i] > l;
	if (dfs(i + 1, max(a[i + 1], r), l)) return true;
	if (dfs(i + 1, r, max(a[i + 1], l))) return true;
	return false;
}

void solve() {
	if (dfs(0, a[0], a[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();
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;

int a[20];
bool vis[20];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T;cin>>T;
	while(T--){
		bool flag=false;
		for(int i=1;i<=10;i++){
			cin>>a[i];
		}
		int k[20];
		int len=1;
		k[1]=a[1];
		for(int i=2;i<=10;i++){
			if(a[i]<k[len]){
				k[++len]=a[i];
			}else{
				*upper_bound(k+1,k+1+len,a[i],greater<int>())=a[i];
			}
			if(len>2){
				flag=true;
				break;
			}
		}
		cout<<(flag?"NO\n":"YES\n");
	}
	return 0;
}

C++: #include<algorithm>
#include<vector>
#include<queue>

using namespace std;

int A[13] = { 0 };

bool solve(int a, int b,int c) {
	if (++c == 10)
		return true;
	else {
		bool r = false;
		if (a < A[c])
			r = solve(A[c], b, c);
		if (b < A[c] && r == false)
			r = solve(a,A[c], c);
		
		return r;
	}
}

int main(void) {
	A[10] = A[11] = A[12] = 100;
	int n = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++)
			scanf("%d", &A[j]);
		if (solve(A[0], 0, 0))
			printf("YES\n");
		else
			printf("NO\n");
	}
}

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


int main() {
  int n;
  int data[10];
  cin >> n;
  while ( n > 0 ) {
    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 <cstdio>
using namespace std;

int ball[10];
bool dfs(int point, int right, int left){
	if(point == 10) return true;
	if(right < ball[point]) return dfs(point + 1, ball[point], left);
	if(left < ball[point]) return dfs(point + 1, right, ball[point]);
	return false;
}
int main(){
	int N;
	scanf("%d", &N);
	while(N){
		for(int i = 0; i < 10; i++){
			scanf("%d", &ball[i]);
		}
		if(dfs(0, 0, 0)) printf("YES\n");
		else printf("NO\n");
		N--;
	}
}

C++: #include <iostream>
int a[15];
bool dfs(int prev_b , int prev_c , int p){
    if(p == 10){
        return true;
    }
    bool tf = false;
    if(a[p] > prev_b){
        tf = dfs(a[p] , prev_c , p + 1);
    }
    if(tf){
        return true;
    }
    if(a[p] > prev_c){
        tf = dfs(prev_b , a[p] , p + 1);
    }
    return tf;
}
int main(){
    int n;
    std::cin >> n;
    while(n--){
        for(int i = 0;i < 10;i++){
            std::cin >> a[i];
        }
        if(dfs(-1 , -1 , 0)){
            std::cout << "YES\n";
        }else{
            std::cout << "NO\n";
        }
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;

int n, k, b = 0, c = 0;
stack<int> sb, sc;

int main(){
	sb.push(0);
	sc.push(0);
	cin >> n;
	REP(i, n){
		REP(j, 10){
			cin >> k;
			if (b == 0){
				sb.push(k);
				b++;
				/*cout << sb.top() << ":" << b << " "
					<< sc.top() << ":" << c << "\n";*/
			}
			else if (c == 0){
				sc.push(k);
				if (sb.top() < k){
					sc.push(sb.top());
					sb.push(k);
				}
				c++;
				/*cout << sb.top() << ":" << b << " "
					<< sc.top() << ":" << c << "\n";*/
			}
			else{
				if (sb.top() < k){
					sb.push(k);
					b++;
				}
				else if (sc.top() < k){
					sc.push(k);
					c++;
				}
				/*cout << sb.top() << ":" << b << " "
					<< sc.top() << ":" << c << "\n";*/
			}
		}
		if (b + c == 10){
			cout << "YES\n";
		}
		else{
			cout << "NO\n";
		}
		sb.push(0);
		sc.push(0);
		b = 0;
		c = 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 if (i != 9){
				std::cout << "NO" << std::endl;
				break;
			}
			else{
				std::cout << "YES" << std::endl;
				break;
			}
		}
		n--;
	}
	return 0;
}