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 <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int d[10];
bool solve(){
  int a=0;
  int b=0;
  for(int i=0;i<10;i++){
    if(a<d[i]){a=d[i];continue;}
    else if(b<d[i]){b=d[i];continue;}
    else return false;
  }
  return true;
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>d[j];
    }
    cout<<(solve()?"YES":"No")<<endl;
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>

typedef long long ll;
using namespace std;

typedef pair<int,int> P;

void seek_lcs(int a,int b,int dp[10+1][10+1],int* num,int* base,vector<int>& idx){
	if(a==0 || b==0){
		return;
	}

	if(num[a] == base[b]){
		seek_lcs(a-1,b-1,dp,num,base,idx);
		idx.push_back(num[a]);
	}
	else{
		if(dp[a-1][b] >= dp[a][b-1]){
			seek_lcs(a-1,b,dp,num,base,idx);
		}
		else{
			seek_lcs(a,b-1,dp,num,base,idx);
		}
	}

}

int main()
{
	int T;
	cin >> T;
	for(int t=0;t<T;t++){

		int num[10+1];
		int base[10+1];
		int dp[10+1][10+1];

		memset(dp,0,sizeof(dp));

		for(int i=1;i<=10;i++){
			scanf("%d",num+i);
			base[i]=i;
		}
		num[0]=0;
		base[0]=0;

		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				if(num[i+1]==base[j+1]){
					dp[i+1][j+1] = max(dp[i+1][j],max(dp[i][j+1],dp[i][j]+1));
				}
				else{
					dp[i+1][j+1] = max(dp[i+1][j],max(dp[i][j+1],dp[i][j]));
				}
			}
		}

		vector<int> idx;
		stack<int> stk;
		seek_lcs(10,10,dp,num,base,idx);

		for(int i=1;i<=10;i++){
			if(find(idx.begin(),idx.end(),num[i]) != idx.end()){
				continue;
			}

			if(stk.empty() || stk.top() < num[i]) stk.push(num[i]);
		}

		printf("%s\n",idx.size() + stk.size() == 10 ? "YES" : "NO");
	}
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){

  int blank,n,num[10],i;
  vector <int> a,b;

  cin>>n;
  for(int j=0;j<n;j++){
  for(i=0;i<10;i++) cin>>num[i];
  blank=0;
  a.clear();
  b.clear();
  a.push_back(0);
  b.push_back(0);
  for(i=0;i<10;i++){

    if(num[i]>a.back() && num[i]>b.back()){
      if(a.back()<=b.back()){
	b.push_back(num[i]);
	continue;
      }
      else {
	a.push_back(num[i]);
	continue;
      }
    }

    if(num[i]>a.back()){
      	a.push_back(num[i]);
	continue;
    }
      if(num[i]>b.back()){
      	b.push_back(num[i]);
	continue;
    }
      
      blank=1;
      break;

  }

  if(blank==0) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  }
  
  return 0;

}

C++: #include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        int a[10];
        for (int j=0;j<10;j++)
            cin >> a[j];
        int left,right;
        left = a[0];
        right = 0;
        for (int j=1;j<10;j++){
            if(a[j]<left && a[j]<right){
                cout << "NO" << endl;
                break;
            }
            else{
                if(j==9){
                    cout << "YES" << endl;
                    break;
                }
                else{
                if(a[j]>left && a[j]<right)
                    left = a[j];
                else{
                    if(a[j]<left && a[j]>right)
                        right = a[j];
                    else{
                        if(left<right)
                            right = a[j];
                        else
                            left = a[j];
                    }
                }
            }
        }
        }
    }
}

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

int main() {
	int n, x;
	cin >> n;
	for (int lop = 0, a = 0, b = 0; lop < n; lop++) {
		bool f = true;
		for (int i = 0; i < 10; i++) {
			cin >> x;
			if (f) {
				if (a < x && b < x) {
					if (a < b) {
						b = x;
						continue;
					}
					a = x;
					continue;
				}
				if (a < x) {
					a = x;
					continue;
				}
				if (b < x) {
					b = x;
					continue;
				}
				f = false;
			}
		}
		cout << (f ? "YES\n" : "NO\n");
	}
	return 0;
}

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

int main() {

  int n;
  cin >> n;

  int b = 0;
  int c = 0;
  int input;

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

    bool flag = false;
    for ( int j = 0; j < 10; j++ ) {
      cin >> input;

      if ( input < b && input < c ) flag = true;
      if ( flag ) continue;

      if ( input < b ) {
	c = input;
      }else if ( input < c ) {
	b = input;
      }else {
	if ( b < c ) {
	  c = input;
	}else {
	  b = input;
	}
      }

    }

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

  }

  return 0;

}

C++: #include<iostream>

using namespace std;

int tama[10],n;

bool Haireruka(int i,int left,int right){
	if(i==9)return true;
	if(tama[i]>left){
		if(Haireruka(i+1,tama[i],right))return true;
	}
	if(tama[i]>right){
		if(Haireruka(i+1,left,tama[i]))return true;
	}
	return false;
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		for(int i=0;i<10;i++){
			cin>>tama[i];
		}
		if(Haireruka(0,0,0))cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

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

int main(void)
{
	int N;
	cin >> N;

	while(N > 0){
		int data[10];
		int a=0,b=-1;
		for(int i = 0; i < 10; i++){
			cin >> data[i];

		}

		for(int i = 0; i < 10; i++){
			if(a > data[i] && b > data[i]){
				a = -1;
				break;
			}
			if(data[i] > a && a > b)
				a = data[i];
			else if(a > data[i] && data[i] > b)
				b = data[i];


		}

		if(a < 0)
			cout << "NO" << endl;
		else
			cout << "YES" << endl;

		N--;
	}

	return 0;

}

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

int n;
int a[11];
//int r, l;

// bool dfs(int i) {
//     if (i == 9) return a[i] > r || a[i] > l;
//     if (a[i] > r) {
//         r = a[i];
//     }
//     if (a[i] > l) {
//         l = a[i];
//     }
//     if (dfs(i+1)) return true;
//     return false;
// }

bool dfs(int i, int r, int l) {
    if (i == 9) return a[i] > a[r] || a[i] > a[l];
    if (dfs(i+1, max(a[i+1], r), l)) return true;
    if (dfs(i+1, r, max(a[i+1], l))) return true;
    return false;
}

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

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> a[j];
        }
        solve();
    }
}