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 <cstdio>
#include <vector>
#include <climits>
using namespace std;
int b = INT_MIN, c = INT_MIN;
bool push(int ball) {
    if(ball > b) b = ball;
    else if (ball > c) c = ball;
    else return(false);
    return(true);
}

int main(void) {
    int num, ans = 0; cin >> num;
    for(int r = 0; r < num; r++) {
        for(int c = 0; c < 10; c++) {
            int input; cin >> input;
            if(!push(input)) ans--;
        }
        if(ans == 0) cout << "YES" << endl;
        else if(ans < 0) cout << "NO" << endl;
    }
    return(0);
}

C++: #include <iostream>
using namespace std;
int main(){
  int b[111],c[111];
  int i,j;
  int a,n;
  int w=0,q=0;
  int x=0,y=0;
  cin >> n;
  for(i=0;i<n;i++){
    for(j=0;j<10;j++){
      cin >> a;
      if(j%2==0){
	b[x]=a;
	if(x==0){
	  x++;
	  continue;
	}
	if(b[x]>b[x-1]){
	  w++;
	}
	x++;
      }
      else{
	c[y]=a;
	if(y==0){
	  y++;
	  continue;
	}
	if(c[y]>c[y-1]){
	  q++;
	}
	y++;
      }
    }
    if(w>=4 && q>=4){
      cout << "YES" << endl;
    }
    else{
      cout << "NO" << endl;
    }
    w=0;
    q=0;
    x=0;
    y=0;
  }
}

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

int x[15],lside[15],rside[15];
int n,kase;

void dfs(int i,int l,int r){
	if(i > 10){
		kase = 1;
		return ;	
	}
	if(kase)	return ;
	if(x[i]>lside[l]){
		lside[l+1] = x[i];
		dfs(i+1,l+1,r);
	}
	if(x[i]>rside[r]){
		rside[r+1] = x[i];
		dfs(i+1,l,r+1);
	}
}
int main(void){
	cin>>n;
	while(n--){
		for(int i=1;i<=10;i++)
			cin>>x[i];
		kase = 0;
		dfs(1,0,0);
		if(kase)	printf("YES\n");
		else	printf("NO\n");
	}
	return 0;
}

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

int n;
int a[10];


bool dfs(int i, int r, int l) {
    if (i == 9) return a[i] > r || a[i] > l;
    if ( dfs(i+1, a[i+1], l)) return true;
    if ( dfs(i+1, r, a[i+1])) return true;
    return false;
}

void solve() {
    if (dfs(0,a[0],a[0])) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> a[j];
        }
        solve();
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;

int n, k;
stack<int> sb, sc;
bool f = 1;

int main(){
	cin >> n;
	REP(i, n){
		REP(j, 10){
			cin >> k;
			if (sb.empty()){
				sb.push(k);
			}
			else if (sc.empty()){
				sc.push(k);
				if (sb.top() < k){
					sc.pop();
					sc.push(sb.top());
					sb.pop();
					sb.push(k);
				}
			}
			else{
				if (sb.top() < k){
					sb.push(k);
				}
				else if (sc.top() < k){
					sc.push(k);
				}
				else{
					f = 0;
				}
			}
		}
		cout << sb.size() << sc.size() << endl;
		if (f){
			cout << "YES\n";
		}
		else{
			cout << "NO\n";
		}
		while (!sb.empty()){
			sb.pop();
		}
		while (!sc.empty()){
			sc.pop();
		}
		f = 1;
		cout << sb.size() << sc.size() << endl;
	}
}

C++: /*
* Filename:    aoj0033.cpp
* Desciption:  DFS
* Created:     2016-03-02
* Author:      JIngwei Xu [mail:xu_jingwei@outlook.com]
*
*/
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#define INT_MAX 2<<30
using namespace std;
//typedef long long ll;
int a[10],n;
int used[10];
bool ans=false;
bool check(){
	int ss=0;
	for (int i = 0; i < 10; i += 1)
	{
		if(used[i]==0){ss=a[i];break;}
	}
	if(ss==0)return true;
	for (int i = 0; i < 10; i += 1)
	{
		if(used[i]==0){
			if(a[i]<ss)return false;
			else ss=a[i];
		}
	}
	return true;
}
void dfs(int k,int rec){
	if(k==10){
		if(check())ans=true;
		return;
	}
	if(ans)return;
	if(a[k]>rec){
		used[k]=1;
		dfs(k+1,a[k]);
		used[k]=0;
		dfs(k+1,rec);
		if(ans)return;
	}
	else{
		used[k]=0;
		dfs(k+1,rec);
	}
}

int main()
{
	scanf("%d",&n);
	for (int i = 0; i < n; i += 1)
	{
		for (int j = 0; j < 10; j += 1)
		{
			scanf("%d",&a[j]);
		}
		memset(used,0,sizeof(used));
		ans=false;
		used[0]=1;
		dfs(1,a[0]);
		if(ans)printf("YES");
		else printf("NO");
		
	}
	return 0;
}

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

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-10;

double zero(double d) {
    return d < EPS ? 0.0 : d;
}

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    rep(i, a.size()) os << (i ? " " : "") << a[i];
    return os << ']';
}

// to avoid error on mingw
string toString(int i) {
    stringstream ss;
    ss << i;
    return ss.str();
}

const int M = 1000000007;
// a^k
ll fpow(ll a, ll k, int M) {
    ll res = 1ll;
    ll x = a;
    while (k != 0) {
        if ((k & 1) == 1)
            res = (res * x) % M;
        x = (x * x) % M;
        k >>= 1;
    }
    return res;
}

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(8);
    ios_base::sync_with_stdio(false);

    int N;
    cin >> N;

    while(N--) {
        int a[10];
        rep(i, 10)
            cin >> a[i];

        bool probEnd = false;
        rep(i, 2<<10) {
            int left = 0, right = 0;
            bool failed = false;

            rep(j,10) {
                bool isRight = ( (i>>j) & 0x1 );
                if(isRight) {
                    if(right > a[j]) {
                        failed = true;
                        break;
                    }
                    right = a[j];
                }
                else {
                    if(left > a[j]) {
                        failed = true;
                        break;
                    }
                    left = a[j];
                }
            }

            if(!failed) {
                cout << "YES" << endl;
                probEnd = true;
                break;
            }
        }

        if(!probEnd)
            cout << "NO" << endl;
    }

    return 0;
}