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;

bool all_dropped_between(bool* dropped, int lower, int upper){
  if (lower == 0)
    return all_dropped_between(dropped, 1, upper);
  if (lower == upper - 1)
    return true;
  else
    return dropped[lower - 1] && all_dropped_between(dropped, lower + 1, upper);
}

int main(){
  int n;
  bool dropped[10];

  cin >> n;
  while(n--){
    for(int i=0; i<10; i++){
      dropped[i] = false;
    }

    int b = 0, c = 0;
    int a[10];
    for(int i=0; i<10; i++){
      cin >> a[i];
    }

    for(int i=0; i<10; i++){
      dropped[a[i] - 1] = true;

      if(b < a[i] && c < a[i]){
        if(b < c)
          c = a[i];
        else
          b = a[i];
      }
      else if(b < a[i]){
        if(!all_dropped_between(dropped, b, a[i])){
          cout << "NO" << endl;
          break;
        }
        else
          b = a[i];
      }
      else if(c < a[i]){
        if(!all_dropped_between(dropped, c, a[i])){
          cout << "NO" << endl;
          break;
        }
        else
          c = a[i];
      }

      if(i == 9)
        cout << "YES" << endl;
    }
  }
}

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

#include <string.h>

int a[10];

int memo[10][10+1][10+1];

int search(int i, int j, int k)
{
  if (memo[i][j][k] >= 0)
    return memo[i][j][k];
  
  if (i == 9)
    return memo[i][j][k] = a[i];

  int r = 0;

  if (a[i] > j)
    r = std::max(search(i + 1, a[i], k), r);
		 
  if (a[i] > k)
    r = std::max(search(i + 1, j, a[i]), r);
  
  return memo[i][j][k] = r;
}

int main(int argc, char** argv)
{
  int N;

  std::cin >> N;

  while (N --) {
    for (int i = 0; i < 10; i ++)
      std::cin >> a[i];

    memset(memo, -1, sizeof(memo));

    std::cout << (search(0, 0, 0) ? "YES" : "NO") << std::endl;
  }
}

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

int main() {
	int n;
	cin >> n;
	for ( int i = 0; i < n; i++ ){
		deque<int>b,c;
		bool endflag = false;
		int dummy;
		cin >> dummy;
		b.push_back( dummy );
		cin >> dummy;
		c.push_back( dummy );
		for ( int j = 0; j < 8; j++ ){
			cin >> dummy;
			if ( !endflag ) {
				if ( c.size() - 1 ) {
					if ( b[b.size() -1] > c[c.size() -1] ) {
						if ( dummy > b[b.size()-1] )	b.push_back( dummy );
						else if ( dummy > c[c.size()-1] )	c.push_back( dummy );
						else {
							cout << "NO" << endl;
							endflag = true;
						}
					} else {
						if ( dummy > c[c.size()-1] )	c.push_back( dummy );
						else if ( dummy > b[b.size()-1] )	b.push_back( dummy );
						else {
							cout << "NO" << endl;
							endflag = true;
						}
					}
				} else {
					if ( dummy > b[b.size()-1] )	b.push_back( dummy );
					else	c.push_back( dummy );
				}
			}
		}
		if( !endflag )	cout << "YES" << endl;
	}
	
	return 0;
}

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

using namespace std;

int main() {
	vector<int> left;
	vector<int> right;
	vector<int> all;

	bool flag = true;

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else
							flag = false;
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}

		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO"<<endl;
		flag = true;
	}

	return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main(){
  int N;
  cin >> N;
  int boll[10];
  stack<int> B,C;
  B.push(0); C.push(0);
  for(int i=0;i<N;i++){
    for(int j=0;j<10;j++) cin >> boll[j];
    for(int j=0;j<10;j++){
        if(boll[j]>B.top()) B.push(boll[j]);
        else if(boll[j]>C.top()) C.push(boll[j]);
        else{
          cout << "NO" << endl;
          break;
        }
        if(j==9) cout << "YES" << endl;
    }
  }
  return 0;
}

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

using namespace std;

int n;
int ball[10]; 
vector<int> l;
vector<int> r;

bool solve() {
    bool res = false;
    for (int i = 0; i < 1024; i++) {
        for (int j = 0; j < 10; j++) {
            if (i & (1 << j)) {
                l.push_back(ball[j]);
            }
            else {
                r.push_back(ball[j]);
            }
        }
        int lLen = l.size();
        int rLen = r.size();
        bool lOK = true;
        bool rOK = true;        
        for (int j = 0; j < lLen - 1; j++) {
            if (l.at(j) > l.at(j + 1)) {
                lOK = false;
                break;
            }
        }
        for (int j = 0; j < rLen - 1; j++) {
            if (r.at(j) > r.at(j + 1)) {
                rOK = false;
                break;
            }
        }
        if (lOK && rOK) {
            res = true;
            break;
        }
        l.clear();
        r.clear();        
    }
    return res;
}

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

C++: // 0033.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define roop(a,t) for(int a=0;a<t;a++) 
int a[10], n;
bool bit(int n,vector<int>left,vector<int>right) {
	if (n == 10) {
		bool left_f = true;
		bool left_r = true;
		roop(i, (int)left.size() - 1) { if (left[i + 1] <= left[i]) { return false; } }
		roop(i, (int)right.size() - 1) { if (right[i + 1] <= right[i]) { return false; } }
		return true;
	}
	if (left.size() > 0 && right.size() > 0) {
		if (left[left.size() - 1] > a[n] && right[right.size() - 1] > a[n]) { return false; }
	}
	vector<int>new_l = left;
	vector<int>new_r = right;
	
	new_l.push_back(a[n]);
	new_r.push_back(a[n]);
	return (bit(n + 1, new_l, right) || bit(n + 1, left, new_r));
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	vector<int>emptynow;
	roop(i, n) {
		roop(j, 10) {
			cin >> a[j];
		}
		if (bit(0, emptynow, emptynow)) { cout << "YES" << endl;}
		else { cout << "NO" << endl; }
	}
	return 0;
}