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<cstdio>

int main(void){
	int n,i,j;
	int a[1024][10];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<10;j++){
			scanf("%d",&a[i][j]);
		}
	}
	
	for(i=0;i<n;i++){
		int b[10],c[10];
		b[0]=a[i][0];
		bool x=true;
		int k=0,l=0;
		for(j=1;j<10;j++){
			if(a[i][j]>b[k]){
				k++;
				b[k]=a[i][j];
			}else {
				c[l]=a[i][j];
				l++;
			}
		}

		for(j=0;j<l-2;j++){
			if (c[j]>c[j+1]){
				x=false;
			}
			//if(c[j]>c[j+1]) break;
		}
		if(x==true){
			printf("Yes\n");
		} else{
			printf("No\n");
		}	
	}
	return 0;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

bool
f(vector<int>&ln, int idx, int x, int y) {
  if (idx == 10) return true;
  int z = ln[idx];
  return (x < z && f(ln, idx + 1, z, y)) || (y < z && f(ln, idx + 1, y, z));
}

int main() {

  int n; cin >> n;
  for (;n--;) {
    vector<int> ln(10);
    rep (i, 10) cin >> ln[i];
    bool bl = f(ln, 0, 0, 0);
    cout << (bl ? "YES" : "NO" ) <<endl;
  }

  return 0;
}

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

using namespace std;

int ball_db[10];

void solve()
{
    vector<int> left;
    vector<int> right;

    left.push_back(0);
    right.push_back(0);

    for (int i = 0; i < 10; ++i) {
        if (ball_db[i] > left.back()) {
            left.push_back(ball_db[i]);
        } else if (ball_db[i] > right.back()) {
            right.push_back(ball_db[i]);
        } else {
            cout << "NO" << endl;
            return;
        }
    }

    if (left.size() + right.size() == 10 + 2) {
        cout << "YES" << endl;
    }
}

int main()
{
    int data_num;

    cin >> data_num;

    for (int i = 0; i < data_num; ++i) {
        for (int j = 0; j < 10; ++j) {
            cin >> ball_db[j];
        }
        solve();
    }


    return 0;
}

C++: #include<iostream>
using namespace std;
int r[10],l[10];
int data[10];

bool solve(int n,int rt,int lt)
{
	if(n==10)
	{
		for(int i = 1; i <= rt ; ++i)
		{
			if(r[i-1]>r[i]) return false;
		}
		for(int i = 1; i <= lt ; ++i)
		{
			if(l[i-1]>l[i]) return false;
		}
		return true;
	}

	r[rt]=data[n];
	if(solve(n+1,rt+1,lt)) return true;
	l[lt]=data[n];
	if(solve(n+1,rt,lt+1)) return true;

	return false;
}

int main()
{
	int n;
	cin>>n;
	while(n--)
	{
		for(int i = 0; i < 10; ++i)
		{
			cin>>data[i];
		}
		cout<<(solve(0,0,0)?"YES":"NO")<<endl;
	}
  return 0;
}

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

const int N = 10;
int a[N];
      
int main() {
  int Tc;
  cin >> Tc;
  while(Tc--) {
    for(int i = 0; i < N; ++i) cin >> a[i];
    string res = "NO";
    for(int b = 0; b < (1<<N); ++b) {
      int pre[2] = {-1,-1};
      for(int i = 0; i < N; ++i) {
	int t = ((b>>i)&1);
	if(pre[t] != -1 && pre[t] > a[i]) {
	  break;
	}
	pre[t] = a[i];
	if(i+1 == N) res = "YES";
      }
    }
    cout << res << endl;
  }
  return 0;
}

C++: include<cstdio>
include<iostream>
sing namespace std;
nt main()

   int T;
   scanf("%d",&T);
   while(T--)
   {
       int n1=0,n2=0,x,jd;
       for(int i=1;i<=10;++i)
       {
           scanf("%d",&x);
           if(x>n1){n1=x;continue;}
           if(x>n2){n2=x;continue;}
           jd=1;
       }
       if(jd) puts("NO");
       else   puts("YES");
   }

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

const int N = 15;
int arr[N];
bool flag;


void dfs(int left, int right, int cur){
    if (flag) return;

    if (cur == 10){
        flag = true;
        return;
    }

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

int main(){
    int t; cin >> t;
    while (t--){
        for (int i = 0; i < 10; ++ i) cin >> arr[i];
        flag = false;

        int left(0), right(0);

        dfs(left, right, 0);
        if (flag) cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}

C++: #include <iostream>
#include <string.h>

using namespace std;

int ball_list[10];
int right_list[10];
int left_list[10];

bool flag;

void dfs(int right, int left){
  int count = right + left;

  if(count == 10){
    flag = true;
  }else{
    if(right == 0 || right_list[right-1] < ball_list[count]){
      if(right == 0){
        right_list[0] = ball_list[count];
      }else{
        right_list[right-1] = ball_list[count];
      }
      dfs(right+1, left);
    }
    if(left == 0 || left_list[left-1] < left_list[left]){
      if(left == 0){
        left_list[0] = ball_list[count];
      }else{
        left_list[left-1] = ball_list[count];
      }
      dfs(right, left+1);
    }
  }
}

int main(){
  int n;

  cin >> n;

  for(int i = 0; i < n; i++){
    flag = false;
    memset(right_list, 0, sizeof(right_list));
    memset(left_list, 0, sizeof(left_list));

    for(int j = 0; j < 10; j++){
      cin >> ball_list[j];
    }
    
    dfs(0, 0);

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

  return 0;
}

C++: #include<stdio.h>
#include<malloc.h>

bool decide(int *b){
	int first = 10000;
	int i;
	for( i = 0; i < 9; i++){
		if(b[i+1] < b[i])first = b[i+1];
		break;
	}
	for(i = i+1; i < 9; i++)
		if(b[i+1] < first)return false;

	return true;
}

int main(){
	int N;
	scanf("%d",&N);
	int (*a)[10];
	a = (int (*)[10])malloc(N*10*sizeof(int));
	for(int i = 0; i < N; i++)
		for(int j = 0; j < 10; j++)
			scanf("%d",&a[i][j]);

	for(int k = 0; k < N; k++){
		int *b = a[k];
		if(decide(b) == false)printf("NO\n");
		else printf("YES\n");
		}

	return 0;
}