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

using namespace std;

int n;
int usea[11];

int dfs(int num, int r_num, int l_num) {
	int res = 0;

	if (usea[num] > r_num) {
		if (num == 9)
			return 1;
		res = dfs(num + 1, usea[num], l_num);
		return res;
	}
	else if (usea[num] >l_num) {
		if (num == 9)
			return 1;
		res = dfs(num + 1, r_num, usea[num]);
		return res;
	}
	else {
		return 0;
	}
}


int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> usea[j];
		}
		if (dfs(0, -1, -1)) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <climits>
using namespace std;
int b = INT_MIN, c = INT_MIN;
bool push(int ball) {
    if(ball > b) b = ball;
    else if (ball > c) c = ball;
    else return(false);
    return(true);
}

int main(void) {
    int num; cin >> num;
    int ans = 0;
    for(int r = 0; r < num; r++) {
        for(int c = 0; c < 10; c++) {
            int input; cin >> input;
            bool result = push(input);
            if(!result) ans += -100;
            else ans++;
        }
        if(ans >= 0) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

C++: //0033
//include-------------------------------------
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<stack>

using namespace std;

//typedef--------------------------------------
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define MP make_pair

//repetition-----------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

//constant-------------------------------------
const double PI = acos(-1.0);

//cout,cin-------------------------------------
#define COUT(x) cout<<(x)<<endl;
#define CIN(x) cin>>(x);


int main(){
	int n;
	int x[10];
	bool ans;

	CIN(n);

	REP(i, n){
		
		REP(j, 10) CIN(x[j]);
		stack<int> B, C;
		B.push(0);
		C.push(0);

		REP(j, 10){
			if ((B.top() > x[j]) && (C.top() > x[j])){
				ans = false;
				break;
			}
			else { 
				if ((B.top() >= C.top()) && (B.top() < x[j])) B.push(x[j]);
				else C.push(x[j]);
			}

		}
		COUT(ans==false?"NO":"YES");
		
	}

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

#define rep(i,a) for(int i=0;i<(a);i++)
using namespace std;

vector<int> in;


bool check(vector<int> r,vector<int> l){
	int lenr=r.size(),lenl=l.size();
	for(int i=1;i<lenr;i++){
		if(r[i]<=r[i-1])return false;
	}	
	for(int i=1;i<lenl;i++){
		if(l[i]<=l[i-1])return false;
	}
	return true;
}

bool dfs(vector<int> r,vector<int> l,int num){
	if(!check(r,l))return false;
	if(num==10)return true;

	r.push_back(in[num]);
	if( dfs(r,l,num+1) )return true;
	r.pop_back();

	l.push_back(in[num]);
	if( dfs(r,l,num+1) )return true;
	l.pop_back();

	return false;
}



int main(){
int N;
	cin>>N;
	rep(roop,N){
        while(in.size())in.pop_back();
		rep(i,10){
			int tmp;
			cin>>tmp;
			in.push_back(tmp);
		}
		if(dfs({},{},0))	cout<<"YES"<<endl;
		else		cout<<"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;
	}

	return ((i==num)? true: false);
}

int main(){
	int i, n;

	cin >> n;
	for (i=0; i<n; i++)
		cout << (judge(10)? "YES": "NO") << endl;

	return 0;
}

C++: #include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    bool flag;
    int num;
    int a,b,t;
    cin >> t;
    while(t--)
    {
        b = 0;
        flag = true;
        for(int i = 0; i < 10; i++)
        {
            scanf("%d",&num);
            if(i == 0)
            {
                a = num;
                continue;
            }
            if(num < a)
            {
                if(num > b)
                {
                    b = num;
                    continue;
                }
                else
                {
                    flag = false;
                    break;
                }
            }
            else if(num > a)
            {
                if(num-a > num-b)
                {
                    b = num;
                    continue;
                }
                else
                {
                    a = num;
                    continue;
                }
            }
        }
        if(flag == true)
        {
            printf("YES\n");
        }
        else printf("NO\n");
        fflush(stdin);
    }
    return 0;
}

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

int balls[10];

bool dfs(int i=0,int b_top=0,int c_top=0){
  //10個のボールを落とせたらtrue
  if(i == 10) return true;
  
  //Bのほうに入れる
  if(balls[i] > b_top && dfs(i+1,balls[i],c_top))
    return true;

  //Cの方に入れる
  if(balls[i] > c_top && dfs(i+1,b_top,balls[i]))
    return true;

  return false;
}

int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++) cin >> balls[j];
    cout << (dfs() ? "YES":"NO") << endl;
  }
  return 0;
}

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


int main(){
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		int ball[10];
		for(int j=0;j<10;j++)scanf("%d",&ball[j]);
		
		stack<int> S,Q;
		int a[2]={0};
		a[0] = ball[0];
		S.push(a[0]);
		Q.push(a[1]);
		
		int k=1;
		bool OK = false;
		while(1){
			a[0] = S.top();
			a[1] = Q.top();
			if(a[0] < ball[k]){
				S.push(ball[k]);
				k++;
				if(k >= 10){
					OK = true;
					break;
				}
			}else if(a[1] < ball[k]){
				Q.push(ball[k]);
				k++;
				if(k >= 10){
					OK = true;
					break;
				}
			}else{
				S.pop();
				Q.pop();
				k--;
			}
			if(S.size() == 0) break;
		}		
		if(OK == true) printf("YES\n");
		else printf("NO\n");
		
	}
	return 0;
}

C++: #include<iostream>

int a[10];
bool J;

void dfs(int n,int left,int right){
	if(n==10)
		J=true;
    if(a[n]>left)
			dfs(n+1,a[n],right);
    if(a[n]>right)
			dfs(n+1,left,a[n]);
}

int main(){
	int N;
	std::cin>>N;
	for(int i=0;i<N;++i){
		for(int i=0;i<10;++i){
			std::cin>>a[i];
		}
		J=false;
		dfs(0,0,0);
		if(J==true)
			std::cout<<"YES"<<std::endl;
		else std::cout<<"NO"<<std::endl;
	}
	return 0;
}