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

int main() {
	int n, x, z;
	cin >> n;

	for (int i = 0; i < n; i++) {
		vector< vector<int> > v{ {0} };
		for (int j = 0; j < 10; j++) {
			cin >> x;
			z = v.size();
			for (int k = 0; k < z; k++) {
				if (v[k].back() < x) {
					v[k].push_back(x);
					break;
				}

				if (k == z - 1) {
					v.push_back({ x });
					break;
				}
			}

			if (v.size() == 3) {
				x = -1;
				break;
			}
		}

		if (x == -1) {
			cout << "NO";
		}
		else {
			cout << "YES";
		}
		cout << endl;
	}
	return 0;
}

C++: #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <ostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define INF 1000000000
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define rev(i,a,b) for (int i=(a)-1;i>=b;i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef queue<int> qi;
typedef queue< pair<int, int> > qpii;
typedef vector<int> vi;
typedef vector<int, int> vii;
typedef vector<string> vs;
typedef vector< pair<int, int> > vpii;
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

int n[10];
int h, w;
int b,c;

bool dfs(int cnt) {
  if(cnt == 10) return true;
  if(n[cnt] > n[b]) {
    int tmp = b;
    b = cnt;
    if(dfs(cnt+1)) return true;
    b = tmp;
  }
  if(n[cnt] > n[c]) {
    int tmp = c;
    c = cnt;
    if(dfs(cnt+1)) return true;
    c = tmp;
  }
  return false;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

  int num;
  cin >> num;
  rep(i,0,num) {
    rep(j,0,10) cin >> n[j];
    b = 0;
    c = 1;

    if(dfs(2)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }

	return 0;
}

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

int ball[10];
int b,c;

//ball[m]?????\????????±b,c???????????????ball???????????????left,right
bool dfs(int m,int left, int right){
    if(m==10) return true;
    if(ball[m]>left){
        if(dfs(m+1,ball[m],right)) return true;
    }
    if(ball[m]>right){
        if(dfs(m+1,left,ball[m])) return true;
    }
    return false;
}

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

int main(){
    int n;cin>>n;
    for(int i=0;i<2;i++){
        solve();
    }
    return 0;
}

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

using namespace std;

int nums[10];

bool check_recursion(int i, int left, int right){
	if(i == 10) return true;
	if(nums[i] > left) check_recursion(i+1, nums[i], right);
	if(nums[i] > right) check_recursion(i+1, left, nums[i]);
	
	return false;
}

int main(){
	int n;
	bool ans;
	cin>>n;

	for(;n>0;n--){
		 scanf("%d %d %d %d %d %d %d %d %d %d",&nums[0],&nums[1],&nums[2],&nums[3],&nums[4],&nums[5],&nums[6],&nums[7],&nums[8],&nums[9]);
		 ans = check_recursion(0,0,0);

	}
	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{
						right = input;
					}
				//}
				//どっちにも入る場合
				/*
				else{
					//先に入ってる数字が大きい方に入れる
					if(left > right){
						left = input;
					}
					else{
						right = input;
					}
				}*/
			}
		}
		cout << (achieve ? "YES" : "NO") << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {

	int a=0, b=0, i, N, x[10], end=0;

	cin >> N;
	for(; N!=0; N--) {
		for(i=0; i<10; i++)
			cin >> x[i];
		for(i=0; i<10; i++) {
			if(a>x[i]&&b>x[i]) {
				end++;
				break;
			}
			if(a>x[i]) {
				if(b<x[i])
					b=x[i];
			}
			else {
				if(b>x[i])
					a=x[i];
				else
					a>b ? a : b =x[i];
			}
		}

		if (end!=0)
			cout << "NO" << endl;
		else
			cout << "YES" << endl;
		end=0;
	}

	return 0;

}

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

int B, C, num[20], b, c;

string dfs(int x){
  if(x == 10) return "YES";
  else if(B>num[x]){
    if(C<num[x]){
      C = num[x];
      return dfs(x+1);
    }
    else return "NO";
  }
  else{
    B = num[x];
    return dfs(x+1);
  }
}

int main(void){
  int N;
  while(cin >> N){
  B = 0;
  C = 0;
  for(int i=0; i<10; i++){
    cin >> num[i];
  }
  string str = dfs(0);
  cout << str << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main(void)
{
	int n;

	cin >> n;
	while (n-- != 0)
	{
		int A[10] = {}, B[10] = {}, C[10] = {}, countb = 0, countc = 0;
		bool f = true;
		for (int i = 0; i < 10; i++)
		{
			cin >> A[i];
		}
		B[countb++] = A[0];
		for (int i = 1; i < 10; i++)
		{
			if (B[countb - 1] < A[i]) B[countb++] = A[i];
			else if (countc == 0) C[countc++] = A[i];
			else if (B[countb - 1] > A[i] && C[countc - 1] < A[i]) C[countc++] = A[i];
			else f = false;
		}
		//for (int i = 0; i < sizeof(B) / sizeof(*B); i++) cout << "B" << i << " =" <<B[i] << endl;
		//for (int i = 0; i < sizeof(C) / sizeof(*C); i++) cout << "C" << i << "=" << C[i] << endl;
		if (f == true) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

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

using namespace std;

int n;
int x[10];
int dp[11][11][11];

string solve(){
  fill_n((int*)dp, 11 * 11 * 11, 0);
  dp[0][0][0] = 1;
  for(int i = 1; i <= 10; ++i){
    int v = x[i - 1];
    rep(j, 11){
      rep(k, v){
        dp[i][j][v] += dp[i - 1][j][k];
      }
    }
    rep(k, 11){
      rep(j, v){
        dp[i][v][k] += dp[i - 1][j][k];
      }
    }
  }
  rep(j, 11){
    rep(k, 11){
      if(dp[10][j][k]){
        return "YES";
      }
    }
  }
  return "NO";
}

int main(){
  cin >> n;
  rep(i, n){
    rep(j, 10){
      cin >> x[j];
    }
    cout << solve() << endl;
  }
  return 0;
}