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++: /*
 * AOJ 0033: Ball
 * ?¢????????????????1-10???10???????????????????????????????????\2????????????????????????????????\??????????????????????¢????????????????????????¨???
 * ?±???????DFS
 * ?????????????????????????????\??§???????????¶???????´????????????\??°?????\????????¶??§????????????
 */

#include <cstdio>
#include <iostream>

using namespace std;

int a[100], b[20][100];
int len[20];
bool ans;


void dfs(int step) {
  if (ans) return;
  if (step == 10) {
    ans = true;
    return;
  }
  for (int i = 0; i < 2; ++i) {
    if (len[i] == 0 || a[step] > b[i][len[i] - 1]) {
      b[i][len[i]++] = a[step];
      dfs(step + 1);
      --len[i];
    }
  }
}

void solve() {
  ans = false;
  for (int i = 0; i < 10; ++i) {
    cin >> a[i];
  }
  len[0] = len[1] = 0;
  dfs(0);
}

int main() {
  int T;
  cin >> T;
  while (T--) {
    solve();
    cout << (ans ? "YES" : "NO") << endl;
  }
  return 1;
}

C++: #include<iostream>
int main() {
	int n;
	std::cin >> n;
	for (int i = 0; i < n; i += 1) {
		int N[10];
		for (int i = 0; i < 10; i += 1) 
			std::cin >> N[i];
		if ((N[0] == 1 || N[1] == 1)&&(N[8]==10||N[9]==10))
			std::cout << "YES" << std::endl;
		else
			std::cout << "NO" << std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <stack>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int a[15];

int main()
{
	int n;
	cin >> n;
	while (n--) {
		for (int i = 0; i < 10; i++)	cin >> a[i];
		stack<int> s1, s2;
		s1.push(a[0]);
		
		bool flag = true;
		
		for (int i = 1; i < 10; i++) {
			if (s2.empty()) {
				if (s1.top() < a[i])	s1.push(a[i]);
				else	s2.push(a[i]);
			}
			else {
				if (s1.top() > a[i]) {
					if (s2.top() > a[i])	{
					   flag = false; break;
					}
					else	s2.push(a[i]);
				}
				else {
					if (s2.top() > a[i])	s1.push(a[i]);
					else {
						if (s1.top() > s2.top())	s1.push(a[i]);
						else	s2.push(a[i]);
					}
				}
			}
		}
		if (flag)	cout << "YES\n";
		else	cout << "NO\n";
	}
	return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int n;
int a[11];

void bitBruteForth() {
   bool printed = false;
   rep (mask, (1<<10)) {
      bool ok = true;
      int oldA = -1, oldB = -1;
      rep (j, 10) {
         if ((mask>>j)&1) {
            if (a[j] > oldA) {
               oldA = a[j];
            } else {
               ok = false;
            }
         } else {
            if (a[j] > oldB) {
               oldB = a[j];
            } else {
               ok = false;
            }
         }
      }
      if (ok) {
         puts("YES");
         printed = true;
         break;
      }
   }
   if (!printed) puts("NO");
}

bool ans;

void rec(int idx, int l, int r) {
   if (idx == 10) {
      ans = true;
      return;
   }

   int val = a[idx];
   if (l < val) rec(idx+1, val, r);
   if (r < val) rec(idx+1, l, val);
}

int main() {
   cin >> n;
   while (n--) {
      rep (i, 10) cin >> a[i];
      ans = false;
      rec(0, -1, -1);
      puts(ans?"YES":"NO");
   }

   return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
  bool f;
  int n, i, a, b, c;
  cin >> n;
  while (n--) {
    for (i = b = c = f = 0; i < 10; i++) {
      cin >> a;
      if (a > b) {
        b = a;
      } else if (a > c) {
        c = a;
      } else {
        f = 1;
      }
    }
    if (f)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}

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

main(){
    int n, B[10], P[2], b, s;
    cin >> n;
    for ( int t = 0; t < n; t++ ){
	for ( int i = 0; i < 10; i++ ) cin >> B[i];
	P[0] = P[1] = 0;
	bool p = true;
	for ( int i = 0; i < 10; i++ ){
	    if ( P[0] > P[1] ) { b = 0; s = 1; }
	    else { b = 1; s = 0;}
	    if ( B[i] > P[b] ) P[b] = B[i];
	    else if ( B[i] > P[s] ) P[s] = B[i];
	    else {p = false; break;}
	}
	if ( p ) cout << "YES" << endl;
	else cout << "NO" << endl;
    }
}

C++: #include <cstdio>

using namespace std;

int n;
int t[15], t1[15], t2[15];

bool yes;
void dfs(int n, int t1[], int num, int t2[])
{
    if(n == 10)
    {
        bool zen1=true, zen2 = true;
        for(int i=1; i<num; i++) if(t1[i]<t1[i-1]) zen1 = false;
        for(int i=1; i<10-num; i++) if(t2[i]<t2[i-1]) zen2 = false;
        if(zen1 && zen2) yes = true;
        return ;
    }
    t1[n+1] = t[n+1];
    dfs(n+1, t1, num+1, t2);
    t2[n+1] = t[n+1];
    dfs(n+1, t1, num, t2);
}

int main()
{
    scanf("%d", &n);
    while(n--)
    {
        for(int i=0; i<10; i++)
            scanf("%d", &t[i]);
        yes = false;
        dfs(0, t1, 0, t2);
        if(yes)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,a,b=0,c=0;
  int i,j;
  int flag=0;
  cin >> n;
  for(i=0;i<n;i++){
    for(j=0;j<10;j++){
      cin >> a;
      if(b<a){
	b=a;
      }
      else if(c<a){
	c=a;
      }
      else{
	flag=1;
      }
    }
    if(flag==0)cout << "YES" << endl;
    if(flag==1)cout << "NO" << endl;
    b=0,c=0;
    flag=0;
  }
}

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

int a[10];
bool flag;
vector< int > l;
vector< int > r;
void dfs(int dep)
{
	if (flag) return;
	if(dep == 10) {
		flag = true;
		return;
	}
	if (l.size() == 0 || l.back() < a[dep]) {
		l.push_back(a[dep]);	
		dfs(dep + 1);
	}
	if (r.size() == 0 || r.back() < a[dep]) {
		r.push_back(a[dep]);
		dfs(dep + 1);
	}
}
int main()
{
	int t;
	cin >> t;
	for (int cas = 0; cas < t; cas++) {
		for (int i = 0; i < 10; i++) { cin >> a[i]; }
		flag = false;
		dfs(0);
		if (flag) cout << "YES\n";
		else cout << "NO\n";
	}
	return 0;
}