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 <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <climits>
#include <utility>

#define PRINT(STR) cout << STR << endl;
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define SPACE " "

typedef long long ll;

using namespace std;

int nextInt() { int n = -1; cin >> n; return n; }
double nextDouble() { double d = -1; cin >> d; return d; }
ll nextll() { ll n = -1; cin >> n; return n; }
string nextString() { string str; cin >> str; return str; }

int INF = 1LL << 25;
double EPS = 1e-9;
int numofbits(int bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

// BEGIN //////////////////////////////////////////////////////////////
int main() {
  int N = nextInt();
  REP(i, N) {
    int b = 0, c = 0;
    bool flag = true;
    REP(j, 10) {
      int a = nextInt();
      if (a > b) {
        b = a;
      } else if (a > c) {
        c = a;
      } else {
        flag = false;
      }
    }
    if (flag) {
      PRINT("YES");
    } else {
      PRINT("NO");
    }
  }
	return 0;
}
// END   //////////////////////////////////////////////////////////////

C++: #include <iostream>
#include <bitset>
#include <algorithm>
using namespace std;
 
///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{
 
	int n;
	cin >> n;
	while (n--)
	{
		int ball[10];
		
		for (int i = 0; i < 10; ++i)
		{
			cin >> ball[i];
		}
 
		bitset<10> direction;
		int all = 1024;
		while (all-- > 0)
		{
			direction = static_cast<bitset<10> >(all);
			bool perfect = true;
			int left = 0;
			int right = 0;
			for (int i = 0; i < 10; ++i)
			{
				if (direction[i])
				{
					if (ball[i] > left)
					{
						left = ball[i];
					}
					else
					{
						perfect = false;
						break;
					}
				}
				else
				{
					if (ball[i] > right)
					{
						right = ball[i];
					}
					else
					{
						perfect = false;
						break;
					}
				}
			}
			if (perfect)
			{
				break;
			}
		}
	
		if (all >= 0)
		{
			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<cstdio>
#include<queue>
using namespace std;
int main(){
	int n, tmp, top;
	queue<int> q;
	scanf("%d", &n);
	while(n--){
		top = 1;
		while (!q.empty()) q.pop();
		bool flag = true;
		for(int i = 0; i < 10; i++){
			scanf("%d", &tmp);
			if (tmp == top){
				top++;
				continue;
			}
			if (!q.empty() && q.front() == tmp){
				q.pop();
				continue;
			}
			if (tmp < top){
				flag = false;
				break;
			}
			while (top != tmp){
				q.push(top);
				top++;
			}
			top++;
		}
		if (flag) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

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

using namespace std;

int a[15],l[15],r[15];
int flag;

void dfs(int i,int j,int k)
{
    if(i>10)
    flag=1;
    if(flag)
    return;
    else
    {
        if(a[i]>l[j-1])
        {
            l[j]=a[i];
            dfs(i+1,j+1,k);
        }
        if(a[i]>r[k-1])
        {
            r[k]=a[i];
            dfs(i+1,j,k+1);
        }
    }

}

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

C++: #include <iostream>

using namespace std;

int main(){
  int n, num, right, left;
  bool flag;

  cin >> n;

  for(int i = 0; i < n; i++){
    right = 0;
    left = 0;
    flag = true;

    for(int j = 0; j < 10; j++){
      cin >> num;

      if(right < num){
        right = num;
      }else if(left < num){
        left = num;
      }else{
        flag = false;
      }
    }

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

  return 0;
}

C++: #include <iostream>
#include <cstring>
using namespace std;
#define MAX_N 10

int N;
int ball[MAX_N];

int used[MAX_N];

bool dfs(int max_l, int max_r, int next) {
    if (next == MAX_N) return true;
    if(ball[next] > max_l)
        return dfs(ball[next],max_r,next+1);
    if(ball[next] > max_r) 
        return dfs(max_l,ball[next],next+1);
    return false;
}

string solve() {
   memset(used,0,sizeof(used));
   return dfs(0,0,0) ? "YES" : "NO";
}

main() {
    cin>>N;
    for(int i=0;i<N;i++) {
        for(int j=0;j<MAX_N;j++) {
            cin>>ball[j];
        }
        cout << solve() << endl;
    }
}

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

typedef long long ll;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t; cin >> t;
    int a[10], b[10];
    while(t--) {
        for(int i = 0; i < 10; i++) {
            cin >> a[i];
        }
        int pre = a[0], count = 0;
        for(int i = 1; i < 10; i++) {
            if(a[i] > pre) pre = a[i];
            else b[count++] = a[i];
        }
        bool flag = false;
        for(int i = 1; i < count; i++) {
            if(b[i] <= b[i-1]) {
                flag = true;
                break;
            }
        }
        if(flag) cout << "NO\n";
        else cout << "YES\n";
    }
    return 0;
}