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 <stack>
using namespace std;

bool solve(int ball[10]){
  stack<int> b, c;
  b.push(ball[0]);
  c.push(0);
  for(int i = 1; i < 10; i++){
    if(ball[i] < b.top() && ball[i] < c.top()) return false;
    if(b.top() > c.top()){
      if(ball[i] > b.top()) b.push(ball[i]);
      else c.push(ball[i]);
    }
    else{
      if(ball[i] > c.top()) c.push(ball[i]);
      else b.push(ball[i]);
    }
  }
  return true;
}

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

  int ball[10];
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 10; j++){
      cin >> ball[j];
    }
    if(solve(ball)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int n;

	cin >> n;

	while(n--){
		int input = 0;
		int left = 0, right = 0;
		bool achieve = true;
		REP(i, 10){
			cin >> input;

			if(left >= input && right >= input){
				//両方入らなかったら
				achieve = false;
				break;
			}
			else{
				//どっちかにしか入らない場合
				if(left >= input || right >= input){
					//入る方探して入れる
					if(input > left){
						left = input;
					}
					else if(input > right){
						right = input;
					}
				}
				//どっちにも入る場合
				else{
					//先に入ってる数字が大きい方に入れる
					if(left > right){
						left = input;
					}
					else{
						right = input;
					}
				}
			}
		}
		cout << (achieve ? "YES" : "NO") << endl;
	}
	return 0;
}

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

int main() {
	int a, n, j;
	bool d;
	vector<int> b, c;

	cin >> n;
	for (int i = 0; i < n; i++) {
		for (j = 0; j < 11; j++) {
			if (j == 10) {
				break;
			}
			cin >> a;
			if (j == 0) {
				b.push_back(a);
			}
			else if (a - 1 != b[b.size() - 1] && c.size() == 0) {
				c.push_back(a);
			}
			else if (a - 1 == b[b.size() - 1]) {
				b.push_back(a);
			}
			else if (a - 1 == c[c.size() - 1]) {
				c.push_back(a);
			}
			else {
				break;
			}
		}
		if (j == 10) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}

C++: #include <iostream>

using namespace std;

int N;
int a[10];

bool dfs(int left, int right, int next)
{
	if(next >= 10) return true;
	
	bool ret1 = false, ret2 = false;
	if(left < a[next]) ret1 = dfs(a[next], right, next+1);
	if(right < a[next]) ret2 = dfs(left, a[next], next+1);
	
	return ret1 || ret2;
}

int main(void)
{
	cin >> N;
	for(int i = 0; i < N; i++){
		
		for(int j = 0; j < 10; j++) cin >> a[j];
		bool ans = dfs(0, 0, 0);
		
		if(ans) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	
	return 0;
}

C++: /*
AOJ 0033 Ball

?¢???????????§??????????????????¢???????§???§?\?????????????A??£?????\???????????????????????????????????????DE?????¶??????B?£???????C?£??????????
??°??????1-10??????????????????????????????A??£?????\???????????????????§???§??¶??????????????\?????\???B?£???????C?£???????????????????????????????????¢????

?????\????¬¬???????????\??°????????°N?????\?????\N??????N???????????°??????????????°?????????10?????´??°?????£??¨???????????\?????????

???????????????????????°????????\?????\?????¨?????????YES?????\????????¨?????????NO
 */
#include <assert.h>
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

#include <algorithm>
#include <complex>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define SZ(a) (int)(a).size()
#define FOR(i,a,b) for (int i=(a); i<=(b); ++i)
#define REP(i,n) for (int i=0; i<(n); ++i)
#define ALL(c) c.begin(), c.end()
#define CLR(c,n) memset(c, n, sizeof(c))
#define TR(it, c) for(typeof(c.begin()) it = c.begin();it != c.end(); ++it)
#define CONTAIN(it, c) (c.find(it) != c.end())
typedef vector<int> VI;
typedef pair<int, int> PII;
template <class T> void checkmin(T &a, T b) { if (b<a) a=b; }
template <class T> void checkmax(T &a, T b) { if (b>a) a=b; }

const int N = 10;
int x[N];

bool go(int idx, int l1, int l2) {
  if (idx == N) return true;
  return (x[idx] > l1 && go(idx+1, x[idx], l2)) ||
      (x[idx] > l2 && go(idx+1, l1, x[idx]));
}

int main(int argc, char *argv[]) {
  int n;
  for (scanf("%d", &n); n; --n) {
    REP(i, 10) scanf("%d", &x[i]);
    puts(go(0, 0, 0)? "YES" : "NO");
  }
}

C++: /*
 * AOJ 0033: Ball
 * ?¢????????????????1-10???10???????????????????????????????????\2????????????????????????????????\??????????????????????¢????????????????????????¨???
 * ?±???????DFS
 * ?????????????????????????????\??§???????????¶???????´????????????\??°?????\????????¶??§????????????
 */

#include <cstdio>
#include <iostream>

using namespace std;

int a[10], b[2][10];
int len[2];
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]) {
      while(len[i]>=10);
      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>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
int num[20];
bool dfs(int x, int left, int right)
{
    if(num[x] > left)
    {
        if(x == 9)
            return true;
        if(dfs(x + 1, num[x], right))
            return true;
        return false;
    }
    else if(num[x] > right)
    {
        if(x == 9)
            return true;
        if(dfs(x + 1, left, num[x]))
            return true;
        return false;
    }
    return false;
}
int main()
{
    int T, i;
    scanf("%d", &T);
    while(T--)
    {
        for(i = 0; i < 10; i++)
            scanf("%d", &num[i]);
        if(dfs(0, -1<<30, -1<<30))
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

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

using namespace std;
int a[15];
int dfs(int x, int y, int step)
{
    if( step == 11)
       return 1;
    if(x < a[step]) dfs(a[step], y, step+1);
    else if(y < a[step]) dfs(x, a[step], step+1);
  else
    return 0;
}
int main ()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        int i;
        for(i = 1;i <= 10;i++)
            scanf("%d", &a[i]);
        if(dfs(0, 0, 1))
            printf("YES\n");
        else
            printf("NO\n");
    }
}