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 <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cstdio>

using namespace std;



int main(){
	int n;

	cin >> n;
	while(n--){
		int a;
		bool f = true;
		vector<int> b, c; 
		for(int i = 0; i < 10; i++){
			cin >> a;
			if(f || b[b.size()-1] < a){
				b.push_back(a);
				f = false;
			}else{
				c.push_back(a);
			}
		}
		bool check = true;
		for(int i = 1; i < b.size() && check; i++){
			if(b[i] < b[i-1]){
				check = false;
			}
		}
		for(int i = 1; i < c.size() && check; i++){
			if(c[i] < c[i-1]){
				check = false;
			}
		}
		
		if(check){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int const MOD = 1000000007;

int main() {
    int n; cin >> n;
    int x;
    rep(k,0,n) {
        int a = 0, b = 0;
        bool can = true;
        rep(i,0,10) {
            cin >> x;
            if(a < x && b < x){
                if(x - a > x - b) b = x;
                else a = x;
            }
            else if(a < x) a = x;
            else if(b < x) b = x;
            else {can = false;}
        }
        if(can) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
    int N,pre,current,second_pre;
    bool NO_FLG;

    scanf("%d",&N);
    for(int i=0;i<N;i++){
        pre = -1;
        second_pre = -1;
        NO_FLG = false;
        for(int k = 0; k < 10; k++){
            scanf("%d",&current);	//????????????????????????
            if(pre > current){	//1?????????????????????????????§????????´???,current?????????1????????????????§????
				if(second_pre == -1){	//2?????????????????????????????¨?????????????????´???
					second_pre = current;
				}else{	//2???????????????????????¨??????????????´???
					if(second_pre > current){ //2????????????????????°??????current???????????§????????´???
						printf("NO\n");
						NO_FLG = true;
						break;
					}else{	//2????????????????????°??????current??????????°?????????´???
						second_pre = current;
					}
				}
			}else{ //pre < current
				pre = current;
			}
        }
        if(!NO_FLG)printf("YES\n");

    }
    return 0;
}

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

stack<int> B, C;
int A[10];

bool dfs(int index)
{
  bool ret = false;
  char s[11];

  if (index >= 10) {
    return true;
  }

  for (int i = 0; i < 11; i++) {
    if (i < index) s[i] = '>';
    else s[i] = 0;
  }

  if (B.empty() || B.top() < A[index]) {
    B.push(A[index]);
    // printf("%spush %d into B\n", s, A[index]);
    ret = dfs(index + 1);
    // printf("%s%s. pop %d from B\n", s, ret ? "succeeded" : "failed", A[index]);
    B.pop();
  }
  if (!ret && (C.empty() || C.top() < A[index])) {
    C.push(A[index]);
    // printf("%spush %d into C\n", s, A[index]);
    ret = dfs(index + 1);
    // printf("%s%s. pop %d from C\n", s, ret ? "succeeded" : "failed", A[index]);
    C.pop();
  }

  return ret;
}

bool solve()
{
  while (!B.empty()) B.pop();
  while (!C.empty()) C.pop();

  B.push(A[0]);
  bool ret = dfs(1);
  B.pop();

  return ret;
}

int main()
{
  int N;
  scor (int j = 0; j < 10; j++) {
      scanf("%d", A + j);
    }

    if (solve()) {
      printf("Yes\n");
    }
    else {
      printf("No\n");
    }
  }

  return 0;
}

C++: #include<iostream>
using namespace std;
int ball[10];
int flag;  //1??????YES???0??????NO
void dfs(int left,int right,int depth){
  if(depth==10){ //???????????????????????§??\???????????????
    flag=1;
    return;
  }
  if(left<ball[depth])
    dfs(ball[depth],right,depth+1);
  if(right<ball[depth])
    dfs(left,ball[depth],depth+1);
}

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    flag=0;//????????°????????????
    for(int j=0;j<10;j++)
      cin>>ball[j];
    dfs(ball[0],0,1);//????????????????????\??????????????????
                     //3??????????????°?????±???
                     //?????????????????\?????????????????\???????????????????????§
                     //????????\?????????????????????????????????
    if(flag)
      cout<<"YES"<<endl;
    else
      cout<<"NO"<<endl;
  }
  return 0;
}

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

int main() {
  int n; cin >> n;
  while (n--) {
    vector<int> a(10); for (int i = 0; i < 10; ++i) cin >> a[i];
    int sum = 0;
    for (int i = 1; i < 10; ++i) {
      sum += (a[i - 1] > a[i]);
    }
    cout << ( (sum < 3) ? "YES" : "NO" ) << endl;
  }
  return 0;
}

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

int main() {
	int a[10], n, j;
	vector<int> b, c;

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