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++: // 2013/10/22 Tazoe

#include <iostream>
using namespace std;

int A[10];

bool DFS(int I, int B, int C){
	if(I==10)
		return true;

	if(A[I]>B && DFS(I+1, A[I], C))
		return true;

	if(A[I]>C && DFS(I+1, B, A[I]))
		return true;

	return false;
}

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>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
	int a,b;
	int n;
	int g;
	bool check;

	while(cin >> n){
		vector<int> ball;
		a = b = 0;
		check = true;
		rep(i,10){
			cin >> g;
			ball.insert( ball.begin(), g);
		}
		rep(i,10){
			if(a < ball.back() && b < ball.back()){
				if(a > b){
					a = ball.back();
				}else{
					b = ball.back();
				}
			}else if(a < ball.back()){
				a = ball.back();
			}else if(b < ball.back()){
				b = ball.back();
			}else{
				check = false;
			}
			ball.pop_back();
		}
		if(check) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

C++: #include<cstdio>
#include<vector>
using namespace std;
int main(){
    int n,a[10];
    scanf("%d",&n);
    for(int ix=0;ix<n;ix++){
        for(int jx=0;jx<10;jx++){
            scanf("%d",&a[jx]);
        }
        bool is=false;
        for(int i=0;i<(1<<10);i++){
            vector<int> b,c;
            for(int j=0;j<10;j++){
                if(i&(1<<j))b.push_back(a[j]);
                else c.push_back(a[j]);
            }
            bool isb=true,isc=true;
            if(!b.empty()){
                for(int j=1;j<b.size();j++){
                    if(b[j-1]>b[j]){
                        isb=false;
                        break;
                    }
                }
            }
            if(!c.empty()){
                for(int j=1;j<c.size();j++){
                    if(c[j-1]>c[j]){
                        isb=false;
                        break;
                    }
                }
            }
            if(isb&&isc){
                is=true;
                break;
            }
        }
        if(is)printf("YES\n");
        else printf("NO\n");
    }
}

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

signed main()
{
  int n;
  vector<int> kanade;
  cin >> n;

  for (int i = 0; i < n; i++) {
    kanade.clear();
    for (int j = 0; j < 10; j++) {
      int tmp;
      cin >> tmp;
      kanade.push_back(tmp);
    }

    int b = 0, c = 0;
    bool hayami = true;
    for (int j = 0; j < 10; j++) {
      if (b == 0 || b < kanade[j]) {
        b = kanade[j];
      } else if (c == 0 || c < kanade[j]) {
        c = kanade[j];
      } else {
        hayami = false;
      }
    }

    if (hayami) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }

  return (0);
}

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

const int N = 10;

int a[N];

void input()
{
    for (int i = 0; i < N; i ++) {
        scanf("%d", &a[i]);
    }
}

void solve()
{
    bool res = false;
    for (int k = 0; k < (1<<10); k++) {
        int num = 0;
        int i;
        for (i = 0; i < N; i ++) {
            if ( (1 << i)&k ) {
                if (a[i] > num)
                    num = a[i];
                else
                    break;
            }
        }
        if (i < N)
            continue;
        num = 0;
        for (i = 0; i < N; i ++) {
            if ( ((1 << i)&k) == 0 ) {
                if (a[i] > num)
                    num = a[i];
                else
                    break;
            }
        }
        if (i == N) {
            res = true;
            //printf("k=%d\n", k);
            break;
        }
    }
    if (res)
        printf("YES\n");
    else
        printf("NO\n");
}

int main(void)
{
    int t;
    cin >> t;
    while (t--) {
        input();

        solve();
    }

    return 0;
}

C++: #include <stdio.h>
#define Max_N 10

int N;
int preA,preB;
int data[Max_N+1];

bool dfs(int x){
	if(x==10) return true;
	if(preA<data[x]){
		preA=data[x];
		if(dfs(x+1)) return true;
	}
	if(preB<data[x]){
		preB=data[x];
		if(dfs(x+1)) return true;
	}
	return false;
}

void solve(){
	preA=0;preB=0;
	if(dfs(0)) printf("YES\n");
	else printf("NO\n"); 
}

int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		for(int j=0;j<10;j++){
			scanf("%d",&data[j]);
		}
		solve();
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int N;

int nums[10];

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

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int i = 0; i < 10; i++) {
			cin >> nums[i];
		}
		
		if (dfs(-1, -1, 0)) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include<stdio.h>
int a[10],b=0,c=0;
bool tube[10];
bool dfs(int i){
    if(i==10) return true;
    bool flagb,flagc;
    if(b>=a[i]&&c>=a[i]) return false;
    if(b<a[i]){
        int oldb=b;
        b=a[i];
        flagb=dfs(i+1);
        b=oldb;
        if(flagb) return true;
    }
    if(c<a[i]){
        int oldc=c;
        c=a[i];
        flagc=dfs(i+1);
        c=oldc;
        if(flagc) return true;
    }
    return false;
}
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(dfs(0)) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

C++: #include<iostream>
#include<stack>
#include<map>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n--){
    stack<pair<int,int> > back;
    int a = 0,b = 0,row[10];
    bool f = true;
    for(int i=0; i<10; i++){cin >>row[i];}
    a = row[0];
    for(int i=1; i<10; i++){
      if(a < row[i] && b > row[i]){a = row[i];}
      else if(a > row[i] && b < row[i]){b = row[i];}
      else if(a < row[i] && b < row[i]){
	back.push(make_pair(a,i));
	a = row[i];
      }
      else if(a > row[i] && b > row[i]){
	if(back.empty()){cout <<"NO"<<endl;f = false;break;}
	else{
	  i = back.top().second;
	  a = back.top().first;
	  b = row[i];
	  back.pop();
	}
      }
    }
    if(f){cout <<"YES"<<endl;}
  }
  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;i++<10;){
  std::cin>>A;
  if(B<A)B=A;else C<A?C=A:i=30;
 }
}