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

int main(){
  int n;
  
  cin >> n;
  for(int j = 0 ; j < n ; j++){ 

    int ball[10]={0},left[5]={0},right[5]={0};
    int lmax=0,rmax=0,lcnt=0,rcnt=0,lc=0,rc=0;
    
    for( int i = 0 ; i < 10 ; i++ ){
      cin >> ball[i];
      
      if(i % 2 == 0) left[lc++] = ball[i];
      else right[rc++] = ball[i];
      
      if( lmax < left[lc-1] ){
	lmax = left[lc-1];
	lcnt++;
      }   
      
      if( rmax < right[rc-1] ){
	rmax = right[rc-1];
	rcnt++;
      }
     
    }
    if( lcnt == 5 && rcnt == 5 ) cout << "YES" << endl;
    else cout << "NO" << endl;
  } 
  return 0;
}

C++: #include<iostream>
#include<queue>
using namespace std;
int main (){
	int n;
	cin>>n;
	queue <int > p,q;
	int a[10];
	while(n--){
		for (int i=0;i<10;i++){
			cin>>a[i];
			if(!i) p.push(a[i]);
			if(a[i]<p.back()) q.push(a[i]);
			else p.push(a[i]);
		}
		int t=q.front(),k=0;
		q.pop();
		while(!q.empty()){
			if(t>q.front()){
				k=1;
				break;
			}else {
				q.pop();
			}
		}
		if(k) cout<<"NO"<<endl;
		else cout<<"YES"<<endl; 
	}
}

C++: #include <cstdio>

using namespace std;
#define INF 1000000000

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

  for (int i = 0; i < N; ++i) {
    int B = 0, C = 0;
    bool ans = true;
    for (int j = 0; j < 10; ++j) {
      int A;
      scanf("%d", &A);
      int diffB = INF, diffC = INF;
      if (A > B) diffB = A - B;
      if (A > C) diffC = A - C;
      if (diffB == INF && diffC == INF) ans = false;
      if (diffB < diffC) B = A;
      else C = A;
    }
    if (ans) puts("YES");
    else puts("NO");
  }
}

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

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); i++)
#define loops(i,f,n) for(int i = (f); i < (n); i++)
#define INF 100000000
typedef pair<int, int> pii;

vector<int> A(10);
bool ans = false;
void dfs(int a, int b, int cnt)
{
	if (cnt == 9)
	{
		if (a < A[cnt])ans = true;
		if (b < A[cnt])ans = true;
		return;
	}
	if (A[cnt] > a)dfs(A[cnt], b, cnt + 1);
	if (A[cnt] > b)dfs(a, A[cnt], cnt + 1);
	if (A[cnt] < a && A[cnt] < b)return;
}

int main()
{
	int n;
	cin >> n;
	loop(k, n)
	{
		loop(i, 10)
		{
			cin >> A[i];
		}
		ans = false;
		dfs(0, 0, 0);
		cout << (ans ? "YES" : "NO") << endl;
	}
	return 0;
}

C++: //
//  main.cpp
//

#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
#include <limits>
#include <math.h>
#include <queue>
#include <tuple>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <memory>

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0033

using namespace std;

// #define TEST

#ifdef TEST
static const string g_SAMPLE = R"(2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 11)";
static FILE* g_IN_FP;
static const char* g_IN_FN = "in.txt";
#define scanf(...) fscanf(g_IN_FP, __VA_ARGS__)
#endif // TEST

int main() {
#ifdef TEST
    g_IN_FP = fopen(g_IN_FN, "w");
    fwrite(g_SAMPLE.c_str(), 1, g_SAMPLE.size(), g_IN_FP);
    fclose(g_IN_FP);
    g_IN_FP = fopen(g_IN_FN, "r");
#endif // TEST
    int N;
    scanf("%d", &N);
    for (int n = 0; n < N; n++) {
        vector<int> balls;
        for (int i = 0; i < 10; i++) {
            int ball;
            scanf("%d", &ball);
            balls.push_back(ball);
        }
        bool foundGoodBits = false;
        for (int bits = 0; bits < (1 << 10); bits++) {
            if (bits > (~bits & ((1 << 10) - 1))) {
                continue;
            }
            function<bool(int)> isGoodBits = [&balls](int bits) -> bool {
                int zeroTop = 0;
                int oneTop = 0;
                for (int bit = 0; bit < 10; bit++) {
                    int* topPtr = (bits & (1 << bit)) != 0 ? &oneTop : &zeroTop;
                    if (balls[bit] <= *topPtr) {
                        return false;
                    } else {
                        *topPtr = balls[bit];
                    }
                }
                return true;
            };
            if (isGoodBits(bits)) {
                foundGoodBits = true;
                break;
            }
        }
        if (foundGoodBits) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <climits>
using namespace std;
int b = INT_MIN, c = INT_MIN;
bool push(vector<int> ball) {
    vector<int>::iterator ite;
    for(ite = ball.begin(); ite != ball.end(); ite++) {
        if(*ite > b) b = *ite;
        else if (*ite > c) c = *ite;
        else return(false);
    }
    return(true);
}

int main(void) {
    int num; cin >> num;
    for(int r = 0; r < num; r++) {
        vector<int> vec;
        for(int c = 0; c < 10; c++) {
            int input; cin >> input;
            vec.push_back(input);
        }
        if(push(vec)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return(0);
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <cstring>
#include <string>
#include <sstream>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

vector<int> in(10);
string res;

void dfs(int, int, int);

int main(void){
    int n; cin >> n;
    while(n --){
        res = "NO";
        rep(i, 10) cin >> in[i];

        dfs(0, 0, 0);
        cout << res << endl;
    }

    return 0;
}

void dfs(int left, int right, int cur){
    if(cur == in.size()) res = "YES";
    if(res == "YES") return;

    if(left < in[cur]) dfs(in[cur], right, cur + 1);
    if(right < in[cur]) dfs(left, in[cur], cur + 1);
}