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 main() {
    int n; cin >> n;  
    while(n--){
        int balls[10] = {0};
        for(int i = 0; i < 10; i++){ cin >> balls[i]; }
        
        bool isYES = true;  
        int topB = 0, topC = 0; 
        for(int i = 0; i < 10; i++){
            if (topB < balls[i]){
                topB = balls[i];
            } else if (topC < balls[i]) {
                topC = balls[i];
            } else {
                isYES = false;
                break;
            }
        }
        cout << (isYES ? "YES" : "NO") << endl;
    }
}

C++: #include<iostream>
using namespace std;
bool solve(int, int, int);
int a[10];

int main(void){
	int n;
	char t;
	bool flag;
	cin >> n;
	do{
		n--;
		cin >> a[0];
		for(int i = 1; i < 10; i++){
			cin >> t >> a[i];
		}
		if(solve(0,0,0)){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}while(n != 0);
	return 0;
}

bool solve(int i, int b, int c){
	if(i == 9){
		if(a[i] > b || a[i] > c)
			return (true);
		return(false);
	}
		if(solve(i + 1, a[i], c) || solve(i + 1, b, a[i])){
			return (true);
		}
	return (false);
}

C++: #include<iostream>
using namespace std;
 
int data[10];
 
bool solve(int i, int a, int b){
 
  if(i == 10) return true;
 
  if(data[i] > a) return solve(i+1, data[i], b);
  if(data[i] > b) return solve(i+1, a, data[i]);
  
  return false;
}
 
int main(){
 
  int n;
 
  cin >> n;
  while(n--){
 
    for(int i=0;i<10;i++) cin >> data[i];
 
    cout << (solve(0, 0, 0)?"YES\n":"NO\n");
 
  }
 
}

C++: #include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in();
	LOOP(N){
		auto V=vecin(10);
		vector<int> B,C;
		bool success = true;
		REP(i,10){
			if(B.empty() || B.back()<V[i]){
				B.push_back(V[i]);
			}
			else if(C.empty() || C.back()<V[i]){
				C.push_back(V[i]);
			}
			else{
				success = false;
				break;
			}
		}

		out(success?"YES":"NO");
	}
	return 0;
}

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

int main() {
	int n1,n2,num,temp,flg=1;
	cin>>num;
	while(num--){
		cin>>n1; cin>>n2;
		for(int i=0;i<8;i++){
			cin>>temp;
			if(temp-n1<0&&temp-n2<0) flg=0;
			if(temp-n1>temp-n2) n2=temp;
			else if(temp-n2>temp-n1) n1=temp;
		}if(flg==1) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}return 0;
}

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

using namespace std;
 
 
int data[10];
 
bool searchB (int a){
    vector<int >sea;
 
    for(int i=0;i<10;i++){
        if(a>>i & 1)sea.push_back(data[i]);
    }
    if(sea.size()>1){
    for(int i=0;i<sea.size()-1;i++){
        if(sea[i]>sea[i+1])return false;
    }
    }
    return true;
}
 
int main(){
 
    int n=0;
    cin>>n;
 
    for(int i=0;i<n;i++){
         
 
    for(int j=0;j<10;j++){
        cin>>data[j];
    }
    bool suc=false;
    for(int i=0;i<1024;i++){
        if(searchB(i) && searchB(~i)){
            cout<<"YES"<<endl;
            suc=true;
            break;
        }
    }
    if(!suc)cout<<"NO"<<endl;
    }
    return 0;
}

C++: /*If I get TLE , it is good.If I get AC,it's NICE !*/
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int MAXN=1e7+10;
const ll mod=1e9+7;
using namespace std;
typedef long long ll;
int a[11];

bool judge()
{
    for(int i=2;i<=5;i++)
    {
        if(a[i]<a[i-1]) return false;
    }
    for(int i=7;i<=10;i++)
    {
        if(a[i]<a[i-1]) return false;
    }
    return true;
}

int main(void)
{
    int t;
    cin >> t;
    while(t--)
    {
        int flag=0;
        for(int i=1;i<=10;i++)
            scanf("%d",&a[i]);
        do
        {
            if(judge())
            {
                flag=1;
                break;
            }
        }while(next_permutation(a+1,a+1+10));
        if(flag)    printf("YES\n");
        else    printf("NO\n");
    }
}

C++: #include <iostream>

using namespace std;

bool recursive(int left, int right, int* list, int index)
{
	int next = list[index];

	if(index == 9)
	{
		if(next <= left && next <= right)
			return false;
		return true;
	}

	if(left < next)
		if(recursive(next, right, list, index+1))
			return true;
	if(right < next)
		if(recursive(left, next, list, index+1))
			return true;

	return false;
}

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

	while( n-- > 0 )
	{
		int list[10];
		for(auto& n : list)
			cin >> n;

		if( recursive(0, 0, list, 0) )
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}

	return 0;
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int a[10];
bool ok = false;

// これから入れるボールのindex，左の筒の一番上のボール，右の筒の一番上のボール
void dfs(int idx, int l, int r) {
  if (idx == 10) {
    ok = true;
    return;
  }
  int val = a[idx];
  if (l < val) dfs(idx + 1, val, r);  // 左の筒に入れる場合
  if (r < val) dfs(idx + 1, l, val);  // 右の筒に入れる場合
}

int main() {
  int n;
  cin >> n;
  REP(i, n) {
    REP(i, 10) cin >> a[i];
    ok = false;
    dfs(0, -1, -1);
    cout << (ok ? "YES" : "NO") << endl;
  }
  return 0;
}

C++: #include <cstdio>

using namespace std;

int a[10];

bool dfs(int i, int l, int r)
{
	if (i == 10) return true;

	if (l < a[i] && dfs(i + 1, a[i], r)) return true;
	if (r < a[i] && dfs(i + 1, l, a[i])) return true;

	return false;
}

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

	while (n--) {
        for (int i = 0; i < 10; ++i) scanf("%d", &a[i]);
        printf("%s\n", (dfs(0, 0, 0) ? "YES" : "NO"));
	}
}