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 <stdio.h>

int main(void)
{
	int tubeM[10];
	int tube1[10], tube2[9];
	int i, j, k;
	int n;
	int ans;
	
	scanf("%d", &n);
	
	while(n){
		for (i = 0; i < 9; i++){
			tube2[i] = 0;
		}
		
		for (i = 0; i < 10; i++){
			scanf("%d", &tubeM[i]);
		}
		
		tube1[0] = tubeM[0];
		for (i = 1, j = 0, k = 0; i < 10; i++){
			if (tubeM[i] > tube1[j]){
				j++;
			}
			else {
				tube2[k] = tubeM[i];
				k++;
			}
		}
		
		ans = 0;
		for (i = 1; tube2[i] != 0; i++){
			if (tube2[i - 1] > tube2[i]){
				ans = 1;
				break;
			}
		}
		
		if (ans == 0){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
		
		n--;
	}
	
	return (0);
}

C++: #include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD
 
int main(){
  int n;
  cin>>n;
  while(n--){
    int left=-1,right=-1;
    bool flag = true;
    REP(i,10){
      int x;
      cin>>x;
      if(x>right){
        right = x;
      }else if(x>left){
        left = x;
      }else{
        flag = false;
      }
    }
    if(flag){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		vector<int> pile1;
		vector<int> pile2;
		pile2.push_back(0);
		int num[10];
		cin>>num[0]>>num[1]>>num[2]>>num[3]>>num[4]>>num[5]>>num[6]>>num[7]>>num[8]>>num[9];
		pile1.push_back(num[0]);
		for(int j=1;j<=9;j++){
			if(pile1[pile1.size()-1]<num[j]) pile1.push_back(num[j]);
			else if(pile2[pile2.size()-1]<num[j]) pile2.push_back(num[j]);
			else{
				cout<<"NO"<<endl;
				break;
			}
			if(j==9) cout<<"YES"<<endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int B,C; int N; int A[10];
bool dfs(int i){
  if(i==10) return true;
  if(A[i]>max(B,C)){
    if(B>C){B=A[i];}else{C=A[i];} dfs(i+1);
  }else if(A[i]<max(B,C)&&A[i]>min(B,C)){
    if(B>C){C=A[i];}else{B=A[i];} dfs(i+1);
  }else{
    return false;
  }
 }
void solve(){
  B=0; C=0;
  for(int i=0; i<10; i++){
      cin>>A[i];
    }
  if(dfs(0)){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
    }
  }
int main() {
  cin>>N;
  for(int i=0; i<N; i++){
  solve();
  }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(void){
	int n,a,b,c;
	bool f;
	cin>>n;
	for(int i=0;i<n;i++){
		f=true;b=0;c=0;
		for(int j=0;j<10;j++){
			cin>>a;
			if(b>a&&c>a){
				f=false;
				break;
			}else if(b<a && c<a){
				if(b>=c)b=a;
				else c=a;
			}else if(b<a){
				b=a;
			}else if(c<a){
				c=a;
			}
		}
		if(f)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

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

int n;
int ball[10];
int r, l;
int now;

bool dfs(int r, int l, int now);

int main(){

	cin >> n;

	for(int i=0; i<n; i++){
		r = 0;
		l = 0;
		now = 0;

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

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

	return 0;
}

bool dfs(int right, int left, int now){
	if(now == 10) return true;
	if(right < ball[now]) return dfs(ball[now], left, now+1);
	if(left < ball[now]) return dfs(right, ball[now], now+1);
	return false;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll; 
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;


ll n, a[100];
stack<int> vi1, vi2;

int main(){
	cin >> n;
	REP(i, n){
		REP(j, 10){
			cin >> a[j];
		}
		REP(j, 10){
			if (vi1.empty()){
				vi1.push(a[j]);
				continue;
			}
			if (vi2.empty()){
				if (vi1.top() > a[j]){
					vi2.push(vi1.top());
					vi1.pop();
					vi1.push(a[j]);
				}
				else{
					vi2.push(a[j]);
				}
				continue;
			}
			if (vi2.top() < a[j]){
				vi2.push(a[j]);
			}
			else{
				if (vi1.top() < a[j]){
					vi1.push(a[j]);
				}
				else{
					cout << "NO" << endl;
					break;
				}
			}
			if (j == 10 - 1){
				cout << "YES" << endl;
			}
		}
		while (!vi1.empty()){
			vi1.pop();
		}
		while (!vi2.empty()){
			vi2.pop();
		}
	}
}

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

using namespace std;



void solve(vector<int> left, vector<int> right, vector<int> all, int n) {
	bool flag = true;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else
							flag = false;
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}	 	
		if (flag)
			printf("YES\n");
		else
			printf("NO\n");
		flag = true;
	}
}

int main() {		
	vector<int> left;
	vector<int> right;
	vector<int> all;


	int n;
	scanf("%d", &n);
	if (n <= 0) return -1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}	  

	solve(left, right, all, n);

	return 0;
}

C++: #include <iostream>
using namespace std;
int b, c, cnt, x[11];
void dfs(int i){
   if(x[i] > b){
       b = x[i];
       dfs(i+1);
       cnt++;
   }
   if(x[i] > c){
       c = x[i];
       dfs(i+1);
       cnt++;
   }
}

int main(void){
   int N;
   cin >> N;
   while(N != 0){
       b = 0;
       c = 0;
       cnt = 0;
       for(int i = 0; i < 10; i++){
           cin >> x[i];    
       }
       dfs(0);
       if(cnt == 11)   cout << "YES" << endl;
       else    cout << "NO" << endl;
       N--;
   }
   return 0;
}