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 n;
int dp[maxn];
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(dp);
        int num;
        int maxlen=0;
        dp[maxlen]=inf;
        int flag=1;
        for(int i=1;i<11;i++){
            scanf("%d",&num);
            if(maxlen>2) flag=0;
            if(num<=dp[maxlen])
                dp[++maxlen]=num;
            else{
                int l=1,r=maxlen;
                while(l<=r){
                    int mid=l+(r-l)/2;
                    if(dp[mid]>num) l=mid+1;
                    else r=mid-1;
                }
                dp[l-1]=num;
            }
        }
        if(flag) printf("YES\n");
        else printf("NO\n");
	}

	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
using namespace std;
const int manx = 500;
stack <int> a;
stack <int> b;
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int input;
        int flag = true;
        scanf("%d",&input);
        a.push(input);
        b.push(0);
        for(int i = 1 ; i < 10 ; i++)
        {
            scanf("%d",&input);
            int ai = input - a.top();
            int bi = input - b.top();
            if(ai <= 0 && bi <= 0)
            {
                flag = false;
                printf("NO\n");
                break;
            }
            if(ai > 0 && bi <= 0)
                a.push(input);
            if(bi > 0 && ai <= 0)
                b.push(input);
            if(ai > 0 && bi > 0)
            {
                if(ai > bi )
                    b.push(input);
                if(ai <= bi)
                    a.push(input);
            }
        }
        if(flag == false)
            continue;
        else
            printf("YES\n");
        while( !a.empty() )
            a.pop();
        while( !b.empty() )
            b.pop();
    }
    return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
#define scai(x) scanf("%d", &x)
#define scac(x) scanf("%c", &x)
#define sca2i(x, y) scanf("%d %d", &x, &y)
#define sca2f(x, y) scanf("%lf %lf", &x, &y)
#define pri(x) printf("%d", x)
#define prc(x) printf("%c", x)
#define pri2(x,y) printf("%d %d", x, y)
#define prif(x) printf("%lf", x)
#define prif2(x, y) printf("%lf %lf", x, y)
#define mset(x, y) memset(x, y, sizeof(x))
#define fori(i, x, y) for(int i = x; i < y; i++)
#define pii pair<int, int>
#define pic pair<int, char>
#define pdd pair<double, double>
typedef long long ll;
const int N = 13;
int a[N];
int zuo[N];
int you[N];
int lc, rc;



bool solve()
{
    for(int i = 0; i < 1024; i++)
    {
        mset(zuo, 0);
        mset(you, 0);
        lc = rc = 0;
        int cnt;
        int j;
        for(j = i, cnt = 0; cnt < 10; cnt++, j >>= 1)
        {
            if(j & 1) zuo[lc++] = a[cnt];
            else you[rc++] = a[cnt];
        }
        bool flag = true;
        for(j = 1; j < lc; j++)
        {
            if(zuo[j] < zuo[j - 1]) {
                flag = 0;
                break;
            }
        }

        if(flag){
            for(j = 1; j < rc; j++){
                if(you[j] < you[j - 1]) {
                    flag = 0;
                    break;
                }
            }
        }

        if(flag) return true;
    }
    return false;
}


int main()
{
    int n;
    cin >> n;
    while(n--)
    {
        for(int i = 0; i < 10; i++)
        {
            scai(a[i]);
        }
        puts(solve()? "YES" : "NO");
    }
    return 0;
}

C++: #include<iostream>
int box[10];
int ltop=-1,rtop=-1;
bool ball(int i){
	if(i==9)return true; 
	if(ltop==-1 || rtop==-1){
		if(ltop==-1){
			ltop=box[i];
			return ball(i+1);
		}
		else{
		    rtop=box[i];
			return ball(i+1);	
		}
	}
	else{
		if(box[i]>ltop&&box[i]>rtop){
			if(ltop>rtop){
				ltop=box[i];
			}
			else{
				rtop=box[i];
			}
			return ball(i+1);
		}
		else if(box[i]>ltop){
			ltop=box[i];
			return ball(i+1);
		}
		else if(box[i]>rtop){
			rtop=box[i];
			return ball(i+1);
		}
		else 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))std::cout<<"YES\n";
		else std::cout<<"NO\n";
		ltop=-1;
		rtop=-1;
	}
}

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

bool dfs(int num, int val1, int val2, vector<int> &v){
  if(val1 > val2){
    int x = val1;
    val1 = val2;
    val2 = x;
  }
  if(num == 10)
    return true;

  if(val2 < v[num]){
    val2 = v[num];
    return dfs(num + 1, val1, val2, v);
  }else if(val1 < v[num]){
    val1 = v[num];
    return dfs(num + 1, val1, val2, v);
  }else {
    return false;
  }
}

int main(){
  int N;
  cin >> N;
  vector<int> v(10);
  vector<int> out(N, 0);
  for(int i=0;i<N;i++){
    for(int j=0;j<10;j++)
      cin >> v[j];
    if(dfs(0, 0, 0, v)){
      out[i] = 1;
    }
  }

  for(int i=0;i<N;i++)
    if(out[i] == 1)
      cout << "YES" << endl;
    else 
      cout << "NO" << endl;

  return 0;
}

C++: #include <stdio.h>

int ball[10];

bool can(int n,int left,int right){
	bool flag;
	
	if(n==10) return true;
	if(ball[n]>right && can(n+1,left ,ball[n])) return true;
	if(ball[n]>left  && can(n+1,ball[n],right)) 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",&ball[j]);
		}
		
		printf(can(0,0,0)?"YES\n":"NO\n");
		
		
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j;i<k;i++)
int N;
int A[10];
bool DFS(int Aindex,int x,int y){
  if(Aindex ==10)return true;
  if(x>A[Aindex] && y>A[Aindex])return false;
  bool m=false;
  if(x<A[Aindex])m=max(m,DFS(Aindex+1,A[Aindex],y));
  if(y<A[Aindex])m=max(m,DFS(Aindex+1,x,A[Aindex]));
  return m;
}
int main(){
  cin >> N;
  string ans[2]={"NO","YES"};
  rep(i,0,N){
    rep(i,0,10){
      cin >>A[i];
    }
    cout << ans[DFS(0,0,0)]<<endl;
  }
  return 0;
}