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 <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
#include <functional>
const int INF =1e5;
const int MOD = 1e9 + 7;
using namespace std;
typedef pair<int,int> P;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define pb push_back
vector<int> a;
vector<int> b;
int v[10];
bool dfs(int,int,int);

int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;++i){
        rep(i,10) cin>>v[i];
        if(dfs(0,0,0)) cout<<"YES"<<endl;
        else  cout<<"NO"<<endl;
    }
    return 0;
}
bool dfs(int i,int a,int b){
    if(i==10)return true;
    if(a<v[i]) return dfs(i+1,v[i],b);
    if(b<v[i]) return dfs(i+1,a,v[i]);
    if(a>=v[i] && b>=v[i])return false;
    return false;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

using namespace std;

int main(){
	int n;

	cin >> n;

	while(n--){
		int tmp = 0;
		vector<int> b, c;
		bool limitB = false, limitC = false;

		for(int i = 0; i < 10; i++){
			limitB = false;
			limitC = false;
			cin >> tmp;

			if(b.size() == 0){
				b.push_back(tmp);
				continue;
			}
			else if(b.size() != 0 && c.size() == 0){
				if(b[b.size() - 1] < tmp){
					b.push_back(tmp);
					continue;
				}
				else{
					limitB = true;
				}
			}
			
			if(c.size() == 0){
				c.push_back(tmp);
				continue;
			}
			
			if(b[b.size() - 1] < tmp){
				b.push_back(tmp);
				continue;
			}
			else{
				limitB = true;
			}
		
			if(c[c.size() - 1] < tmp){
				c.push_back(tmp);
				continue;
			}
			else{
				limitC = true;
			}

			if(limitB && limitC){
				cout << "NO" << endl;
				break;
			}

		}
		if(!limitB || !limitC){
			cout << "YES" << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int a[10];

bool dfs(int i, int left, int right){
	cout << left << " " << right << " " << i << endl;
	if(i == 10) return true;
	bool answer = false;
	if(left < a[i]){
		answer = dfs(i+1, a[i], right);
	}
	if(right < a[i]){
		answer = dfs(i+1, left, a[i]);
	}

	return answer;
}


int main(){
	int N;
	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;
	}
	return 0;
}

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

int n;
int a[10];
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;
}

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

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

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

int main(){
  int N,t,B,C;
  cin >> N;
  for(int i = 0 ; i < N ; i++){
    B = C = 0;
    for(int j = 0; j < 10; j++){
      cin >> t;
      if(B >= t && C >= t){
	cout << "NO" << endl;
	break;
      }
      else if(B < t && C < t){
	if(B < C) C = t;
	else B = t;
      }
      else if(B < t) B = t;
      else if(C < t) C = t;
      //      cout << B << " ";
      if(j == 9) cout << "YES" << endl;
    }
  }
  return 0;
}

C++: #include <cstdio>

using namespace std;

bool is_satisfiable(const int balls[], int left_top, int right_top) {
  if (*balls == 0) { return true; }
  return (*balls > left_top &&
          is_satisfiable(balls + 1, *balls, right_top)) ||
         (*balls > right_top &&
          is_satisfiable(balls + 1, left_top, *balls));
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int balls[11];
    for (int j = 0; j < 10; ++j) { scanf("%d", balls + j); }
    balls[10] = 0;
    puts(is_satisfiable(balls, 0, 0) ? "YES" : "NO");
  }

  return 0;
}

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

C++: #include <bits/stdc++.h>

#define SIZE 300005
#define MOD 1000000007LL
#define INF INT_MAX / 3
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef valarray<int> Array;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i];if(i==a.size()-1)cout<<endl;else cout<<" ";}}
int gcd(int a,int b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
int lcm(int a,int b){return a==0||b==0?0:a*b/gcd(a,b);}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  REP(v,n)
  {
    vector<int> a, b;
    int m = 0;
    REP(i,10)
    {
      int t; cin >> t;
      if(t > m)
      {
        m = t;
        a.push_back(t);
      }
      else b.push_back(t);
    }
    int i = 0;
    while(i<b.size()-1)
    {
      if(b[i] > b[++i])
      {
        cout << "NO" << "\n";
        break;
      }
    }
    if(i==b.size()-1) cout << "YES" << "\n";
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 1000000000;
using namespace std;
int main() {
  int n, s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a = 0, b = 0;
    bool key = 1;
    for (int j = 0; j < 10; j++) {
      cin >> s;
      if (s > a)
        a = s;
      else if (s > b)
        b = s;
      else
        key = 0;
    }
    cout << (key ? "YES" : "NO") << endl;
  }
  return 0;
}