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

using namespace std;

int main()
{
    int n;
    cin >> n;

    for( int iii=0; iii<n; ++iii ) {
        stack<int> p[2];
        bool succ = true;

        for( int i=0; i<10; ++i ) {
            int ball;
            cin >> ball;

            if ( p[0].empty() ) {
                p[0].push( ball );

            } else {
                int diff = 999, t;
                for( int j=0; j<2; ++j ) {
                    int r = 0;
                    if ( !p[j].empty() )
                        r = ball - p[j].top();
                    if ( r < 0 )
                        continue;

                    if ( r < diff ) {
                        diff = r;
                        t = j;
                    }
                }

                if ( diff == 999 ) {
                    succ = false;
                } else {
                    p[t].push( ball );
                }
            }
        }

        cout << ( succ ? "YES" : "NO" ) << endl;
    }
}

C++: #include <iostream>

using namespace std;

int main() {
	int n; cin >> n;
	for (int t = 0; t < n; ++t) {
		int a[10];
		for (int i = 0; i < 10; ++i) cin >> a[i];

		bool ans = false;
		for (int k = 0; k < (1 << 10); ++k) {
			int top[2] = {-1, -1};
			bool f = true;
			for (int i = 0; i < 10; ++i) {
				int tid = k & i ? 1 : 0;
				if (a[i] < top[tid]) {
					f = false;
					break;
				}
				top[tid] = a[i];
			}
			ans |= f;
		}

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

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

using namespace std;

int main() {
	vector<int> left;
	vector<int> right;
	vector<int> all;

	bool flag = true;

	int n;
	cin >> n;
	if (n == 0) return -1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else  if (all.size() == (i+1)*(j+1)) {

						}
						else {
							flag = false;
						}			  						
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}

		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
		flag = true;
	}

	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>

typedef long long ll;
using namespace std;

typedef pair<int,int> P;

void seek_lcs(int a,int b,int dp[10+1][10+1],int* num,int* base,vector<int>& idx){
	if(a==0 || b==0){
		return;
	}

	if(num[a] == base[b]){
		seek_lcs(a-1,b-1,dp,num,base,idx);
		idx.push_back(num[a]);
	}
	else{
		if(dp[a-1][b] >= dp[a][b-1]){
			seek_lcs(a-1,b,dp,num,base,idx);
		}
		else{
			seek_lcs(a,b-1,dp,num,base,idx);
		}
	}

}

int main()
{
	int T;
	cin >> T;
	for(int t=0;t<T;t++){

		int num[10+1];
		int base[10+1];
		int dp[10+1][10+1];

		memset(dp,0,sizeof(dp));

		for(int i=1;i<=10;i++){
			scanf("%d",num+i);
			base[i]=i;
		}
		num[0]=0;
		base[0]=0;

		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				if(num[i+1]==base[j+1]){
					dp[i+1][j+1] = max(dp[i+1][j],max(dp[i][j+1],dp[i][j]+1));
				}
				else{
					dp[i+1][j+1] = max(dp[i+1][j],max(dp[i][j+1],dp[i][j]));
				}
			}
		}

		vector<int> idx;
		stack<int> stk;
		seek_lcs(10,10,dp,num,base,idx);

		for(int i=1;i<=10;i++){
			if(find(idx.begin(),idx.end(),num[i]) != idx.end()){
				continue;
			}

			if(stk.empty() || stk.top() < num[i]) stk.push(num[i]);
		}

		printf("%s\n",idx.size() + stk.size() == 10 ? "YES" : "NO");
	}
}

C++: #include<iostream>
#include<stdio.h>
const int nn = 10;
int a[nn];
using namespace std;
bool dfs()
{
	int left = -1;
	int right = -1;
	
	int T = 0;
	while (T<nn)
	{
		if (right < a[T])
		{
			right = a[T++];
			continue;
		}
		if (left < a[T])
		{
			left = a[T++];
			continue;
		}
		return false;
	}
	return true;
}
int main()
{
	//freopen("in.txt", "r", stdin);
	int N;
	scanf("%d", &N);
	while (N--)
	{
		for (int i = 0; i < nn; i++)
			scanf("%d", &a[i]);
		if (dfs())
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#include<cstdio>
#define MAXN 2555
#define INF 0x3f3f3f3f
#define v first
#define b second
using namespace std;
stack<int>q;
stack<int>p;
int s[15];
bool flag;
void dfs(int x)
{
   if(x==10)
   {
      flag=true;
      return ;
   }
   if(s[x]>q.top())
   {
      q.push(s[x]);
      dfs(x+1);
      q.pop();
   }
   if(s[x]>p.top())
   {
      p.push(s[x]);
      dfs(x+1);
      p.pop();
   }
   return ;
}
int main()
{
   int t;
   scanf("%d",&t);
   q.push(0);
   p.push(0);
   while(t--)
   {
      flag=false;
      for(int i=0;i<10;i++)
         scanf("%d",&s[i]);
      dfs(0);
      if(flag)
         cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
   }
   return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
 
using namespace std;
 
const double eps=1e-10;

int main()
{
	int n;
	cin>>n;

	for(int i=0;i<n;i++){
		vector<int> a(10);
		for(int j=0;j<10;j++) cin>>a[j];

		bool ok=false;

		for(int j=0;j<(1<<10);j++){
			vector<int> b,_b,c,_c;

			for(int k=0;k<10;k++){
				if(j & (1<<k)) b.push_back(a[k]);
				else c.push_back(a[k]);
			}

			_b=b; _c=c;
			sort(_b.begin(),_b.end());
			sort(_c.begin(),_c.end());

//			reverse(_b.begin(),_b.end());
//			reverse(_c.begin(),_c.end());

			if(b==_b && c==_c){
				cout<<"YES"<<endl;


				ok=true; break;
			}

		}

		if(!ok) cout<<"NO"<<endl;

	}

	return 0;
}