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 <cstdio>


int balls[12];

bool DFS(int cur,int left,int right){
    if (cur > 10) return true;
    auto val=balls[cur];
    return (val>left&&DFS(cur+1,val,right))||(val>right&&DFS(cur+1,left,val));
}

int main(){

    int N;
    scanf("%d",&N);

    for(int i=0;i<N;i++){
        for(int i=1;i<=10;i++) scanf("%d",balls+i);
        if (DFS(1,0,0)) puts("YES");
        else puts("NO");
    }

    return 0;
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  REP(t,N){
	int a[10]; REP(i,10) cin >> a[i];
	bool flag = true;
	for(int d=0;d<=1;++d)
	  for(int i=2;i<10;i+=2)
		if(a[i-2+d] >= a[i+d]) flag = false;
	cout << (flag? "YES": "NO") << endl;
  }
  
  return 0;
}

C++: #include<iostream>
using namespace std;
int n, cnt, G[15], L[15];
int main()
{
    cin >> n;
    for(int w = 0; w < n; w++)
    {
        cnt = 0;
        for(int i = 0; i < 15; i++) L[i] = 15;
        for(int i = 1; i <= 10; i++)
        {
            cin >> G[i];
            if(G[i] <= L[cnt]) L[++cnt] = G[i];
            else
            {
                for(int j = cnt - 1; j >= 0; j--)
                    if(G[i] < L[j]) {L[j + 1] = G[i]; break;}
            }
        }
        cout << (cnt > 2 ? "NO" : "YES") << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
#define NUM 10
int main(){
  int n;
  int ball[NUM];
  int b[NUM];
  cin>>n;
  for(int c=0;c<n;c++){
    for(int i=0;i<NUM;i++){
      cin>>ball[i];
      b[i]=-1;
    }
    int x=0;
    for(int j=0;j<NUM-1;j++){
      int t=ball[j];
      while(j<NUM-1 && t>=ball[j+1]){
	b[x]=ball[j+1];
	x++;
	j++;
      }
    }
    int f=true;
    for(int j=1;j<NUM && b[j]>0;j++){
      if(b[j]<=b[j-1]){
        f=false;
	break;
      }
    }
    if(f)
      cout<<"YES"<<endl;
    else
      cout<<"NO"<<endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
 
using namespace std;
 
#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
 
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;
 
int N;
vector<int>a;
 
int dfs(int n, int b, int c){
  if(n == 10) return 1;
 
  if(b < a[n] && dfs(n+1, a[n], c)) return 1;
  if(c < a[n] && dfs(n+1, b, a[n])) return 1;
  return 0;
}
 
int main(){
  scanf("%d", &N);
  rep(i, N){
    a.clear();
    int b;
    rep(i, 10){
      scanf("%d", &b);
      a.PB(b);
    }
 
    printf("%s\n", dfs(0, 0, 0)?"YES":"NO");
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int a[10];

bool dfs(int d, int left, int right) {
    if (d == 10) {
        return true;
    }
    if (a[d] > left) {
        return dfs(d + 1, a[d], right);
    }
    if (a[d] > right) {
        return dfs(d + 1, left, a[d]);
    }
    return false;
}

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

    return 0;
}

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

int main(){
  int n;
  cin>>n;
  for(int k=0;k<n;k++){
    vector<int> a(10);
    for(int i=0;i<10;i++)cin>>a[i];
    int x=a[0];
    int y=0;
    int fl=1;
    for(int i=1;i<10;i++){
      if(x>a[i]&&y>a[i]){
        fl=0;
        cout<<"NO"<<endl;
        break;
      }
      if(x>=y){
        if(x<a[i]){
          x=a[i];
        }else{
          y=a[i];
        }
      }else{
        if(y<a[i]){
          y=a[i];
        }else{
          x=a[i];
        }
      }
    }
    if(fl)cout<<"YES"<<endl;
  }
}

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

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

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

		int f = 0;
		for (int i = 0; i < 10; i++) {
			int x;
			cin >> x;

			if (!i) {
				a = x;
			}
			else {
				if (x > a) {
					a = x;
				}
				else {
					if (!b) {
						b = x;
					}
					else if (x>b) {
						b = x;
					}
					else {
						f = 1;
					}
				}
			}
		}

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

C++: #include <bits/stdc++.h>

using namespace std;

vector<int> a;
stack<int> b, c;

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

	bool res1 = false, res2 = false;

	if (b.empty()) {
		b.push(a[i]);
		res1 = dfs(i + 1);
		b.pop();
	} else if(c.empty()) {
		c.push(a[i]);
		res2 = dfs(i + 1);
		c.pop();
	} else {
		if (b.top() < a[i]) {
			b.push(a[i]);
			res1 = dfs(i + 1);
			b.pop();
		}
		if (c.top() < a[i]) {
			c.push(a[i]);
			res2 = dfs(i + 1);
			c.pop();
		}
	}

	return res1 || res2;
}

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

	while (n--) {
		a.clear();
		while (b.size()) b.pop();
		while (c.size()) c.pop();

		for (int i = 0; i < 10; ++i) { int v; cin >> v; a.push_back(v); }

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