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<string>
#include<algorithm>	
#include<cmath>
#include<map>
#include<vector>
#define int long long
using namespace std;
int test[51];
signed main() {
    int n, a, b; cin >> n;
    for (int h = 0; h < n; h++) {
        int sum = 0, num = 0, c = 0;
        for (int i = 0; i < 10; i++) {
            cin >> a;
            if (c == 0) {
                if (sum < a) { sum = a; }
                else if (num < a) { num = a; }
                else { cout << "NO" << endl; c++; }
            }
        }
        if (c == 0) { cout << "YES" << endl; }
    }
}

C++: #include<iostream>

using namespace std;

int main()
{
	int n, i,j,a, b, c,flag;

	cin >> n;
	for (i = 0; i < n; i++) {
		b = c = 0;
		flag = 1;
		for (j = 0; j < 10; j++) {
			cin >> a;
			if (a > b) {
				b = a;
			}
			else if (a > c) {
				c = a;
			}else {
				flag = 0;
			}
		}

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

	return 0;
}

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

using namespace std;


int q;
int Ball[10];
bool flag;
vector<string> log;

bool is_satisfies(vector<int> a) {
    vector<int> copy = a;
    sort(a.begin(), a.end());
    return a == copy;
}

void bfs(int i, vector<int> B, vector<int> C) {
    if (i == 9) {
        if (is_satisfies(B) && is_satisfies(C))
            flag = true;
        else
            flag = flag == true ? true : false;
    } else {
        vector<int> temp;

        temp = B;
        temp.push_back(Ball[i]);
        bfs(i + 1, temp, C);

        temp = C;
        temp.push_back(Ball[i]);
        bfs(i + 1, B, temp);
    }
}

void solve() {
    vector<int> B, C;
    flag = false;

    bfs(0, B, C);

    if (flag)
        log.push_back("YES");
    else
        log.push_back("NO");
}

int main() {
    cin >> q;
    for (int i = 0; i < q; ++i) {
        for (int j = 0; j < 10; ++j)
            scanf("%d", &Ball[j]);

        solve();
    }

    for (int i = 0; i < log.size(); ++i) {
        cout << log[i] << endl;
    }
}

C++: #include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)

int a[11];
bool ans;

int main()
{
	int n; cin >> n;
	REP(l, n)
	{
		REP(i, 10) cin >> a[i];
		int b = 0; int c = 0;
		REP(i, 10)
		{

			if (a[i] < b&&a[i] < c) goto miss;
			else if (a[i] > b&& a[i] > c)
			{
				if (b > c) b = a[i];
				else c = a[i];
			}
			else if (a[i] > b&& a[i] < c) b = a[i];
			else if (a[i] < b&& a[i] > c) c = a[i];
		}
		cout << "YES" << endl;
		continue;
	miss:
		cout << "NO" << endl;
	}
	return 0;
}

C++: # include <stdio.h>

int main ()
{
	int n; 
	int a[10], b[10], c[10] ;
	while(scanf("%d", &n) != EOF)
	{
		while(n --)
		{
			int m = 0 ;
			int k = 0 ;
			int maxn ;
			for(int i = 0; i < 10; i ++)
				scanf("%d", &a[i]) ;
			int f = 0 ;
			maxn = 0 ;
			for(int i = 0; i < 10; i ++)
			{
				if(a[i] > maxn)
				{
					maxn = a[i] ;
					b[m++] = a[i] ;
				}
				else
				{
					if(a[i] > f)
					{
						f = a[i] ;
						c[k++] = a[i] ;
					}					
				}
			}
			if(m + k == 10)
				puts("YES") ;
			else
				puts("NO") ;
		
		}	
	}
	return 0 ;
}

C++: #include<iostream>
using namespace std;
int main(void)
{
    int bo[11],n,B[11],C[11],b1=0,c1=0,A=0,k=0,l=1;
    cin>>n;
    for(int i=0;i<n;i++){
            C[0]=11;k=0;l=0;B[0]=0;b1=0;c1=0;C[1]=13;
        for(int j=0;j<10;j++){
                //srand(time(NULL));
           cin>>bo[j];
           /*bo[j]=6-5+rand()%10;
            for(int m=0;m<j;m++){
                if(bo[j]==bo[m]){
                    --j;break;
                }
            }*/
        }
        for(int j=0;j<10;j++)cout<<bo[j]<<" ";
        cout<<"\n";
        for(int j=1;;j++){
                cout<<bo[j]<<" ";
            if(j==1)B[0]=bo[0];
        if(C[0]==11&&j==2){
            C[0]=bo[j];
            k++;
           // cout<<"6\n";
        }else if(C[1]==13&&j>3&&C[0]<bo[j]){
            C[1]=bo[j];
            k++;
            c1=1;
            //cout<<"7\n";
        }else if(B[l]<bo[j]){
            b1=1;
            B[l+1]=bo[l];
            l++;
            //cout<<"1\n";
        }else if(C[0]==11){
            C[0]=bo[j];
            k++;
            //cout<<"2\n";
        }else if(C[k-1]<bo[j]){
            c1=1;
            C[k+1]=bo[j];
            //cout<<"3\n";
        }else if(B[l]<bo[j+1]){
            C[k+1]=bo[j];
            k++;
            if(C[k]>C[k-1])c1=1;
            //cout<<"5\n";
        }else if(C[1]==13&&j>3){
            C[1]=bo[j];
            k++;
           // cout<<"7\n";
        }else{
            B[l+1]=bo[j];
            l++;
           // cout<<"4\n";
        }
        if(j==9||(b1==1&&c1==1))break;
    }
    if(b1==1&&c1==1)cout<<"YES\n";
    else cout<<"NO\n";
    for(int j=0;j<10;j++){
        B[j]=0;C[j]=0;
    }

}
}

C++: #include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

const int n = 10;
int t;
int a, b, c;

int main()
{
  cin >> t;

  while(t--){
    bool ok = true;
    b = c = 0;
    rep(i, n){
      cin >> a;
      if(b > c) swap(b, c);
      if(a > c){ c = a;  continue; }
      if(a > b){ b = a;  continue; }
      ok = false;
      break;
    }
    puts(ok ? "YES" : "NO");
  }

  return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
bool sf;
int T,st1,st2,x;
    int a[20],b[20],s[20];
void dfs(int i)
{
    if(i==10)
    {
        sf=1;
        return ;
    }
    if(sf)return ;
    if(a[st1]<s[i])
    {
        a[++st1]=s[i];
        dfs(i+1);
    }
    if(b[st2]<s[i])
    {
        b[++st2]=s[i];
        dfs(i+1);
    }

}
int main()
{
   // freopen("input.txt","r",stdin);

    cin>>T;
    while(T--)
    {
        for(int i=0;i<10;i++)
            cin>>s[i];
        sf=0;
        dfs(0);
        if(sf)cout<<"YES\n";
        else cout<<"NO\n";

    }





    return 0;
}