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 <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <array>
#include <stack>
#include <queue>
#include <chrono>
#include <numeric>

#pragma warning(disable:4996)
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
typedef long long Int;

using namespace std;

int balls[10];
int ar[10];

bool solve()
{
	int a(0);
	int b(0);

	REP(i, 10){
		if (ar[i]){
			if (a > balls[i])
				return false;
			a = balls[i];
		}
		else{
			if (b > balls[i])
				return false;
			b = balls[i];
		}
	}
	return true;
}

int main()
{
	cin.tie(0); ios::sync_with_stdio(false);
	//fstream fs("input.txt");
	////////////ここから開始///////////
	int n(0);
	cin >> n;
	while (n--){
		bool f = false;
		REP(i, 10){
			cin >> balls[i];
			ar[i] = 0;
		}
		for (int i = 0; i < 1 << 10; ++i){
			REP(j, 10)
				ar[9 - j] = i >> j & 1;

			f |= solve();
		}
		string ans = f ? "YES" : "NO";
		cout << ans << endl;
	}
	
	return 0;
}

C++: /*
Á·Ï°Ìâ£ºBall_AOJ 0033
*/
#include <cstdio>
using namespace std;

int a[15];

bool dfs(int x)
{
	if(x>=8)
		return true;
	if(a[x]<a[x+2])
	{
		return dfs(x+2);
	}
	else
		return false;
	
	
}

int main()
{
	int T;
	scanf("%d", &T);
	while(T--)
	{
		for(int i=0; i<10; i++)
			scanf("%d", &a[i]);
		int f1=dfs(0);
		int f2=dfs(1);
		if(f1&&f2)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int a[15];
string b,c; 
int main(){
	int n;
	cin>>n;
	while(n--){
		for(int i=0;i<10;i++){
			cin>>a[i];	
		}
		for(int i=0;i<=1024;i++){
			if(i==1024){
				cout<<"NO"<<endl;
				break;
			}
			c.clear();b.clear();
			for(int j=0;j<10;j++){
				if((i>>j)&1){//进c 
					c+=('0'+a[j]);
				}
				else{//进b 
					b+=('0'+a[j]);
				}
			}
			int ok=1;
			for(int j=0;j<b.size()-1;j++){
				if(b[j]>b[j+1]){
					ok=0;
					break;
				}
			}
			for(int j=0;j<c.size()-1;j++){
				if(c[j]>c[j+1]){
					ok=0;
					break;
				}
			}
			if(ok){
				cout<<"YES"<<endl;break;
			}
		}
	}	
	return 0;
}

C++: /*
* Filename:    aoj0033.cpp
* Desciption:  DFS
* Created:     2016-03-02
* Author:      JIngwei Xu [mail:xu_jingwei@outlook.com]
*
*/
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#define INT_MAX 2<<30
using namespace std;
//typedef long long ll;
int a[10],n;
int used[10];
bool ans=false;
bool check(){
	int ss=0;
	for (int i = 0; i < 10; i += 1)
	{
		if(used[i]==0){ss=a[i];break;}
	}
	if(ss==0)return true;
	for (int i = 0; i < 10; i += 1)
	{
		if(used[i]==0){
			if(a[i]<ss)return false;
			else ss=a[i];
		}
	}
	return true;
}
void dfs(int k,int rec){
	if(k==10){
		if(check())ans=true;
		return;
	}
	if(ans)return;
	if(a[k]>rec){
		used[k]=1;
		dfs(k+1,a[k]);
		if(ans)return;
		used[k]=0;
		dfs(k+1,rec);
		if(ans)return;
	}
	else{
		used[k]=0;
		dfs(k+1,rec);
	}
}
int main()
{
	scanf("%d",&n);
	for (int i = 0; i < n; i += 1)
	{
		for (int j = 0; j < 10; j += 1)
		{
			scanf("%d",&a[j]);
		}
		ans=false;
		for (int i = 0; i < 10; i += 1)
		{
			memset(used,0,sizeof(used));
			used[i]=1;
			dfs(i+1,a[i]);
			if(ans)break;
		}
		
		
		if(ans)printf("YES");
		else printf("NO");
		
	}
	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<string>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
int flag,a[11],vis[11];
void bfs(){
	queue<int>q;queue<int>p;
	q.push(a[0]);
	p.push(a[1]);
	int i=2;
	while(i<10){
		int t1=q.front(),t2=p.front();
		if(!q.empty())q.pop();if(!p.empty())p.pop();
		if(a[i]<t1&&a[i]<t2){
			flag=0;
			break;
		}
		 if(a[i]>=t1){
			q.push(a[i]);
			i++;
		}
		 if(a[i]>=t2){
			p.push(a[i]);
			i++;
		}
	}
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--){
		flag=1;
		for(int i=0;i<10;i++)
		scanf("%d",&a[i]);
		bfs();
		if(flag)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++: /*
*
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#define CLR(ARR,NUM) memset(ARR,NUM,sizeof(ARR))
#define GETNUM(NUM) scanf("%d",&NUM)
#define faster_io() ios_base::sync_with_stdio(false)
using namespace std;
const int MAXN = 20;
int a[MAXN];
bool vaild;
void dfs(int x,int l,int r)
{
	if(x==10){
		vaild=true;
		return;
	}
	if(a[x]>l){
		dfs(x+1,a[x],r);
	}
	if(a[x]>r){
		dfs(x+1,l,a[x]);
	}
}

int main()
{
	int n;
	cin >> n;
	while(n--){
		for(int i=0;i<10;i++){
			GETNUM(a[i]);
		}
		vaild=false;
		dfs(0,0,0);
		if(vaild){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
 
using namespace std;
 
int a[10];
bool flag;
 
void dfs(int n, int l, int r)
{
    if (n == 10) {
        flag = true;
        return ;
    }
 
    if (a[n] > l)
        dfs(n + 1, a[n], r);
    if (a[n] > r)
        dfs(n + 1, l, a[n]);
 
    return ;
}
 
int main()
{
    int n;
 
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++)
            cin >> a[j];
 
        flag = false;
        dfs(0, 0, 0);
        if (flag)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
 
    return 0;
}

C++: #include<algorithm>
#include<iostream>
#include<cstring>
#include<climits>
#include<cstdio>
using namespace std;
int T,a[15],isac;
void dfs(int num,int left,int right)
{
    if(num==11){isac=1;return ;}
    if(a[num]>left)dfs(num+1,a[num],right);
    if(a[num]>right)dfs(num+1,left,a[num]);
}
int main()
{
    scanf("%d",&T);
    while(T--)
    {
        isac=0;
        for(int i=1;i<=10;i++)scanf("%d",&a[i]);
        dfs(1,0,0);
        if(isac)printf("YES\n");
        else printf("NO\n");
    }
}

C++: #include<iostream>
int box[10];
int ltop = -1, rtop = -1;
bool ball(int i, int left, int right){
	if (i == 10)return true;
	if (left<box[i])return ball(i + 1, box[i], right);
	if (right<box[i])return ball(i + 1, left, box[i]);
	if (left>box[i] && right>box[i])return false;
}
int main(){
	int n;
	std::cin >> n;
	for (int what = 0; what<n; ++what){
		for (int i = 0; i<10; ++i){
			std::cin >> box[i];
		}
		if (ball(0, ltop, rtop))std::cout << "YES\n";
		else std::cout << "NO\n";
		ltop = -1;
		rtop = -1;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    vector<int> v(10);
    for (int j = 0; j < 10; j++) {
      cin >> v.at(j);
    }
    sort(v.begin(), v.begin() + 2);
    int a = v.at(0), b = v.at(1);
    bool flag = true;
    for (int k = 2; k <= 10; k++) {
      if (v.at(k) > a) {
        if (v.at(k) < b) {
          a = v.at(k);
        } else {
          b = v.at(k);
        }
      } else {
        flag = false;
      }
    }
    if (flag)
    cout << "YES" << endl;
    else
    cout << "NO" << endl;
  }
}