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;

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

	for (int i = 0; i < n; i++) {
		vector<vector<int>> v{ {0} };
		for (int j = 0; j < 10; j++) {
			cin >> x;
			for (int k = 0; k < v.size(); k++) {
				if (v[k].back() < x) {
					v[k].push_back(x);
					break;
				}

				if (k == v.size() - 1) {
					v.push_back({ x });
					break;
				}
			}

			if (v.size() == 3) {
				x = -1;
				break;
			}
		}
		if (x == -1) {
			cout << "NO";
		}
		else {
			cout << "YES";
		}
		cout << endl;
	}
	return 0;
}

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

int ball[MAX_BALL];
int n;
int r = 0, l = 0;
bool flag = 0;

void dfs(int x)
{
	if (x == MAX_BALL)
	{
		flag = true;
		return;
	}
	if (ball[x] >= r)
	{
		r = ball[x];
		dfs(x + 1);
	}
	if (ball[x] >= l)
	{
		l = ball[x];
		dfs(x + 1);
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		flag = false;
		r = 0;
		l = 0;
		for (int j = 0; j < MAX_BALL; j++)
			cin >> ball[j];
		dfs(0);
		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

C++: #include <cstdio>

#define N 10

int D, Ball[N];
int R, L;

bool solve(int i) {
	if(i == N) return true;
	if(R < Ball[i]) {
		R = Ball[i];
		if( solve(i+1) ) return true;
	}
	if(L < Ball[i]) {
		L = Ball[i];
		if( solve(i+1) ) return true;
	}
	return false;
}

int main() {
	scanf("%d", D);
	for(int i = 0; i < D; i++) {
		R = L = 0;
		for(int j = 0; j < N; j++) scanf("%d", &Ball[j]);
		R = Ball[0];
		if( solve(1) )	printf("YES\n");
		else			printf("NO\n");
	}
	return 0;
}

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

using namespace std;

int N;
const int LEN = 10;
int arr[LEN+1];
vector<int> bucket[2];

bool dfs(int n, int idx)
{
    if (n == LEN)
        return true;
    vector<int>& buc = bucket[idx];
    if (!buc.empty() && arr[n] < buc.back()) return false;
    buc.push_back(arr[n]);
    bool res[2];
    res[0] = dfs(n+1, 0);
    if (res[0]) goto finish;
    res[1] = dfs(n+1, 1);
finish:
    buc.erase(buc.end()-1);
    return res[0] || res[1];
}

int main()
{
    scanf("%d", &N);
    for (int j = 0; j < N; j++) {
        for (int i = 0; i < LEN; i++) {
            scanf("%d", &arr[i]);
        }
        if (dfs(0, 0) || dfs(0, 1)) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int ball;
	int n;
	while(cin >> n){
		bool flag = true;
		for(int i=0; i<n; i++){
			int B=0, C=0;
			for(int j=0; j<10; j++){
				cin >> ball;
				if(flag){
					if(B < ball) B=ball;
					else if(C < ball) C=ball;
					else flag=false;
				}
			}
			
			if(flag) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<vector>
#include<utility>
#include<queue>
#include<math.h>
#include<string>
#include<stack>
#include<typeinfo>
using namespace std;
typedef pair<int, int> P;
int main() {
	int n,ball[10],under;
	cin >> n;
	for (int data = 0; data < n; ++data) {
		for (int i = 0; i < 10; ++i) cin >> ball[i];
		under = ball[0];
		ball[0] = 0;
		for (int i = 1; i < 10; ++i) {
			if (under < ball[i]) {
				under = ball[i];
				ball[i] = 0;
			}
		}
		int k;
		for (k = 1; k < 10; ++k) {
			if (ball[k] == 0)continue;
			else {
				under = ball[k];
				ball[k] = 0;
				break;
			}
		}
		char bo = true;
		for (int i = k + 1; i < 10; ++i) {
			if (ball[i] == 0)continue;
			else if (under < ball[i]) {
				under = ball[i];
				ball[i] = 0;
			}
			else {
				bo = false;
				break;
			}
		}
		if (bo)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

int main() {
	int n;
	cin>>n;
	while (n--){
	bool yes=true;
		stack<int> s1;
		stack<int> s2;
		s1.push(0);
		s2.push(0);
		REP(i, 10){
			int a;
			cin >> a;
			if (s1.top() <= s2.top()){
				if (s1.top() < a)
					s1.push(a);
					continue;
			}
			if (s2.top() < a){
					s2.push(a);
					continue;
			}
			yes=false;

		}
		if (yes)
			cout << "YES"<<endl;
			else
				cout << "NO" << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <queue>
using namespace std;
int ball[10];
int dfs(int k,int B,int C)
{
    if(k == 9)
        return 1;
    if(ball[k] > B)
        return dfs(k + 1,ball[k],C);
    if(ball[k] > C)
        return dfs(k + 1,B,ball[k]);
    return 0;
}
int main(void)
{
    int n;
    cin>>n;
    while(n--){
        int i;
        queue<int> left,right;
        for(i = 0;i < 10;i++)
            cin>>ball[i];
        if(dfs(0,0,0))
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int ball[10];
		for(int i = 0; i < 10; i++)cin >> ball[i];
		int b = 0,c = 0;
		for(int i = 0; i < 10; i++){
			if(b > ball[i] && c > ball[i]){
				cout << "NO" << endl;
				goto no;
			}else if(b < ball[i] && c > ball[i])b = ball[i];
			else if(b > ball[i] && c < ball[i])c = ball[i];
			else if(b > c)b = ball[i];
			else c = ball[i];
		}
		cout << "YES" << endl;
		no:;
	}
}

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

int a[10],b[10],c[10];

void initial()
{
	for(int i=0;i<10;i++)
	{
		b[i]=-1;
        c[i]=-1;
	}
}
bool judge()
{
  int p=0,q=0,i;
  initial();
  b[0]=a[0];
  for(i=1;i<10;i++)
  {
	  if(a[i]>b[p])b[++p]=a[i];
	  else if(q==0)c[q++]=a[i];
	  else if(a[i]>c[q-1])c[q++]=a[i];
	  else 
	  {
		  return false;
		  break;
	  }
  }
  if(i==10)
	  return true;
}

int main()
{
	int num;
	cin>>num;
	while(num--)
	{
		for(int i=0;i<10;i++)
			cin>>a[i];
		puts(judge()?"YES":"NO");
	}
return 0;
}