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 <stack>
#include <vector>

using namespace std;

int N;
int A_bottle[10];

stack<int> B_bottle,C_bottle;

bool dfs(int i){
	//A????????????i???????????°?????????????????????
	if (i==10){
		//?????????????????????????????????????????????
		return true;
	}
	bool flg=false;

	if (B_bottle.empty() || B_bottle.top()<A_bottle[i]){
		//B????????????????????????
		B_bottle.push(A_bottle[i]);
		flg=dfs(i+1);
		B_bottle.pop();
		if (flg) return true;
	}
	if (C_bottle.empty() || C_bottle.top()<A_bottle[i]){
		//C????????????????????????
		C_bottle.push(A_bottle[i]);
		flg=dfs(i+1);
		C_bottle.pop();
		if (flg) return true;
	}
	return false;
}

int main(){
	vector<bool> out;
	cin>>N;
	for (int i=0;i<N;i++){
		for (int j=0;j<10;j++){
			cin>>A_bottle[j];
		}
		out.push_back(dfs(0));
	}
	for (vector<bool>::iterator ite=out.begin();ite!=out.end();ite++){
		cout<<(*ite ? "YES" : "NO")<<endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

bool judge(int num){
	int i, n, q[2]={0,0};

	for (i=0; i<num; i++) {
		cin >> n;
		if (q[0]<n)
			q[0] = n;
		else if (q[1]<n)
			q[1] = n;
		else
			break;
	}

	if (i==num)
		return true;
	else
		return false;
}

int main(){
	int i, lines;

	cin >> lines;
	for (i=0; i<lines; i++) {
		if (judge(10))
			cout << "NO\n";
		else
			cout << "YES\n";
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
using namespace std;

int ball[10];

stack<int> b;
stack<int> c;

bool routine(int dep){
	if(dep == 10){
		return true;
	}
	bool bcheck;
	//b?????\??????
	if(b.size() == 0){
		b.push(ball[dep]);
		bcheck = routine(dep+1);
	}else{
		if(b.top() < ball[dep]){
			b.push(ball[dep]);
			bcheck = routine(dep+1);
		}else{
			bcheck = false;
		}
	}
	bool ccheck;
	if(c.size() == 0){
		c.push(ball[dep]);
		ccheck = routine(dep+1);
	}else{
		if(c.top() < ball[dep]){
			c.push(ball[dep]);
			ccheck = routine(dep+1);
		}else{
			ccheck = false;
		}
	}
	return (bcheck || ccheck);
}

void solve(){
	for(int i = 0; i < 10; i++){
		scanf("%d", &ball[i]);
	}
	printf(routine(0) ? "YES\n" : "NO\n");
}

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		solve();
	}
	return 0;
}

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

int main(){
	int n;

	cin >> n;

	int* a = new int[ n * 10 ];

	for ( int i = 0; i < n; ++i ){
		cin >> a[ i*10 + 0 ] >> a[ i*10 + 1 ] >> a[ i*10 + 2 ] >> a[ i*10 + 3 ] >> a[ i*10 + 4 ]
			>> a[ i*10 + 5 ] >> a[ i*10 + 6 ] >> a[ i*10 + 7 ] >> a[ i*10 + 8 ] >> a[ i*10 + 9 ];
	}

	for ( int i = 0; i < n; ++i ){
		int right = 0, left = 0;
		for ( int j = 0; j < 10; ++j ){
			int pick = a[ i*10 + j ];
			if ( pick < right && pick < left ){
				cout << "NO" << endl;
				break;
			}else if ( pick > right && pick < left ){
				right = pick;
			}else if ( pick < right && pick > left ){
				left = pick;
			}else if ( right > left ){
				right = pick;
			}else{
				left = pick;
			}
			if ( j == 9 ){
				cout << "YES" << endl;
			}
		}
	}

	delete[] a;

	return 0;
}

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

using namespace std;

int main(){
  int f;
  int n;
  int in,b,c;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    f=b=c=0;
    for(int j=0;j<10;j++){
      scanf("%d",&in);
      if(in<=min(b,c)){
	f=1;
	break;
      }
      if((b>=c && b<in)||(c>=b && c>in))b=in;
      else c=in;
    }
    if(f)printf("NO\n");
    else printf("YES\n");
  }
}

C++: #include <iostream>
#include <algorithm>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); ++i)

int ball[10], lb[10], rb[10];

bool dfs(int n, int l, int r) {
    if(n==10) {
        rep(i, l-1) if(lb[i] > lb[i+1]) return false;
        rep(i, r-1) if(rb[i] > rb[i+1]) return false;
        return true;
    }
    lb[l] = ball[n];
    bool hoge = dfs(n+1, l+1, r);
    rb[r] = ball[n];
    bool fuga = dfs(n+1, l, r+1);
    if(hoge || fuga) return true;
    else return false;
}

int main(void){
    int N;
    cin >> N;
    rep(loop, N) {
        rep(i, 10) cin >> ball[i];
        if(dfs(0, 0, 0)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int n;
    cin>>n;
    while(n--){
        int ball[15]={0};
        int A=0,B=0;
        int x=0,y=0;
        bool flg=0;
        for(int i=0;i<10;i++){
            cin>>ball[i];
        }
        for(int i=0;i<10;i++){
            if(x<ball[i])x=ball[i];
            else if(y<ball[i])y=ball[i];
            else{
                cout<<"NO"<<endl;
                flg=1;
                break;
            }
        }
        if(flg==0)cout<<"YES"<<endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(void)
{
int n;
cin>>n;
int b[10]={0};
int c[10]={0};
for(int i=0;i<n;i++)
{
	int a[10]={0};
	for(int j=0;j<10;j++)
	{
	int x;
	cin>>x;
	a[j]=x;
	}
	int k=0;
	for(int j=0;j<10-1;j++)
	{
	
	if(a[j]>a[j+1])
		{
		b[k]=a[j];
		k++;
		}
	else c[j]=a[j];
	}
	for(int i=0;i<10-1;i++)
	{
	if(b[i]>b[i+1] && b[i+1]!=0 || c[i]>c[i+1] && c[i+1]!=0)
	{
	cout<<"NO"<<endl;
	break;
	}
	else 
	{
	cout<<"YES"<<endl;
	break;
	}
	}
}
return 0;
}

C++: #include<iostream>
#include<stack>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;
int main(){
  int n;
  cin >> n;
  int a[n][10];
  REP(i,n){
    REP(j,10){
      int b;
      cin >> b;
      a[i][j] = b;
    }
  }
  int flag[n] = {0};
  REP(i,n){
    stack <int> b;
    stack <int> c;
    b.push(a[i][0]);
    for(int j = 1;j < 10;j++){
      if(b.top() < a[i][j]){
	b.push(a[i][j]);
      }
      else{
	if(c.empty()){
	  c.push(a[i][j]);
	}
	else if(c.top() < a[i][j]){
	  c.push(a[i][j]);
	}
	else{
	  flag[i] = 1;
	}
      }
    }
  }

  REP(i,n){
    if(flag[i] == 1){
      cout << "NO" << endl;
    }
    else{
      cout << "YES" << endl;
    }
  }

}