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>

using namespace std;

int main(void) {
    int N, a, b, c, x[10];
    cin >> N;
    for (; N--; ) {
        bool ok = true;
        b = c = 0;
        for (int i = 0; i < 10; i++) {
            cin >> x[i];
        }
        cerr << b << endl;
        cerr << c << endl;
        for (int i = 0; i < 10; i++) {
            a = x[i];
            if (a < b && a < c) {
                ok = false;
                break;
            } else if (a < b) {
                c = a;
            } else if (a < c) {
                b = a;
            } else if (b < c) {
                c = a;
            } else {
                b = a;
            }
        }
        if (ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <string>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <vector>
#include <cstdlib>
#include <stack>
#include <time.h>
using namespace std;
typedef long long LL;
const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1.0); //M_PI;
const int maxn = 100001;
int a[maxn];
int vis[maxn];

void dfs(int cur , int next)
{
    if(cur >= 10 || next >= 10) return ;
    else{
        if(a[cur] < a[next]){
             vis[next] = 1;
             dfs(next , next + 1);
        }
        else{
            dfs(cur , next + 1);
        }
    }
}

int main()
{
    #ifdef DoubleQ
    freopen("in.txt" , "r" , stdin);
    #endif
    int n;
    cin >> n;
    while(n --){
        for(int i = 0 ; i < 10 ; i ++){
            cin >> a[i];
        }
        int flag = 0;
        int y = 0;
        for(int i = 0 ; i < 10 ; i ++){
            memset(vis , 0 , sizeof(vis));
            vis[i] = 1;
            dfs(i , i + 1);
            int tp = -1;
            flag = 0;
            for(int j = 0 ; j < 10 ; j ++){
                if(vis[j] == 0){
                    if(a[j] > tp){
                        tp = a[j];
                    }
                    else{
                        flag = 1;
                        break;
                    }
                }
            }
            if(flag == 0)
            {
                
                y = 1;
                cout << "YES" << endl;
                break;
            }
        }
        if(y == 0) cout << "NO" << endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include<stack>
#include<vector>

using namespace std;
int t[11];
vector<int>a;
vector<int>b;
int aa,bb;
bool solve()
{
      for(int i = 0 ; i< 1<<10 ;i++)
      {
          a.clear(),aa=0;
          b.clear(),bb=0;
        for(int j = 0 ; j < 10 ; j++)
        {
            if(i&(1<<j))
            a.push_back(t[j]);
            else
            b.push_back(t[j]);

        }
      for(int i=0;i<a.size();i++)
      {
          if(a[i]>a[i+1])
          {
                 aa=1;break;
          }

      }

        for(int i=0;i<b.size();i++)
      {
          if(b[i]>b[i+1])
          {
              bb=1;break;
          }

      }

      if(aa==0&&bb==0)
      {
          return true;
      }

    }

        return false;


}
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        a.clear();aa=0;
        b.clear();bb=0;
        memset(t,0,sizeof(t));
        for(int i = 0 ; i < 10 ; i++)
        {
           scanf("%d",&t[i]);
        }

        if(solve())
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;


   }
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int b = 0, c = 0;
bool push(vector<int> ball) {
    vector<int>::iterator ite;
    for(ite = ball.begin(); ite != ball.end(); ite++) {
        if(*ite > b) b = *ite;
        else if (*ite > c) c = *ite;
        else return(false);
    }
    return(true);
}

int main(void) {
    int num; cin >> num;
    for(int r = 0; r < num; r++) {
        vector<int> vec;
        for(int c = 0; c < 10; c++) {
            int input; cin >> input;
            vec.push_back(input);
        }
        if(push(vec)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return(0);
}

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

stack<int> b,c;

int main()
{
    int ball,n;
    bool flag = true;
    scanf("%d", &n);
    for(int i=0;i<n;++i) {
        for(int j=0;j<10;++j) {
            scanf("%d", &ball);
            if (b.empty())      { b.push(ball); continue; }
            if (b.top() < ball) { b.push(ball); continue; }
            if (c.empty())      { c.push(ball); continue; }
            if (c.top() < ball) { c.push(ball); continue; }
            flag=false;
            break;
        }
        (flag) ? puts("YES") : puts("NO");
    }

    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;

int main() {
    int T; cin >> T;
    while (T--) {
        int a = 0, b = 0, succ = 1;
        for (int i = 0; i < 10; i++) {
            int n; scanf("%d", &n);
            if (a > b) {
                if (n > a) a = n;
                else if (n > b) b = n;
                else succ = 0;
            } else {
                if (n > b) b = n;
                else if (n > a) a = n;
                else succ = 0;
            }
        }
        puts(succ ? "YES" : "NO");
    }
    return 0;
}

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

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");
	}
}