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++: //
// Create by 神舟 on 2015-02-20
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cctype>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <set>
#include <vector>
using namespace std;

#define CLR(x) memset(x,0,sizeof x)
#define ll long long
#define inf 0x3f3f3f3f
const int maxn=1e1+5;
const int MOD=5e5+5;
int num[maxn],n;
bool dfs( int deep, int A, int B)
{
    if(deep==11) return true;
    if(num[deep]>A&&dfs(deep+1,num[deep],B)) return true;
    if(num[deep]>B&&dfs(deep+1,A,num[deep])) return true;
    return false;

}
int main()
{
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(0);

	scanf("%d",&n);
	while(n--){
        CLR(num);
        for(int i=1;i<11;scanf("%d",num+i++));
        if(dfs(1,-inf,-inf)) printf("YES\n");
        else printf("NO\n");
	}
	return 0;
}

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

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	int n,d[10],f;
	stack<int> a,b,*p,*q;
	scanf("%d",&n);
	rep(i,n){
		rep(j,10)scanf("%d",d+9-j);
		while(!a.empty())a.pop();
		while(!b.empty())b.pop();
		a.push(11);
		b.push(11);
		f=0;
		rep(j,10){
			p=a.top()>b.top()?&a:&b;
			q=a.top()<=b.top()?&a:&b;
			if(q->top()>d[j])q->push(d[j]);
			else if(p->top()>d[j])p->push(d[j]);
			else {
				f=1;break;
			}
		}
		puts(f?"NO":"YES");
	}
	return 0;
}

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

stack<int> B, C;
int A[10];

bool dfs(int index)
{
  bool ret = false;
  char s[11];

  if (index >= 10) {
    return true;
  }

  for (int i = 0; i < 11; i++) {
    if (i < index) s[i] = '>';
    else s[i] = 0;
  }

  if (B.empty() || B.top() < A[index]) {
    B.push(A[index]);
    // printf("%spush %d into B\n", s, A[index]);
    ret = dfs(index + 1);
    // printf("%s%s. pop %d from B\n", s, ret ? "succeeded" : "failed", A[index]);
    B.pop();
  }
  if (!ret && (C.empty() || C.top() < A[index])) {
    C.push(A[index]);
    // printf("%spush %d into C\n", s, A[index]);
    ret = dfs(index + 1);
    // printf("%s%s. pop %d from C\n", s, ret ? "succeeded" : "failed", A[index]);
    C.pop();
  }

  return ret;
}

bool solve()
{
  while (!B.empty()) B.pop();
  while (!C.empty()) C.pop();

  B.push(A[0]);
  bool ret = dfs(1);
  B.pop();

  return ret;
}

int main()
{
  int N;
  scanf("%d", &N);

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      scanf("%d", A + j);
    }

    if (solve()) {
      printf("Yes\n");
    }
    else {
      printf("No\n");
    }
  }

  return 0;
}

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

int Balls[10];


bool not_dfs(int balls[]){
  int b = 0, c = 0;
  for (int i = 0; i < 10; i++) {
    if (b < balls[i]) continue;
    if (c < balls[i]) continue;
    return false;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> Balls[j];
    }
    if(not_dfs(Balls)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

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

using namespace std;

int main(void){
	int n;

	cin >> n;
	for(int i=0;i<n;i++){
		int ball;
		stack<int> b,c;
		bool put=true;

		for(int j=0;j<10;j++){
			cin >> ball;
			if(put){
				if(b.empty()||b.top()<ball)
					b.push(ball);
				else if(c.empty()||c.top()<ball)
					c.push(ball);
				else
					put=false;
			}
		}
		cout << (put?"YES":"NO") << endl;
	}
}

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

int ball[10];

int  bunbetu(int i, int left, int right) {
	if (i == 10) {
		cout << "YES" << "\n";
		return 0;
	}
	if (ball[i] < left) {
		if (ball[i] < right) {
			cout << "NO" << "\n";
			return 0;
		}
		bunbetu(i + 1, left, ball[i]);
	}
	else bunbetu(i + 1, ball[i], right);
}

int main() {
	int set;
	cin >> set;
	for (int i = 0; i < set; i++) {
		for (int j = 0; j < 10; j++){
			cin >> ball[j];
		}
		bunbetu(0, 0, 0);
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#define INF 1000000000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define all(x) (x).begin(),x.end()
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

int a[11];

int dfs(int left,int right,int cnt){
  //cout<<left<<" "<<right<<" "<<cnt<<endl;
  if(cnt==9)return cnt;
  if(left<a[cnt]&&right<a[cnt]) cnt=max(dfs(a[cnt],right,cnt+1),dfs(left,a[cnt],cnt+1));
  else if(left<a[cnt])cnt=dfs(a[cnt],right,cnt+1);
  else if(right<a[cnt]) cnt=dfs(left,a[cnt],cnt+1);
  
  return cnt;
}

int main(){
  int n;
  cin>>n;
  rep(i,n){
    rep(j,10)cin>>a[j];
    //rep(j,10)cout<<a[i]<<" ";
    //cout<<endl;
    if(dfs(a[0],-INF,1)==9)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}

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

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

int main(){
    int x;
    for(int i=0;i<x;++i){
        std::vector<int> vec(10);
        for(int l=0;l<10;++l){
            std::cin>>vec[l];
        }
        std::vector<std::vector<int> > vec2(2);
        vec2[0].push_back(vec[0]);
        for(int l=1;l<vec.size();++l){
            if(l==1){
                if(vec2[0][0]<vec[1]){
                    vec2[0].push_back(vec[1]);
                }else vec2[1].push_back(vec[1]);
            }else{
                if(vec[l]>vec2[0][vec2[0].size()-1]){
                    vec2[0].push_back(vec[l]);
                }else{
                    if(vec2[1].size()==0)vec2[1].push_back(vec[l]);
                    else if(vec2[1][vec2[1].size()-1]<vec[l]){
                        vec2[1].push_back(vec[0]);
                    }else{
                        std::cout<<"NO"<<std::endl;
                        goto con;
                    }
                }
            }
        }
        std::cout<<"YES"<<std::endl;
con:
    }
    return 0;
}