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 <string>

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
using namespace std; 

#define MAX 10

int N;
int in[MAX];
vector<string> vs;
string s;

void dfs(int l, int r, int cnt) {
	if(cnt == MAX) s = "YES";
	if(in[cnt] > l) dfs(in[cnt],r,cnt+1);
	if(in[cnt] > r) dfs(l,in[cnt],cnt+1);
}

void solve()
{
	s = "NO";
	dfs(0,0,0);
	vs.pb(s);
}

void input()
{
	cin >> N;
	rep(i,0,N) {
		rep(j,0,MAX) cin >> in[j];
		solve();
	}
}

int main(void)
{
	input();
	rep(i,0,vs.size()) cout << vs[i] << endl;
	return 0;
}

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=1e5+5;
const int MOD=5e5+5;
int n,flag,num[maxn],l[maxn],r[maxn];
void dfs(int ln,int rn)
{

    if(ln+rn==10) flag=1;
    if(flag) return;
    if(num[ln+rn+1]>l[ln]){
        l[ln+1]=num[ln+rn+1];
        dfs(ln+1,rn);
    }
    if(num[ln+rn+1]>r[rn]){
        r[rn+1]=num[ln+rn+1];
        dfs(ln,rn+1);
    }
}
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--){
        flag=0;
        CLR(l);
        CLR(r);
        CLR(num);
        l[0]=r[0]=-inf;
        for(int i=1;i<11;scanf("%d",num+i++));
        dfs(0, 0);
        if(flag) printf("YES\n");
        else printf("NO\n");
	}
	return 0;
}

C++: #include <stdio.h>

int main()
{
	int N, ball[10], B[10], C[10], b, c, k;

	scanf("%d", &N);

	for (int i = 0; i < 2; i++){
		scanf("%d %d %d %d %d %d %d %d %d %d", &ball[0], &ball[1], &ball[2], &ball[3], &ball[4], &ball[5], &ball[6], &ball[7], &ball[8], &ball[9]);

		b = 0;
		c = 0;
		k = 0;
		for (int j = 0; j < 10; j++){
			if(b < ball[j] && (ball[j] - b) <= (ball[j] - c)) b = ball[j];
			else if(c < ball[j]) c = ball[j];
			else {k = 1; break;}
		}

		if(k == 0) printf("YES\n");
		else printf("NO\n");
	}
	
	return 0;
}

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

int main()
{
int n;
scanf("%d", &n);
for(int testcase = 0; testcase < n; ++testcase) {
bool yes = false;
int s = 10;
vector<int> x;
x.resize(s);
for(int i = 0; i < s; ++i)
scanf("%d", &x[i]);
for(int bit = 0; bit < (1 << s); ++bit) {
int count = 0;
for(int i = 0; i < s; ++i)
count += (bit >> i) & 1;
if(count != s / 2)
continue;
bool valid = true;
for(int lr = 0; lr < 2; ++lr) {
int prev = -100;
for(int i = 0; i < s; ++i) {
if(((bit >> i) & 1)== lr) {
if(prev >= x[i]) {
valid = false;
break;
}
prev = x[i];
}
}
}
if(valid) {
yes = true;
break;
}
}
printf("%s\n", yes ? "YES" : "NO");
}
return 0;
}

C++: #include<stdio.h>

#include<string.h>

int a[13],vis[13],flag;

void dfs(int x,int l,int r)

{

    int i;

    if(x==11)return; 

    if(flag)return ;

    if(a[x]>l)dfs(x+1,a[x],r);

    else  if(a[x]>r)dfs(x+1,l,a[x]);

    else  {flag=1;return;}

  

}

int main()

{

int T,i,j,k;

scanf("%d",&T);

while(T--)

{

flag=0;

for(i=1;i<=10;i++)

scanf("%d",&a[i]);

memset(vis,0,sizeof(vis));

dfs(1,0,0);

if(flag)printf("NO\n");

else printf("YES\n");

}

return 0;

}

C++: #include<cstdio>
int n, a[10];
int b[11] = { }, c[11] = { };

bool
dfs (int l, int r)
{
  if (l + r == 10)
    return true;
  if (b[l] < a[l + r])
    {
      b[l + 1] = a[l + r];
      return dfs (l + 1, r);
    }
  else if (c[r] < a[l + r])
    {
      c[r + 1] = a[l + r];
      return dfs (l, r + 1);
    }
  return false;
}

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

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int a,m1=0,m2=0;
		bool ans=true;
		for(int j=0;j<10;j++){
			cin >> a;
			if(m1<a) m1=a;
			else if(m2<a) m2=a;
			else ans=false;
			if(m1<m2) swap(m1,m2);
		}
		cout << (ans ? "YES" : "NO") << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;

#define FOR(x) for(int i = 0; i < x; i++)


stack<short> x, y;
short a[10], n, j, i;

bool solve(short c, bool judge){
	if(c == 10) return true;
	if(x.top() < a[c]){
		x.push(a[c]);
		if(solve(c + 1, true)) return true;
	}
	if(y.top() < a[c]){
		y.push(a[c]);
		if(solve(c + 1, false)) return true;
	}
	if(judge) x.pop();
	else y.pop();
	return false;
}

int main(){
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		x.push(0);
		y.push(0);
		for(j = 0; j < 10; j++)
			scanf("%d", &a[j]);
		if(solve(0, true)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    while (N--) {
        vector<int> a(10);
        for (int i = 0; i < 10; i++) {
            cin >> a[i];
        }
        bool pos = 1;
        stack<int> st[2];
        st[0].push(a[0]);
        for (int i = 1; i < 10; i++) {
            bool use = 0;
            for (int j = 0; j < 2; j++) {                
                if (st[j].empty() || st[j].top() < a[i]) {
                    st[j].push(a[i]);
                    use = 1;
                    break;
                }
            }
            if (!use) {
                pos = 0;
                break;
            }
        }
        cout << (pos ? "YES" : "NO") << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<cstdio>
#include<cstdlib>
#include<cmath>

using namespace std;
typedef pair<int,int> PII;
typedef long long ll;

int main(){
  int n,a,b,c,i;
	cin>>n;
	for(;n>0;n--){
		a = b = 0;
		for(i=0;i<10;i++){
			cin>>c;
			if(a >= b && c > a)
				a = c;
			else if(c > b)
				b = c;
			else
				break;
		}
		if(i==10)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
  return 0;
}