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>

using namespace std;

int main(void){
    int a[11],fir,i,n;
    cin>>n;
    while (n--) {
        int sec=0;
        for (i=0; i<10; i++) {
            cin>>a[i];
        }
        fir=a[0];
        for (i=1; i<10; i++) {
            if(fir<a[i])fir=a[i];
            else if(sec<a[i])sec=a[i];
            else break;
        }
        if(i==10)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;
const int kBalln = 10;
int ball[kBalln];

bool ExistAsceOrder(int i, int a, int b){
  if (i == kBalln)  return true;

  if (a < ball[i] && ExistAsceOrder(i+1,ball[i],b)) return true;

  if (b < ball[i] && ExistAsceOrder(i+1,a,ball[i])) return true;

  return false;
}

int main(){
  int n;

  cin >> n;
  for (int j = 0; j < n; ++j)
    {
      for (int i = 0; i < kBalln; ++i)
        {
          cin >> ball[i];
        }
      cout << (ExistAsceOrder(0,0,0)? "YES" : "NO") << endl;
    }
  return 0;
}

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

int n;
int a[10];
vector<int> l, r;
vector<int> emp;

bool dfs(int p){
	printf("p=%d\n", p);
	/*
	printf("l ");
	for(int i=0; i<l.size(); i++){
		printf("%d ", l[i]);
	}
	printf("\nr ");
	for(int i=0; i<r.size(); i++){
		printf("%d ", r[i]);
	}
	printf("\n");
*/
	if(p == 10) return true;
	l.push_back(a[p]);
	if(l.size() == 1 || l[l.size() - 2] < l[l.size() - 1]){
		return dfs(p+1);
	}else{
		l.pop_back();
		r.push_back(a[p]);
		if(r.size() == 1 || r[r.size() - 2] < r[r.size() - 1]){
			return dfs(p+1);
		}else{
			r.pop_back();
			return false;
		}
	}
}

int main(){
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		l = emp;
		r = emp;
		for(int j=0; j<10; j++){
			scanf("%d", &a[j]);
		}
		if(dfs(0)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

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

int main(){
    stack <int> st1;
    stack <int> st2;
    int n,tmp,a,b;
    bool judge;
    cin >> n;
    while(n--){
        judge = true;
        for(int i=0;i<10;i++){
            cin >> tmp;
            if(i == 0){
                st1.push(tmp);
                continue;
            }
            if(st2.empty()){
                if(tmp < st1.top()) st2.push(tmp);
                else st1.push(tmp);
                continue;
            }
            if(tmp - st1.top() > 0 && tmp - st2.top() > 0){
                a = tmp - st1.top();
                b = tmp - st2.top();
                if(a < b) st1.push(tmp);
                else st2.push(tmp);
            }
            else if(tmp - st1.top() > 0) st1.push(tmp);
            else if(tmp - st2.top() > 0) st2.push(tmp);
            else judge = false;
        }
        if(judge) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

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


int res=0;

bool saiki(int ball[],int ttB,int ttC,int res){
	if(res==10)return true;
	if(ball[res]>ttB){
		return saiki(ball,ball[res],ttC,res+1);
	}
	if(ball[res]>ttC){
		return saiki(ball,ttB,ball[res],res+1);
	}
	return false;
}

int main(void){
	int a,b;
	int ball[11];
	int ttB=0,ttC=0;
	int n;
	scanf("%d",&n);
	for(a=0;a<n;a++){
		for(b=0;b<10;b++){
			ball[b]=0;
		}
		ttB=0;
		ttC=0;
		res=0;
		for(b=0;b<10;b++){
			scanf("%d",&ball[b]);
		}
		if(saiki(ball,ttB,ttC,res)==true)printf("YES\n");else printf("NO\n");
	}
	return 0;
}

C++: #include<iostream>
main(){int n,i,A,B,C;for(std::cin>>n;n-->0;puts(i>20?"NO":"YES"))for(B=C=i=0;std::cin>>A,i++<10;)if(B<A)B=A;else C<A?C=A:i=30;}

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

using namespace std;

int n, a[10];

bool dfs(int depth, int b, int c) {
    if (depth == 10)
        return true;
    bool ret = false;
    if (a[depth] > b) {
        ret = ret || dfs(depth + 1, a[depth], c);
    }
    if (a[depth] > c) {
        ret = ret || dfs(depth + 1, b, a[depth]);
    }
    return ret;
}

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

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--){
    bool used[10];
    REP(i,10)used[i]=false;
    int left=-1,right=-1;
    bool flag = true;
    REP(i,10){
      int x;
      cin>>x;
      --x;
      if(x<left && x<right){
        flag = false;
        break;
      }else if(x<left && x>right){
        right = x;
        used[x] = true;
      }else if(x>left && x<right){
        left = x;
        used[x] = true;
      }else{
        if(right>left){
          right = x;
          used[x] = true;
        }else{
          left = x;
          used[x] = true;
        }
      }
    }
    if(flag){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
  }
  return 0;
}

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

using namespace std;

int n;
vector<int> vec;
int lcount, rcount, l, r;

bool dfs(int i)
{
	if(i == 10) return true;
	if(lcount < 10 && l < vec[i]){ l = vec[i]; if(dfs(i + 1)) return true; }
	if(rcount < 10 && r < vec[i]){ r= vec[i]; if(dfs(i + 1)) return true; }
	return false;
}

int main()
{
	while (cin >> n && n)
	{
		lcount = 0; rcount = 0; l = 0; r = 0;
		vec.resize(10);
		for (int j = 0; j < n; j++)
		{

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

C++: #include<iostream>

using namespace std;

int main(){

  int in;
  cin >> in;
  for(int i = 0; i < in; i++){
    int data[2];
    data[0] = data[1] = 0;
    int flg = 0;
    for(int i = 0; i < 10; i++){
      int num;
      cin >> num;
      if(data[0] < data[1]){
	int tmp = data[0];
	data[0] = data[1];
	data[1] = tmp;
      }
      if(num > data[0]) data[0] = num;
      else if(num > data[1]) data[1] = num;
      else flg = 1;
    }
    if(flg) cout << "NO"<< endl;
    else cout << "YES"<<endl;
  }
  return 0;
}