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<cstdio>
#include<string>
#include<vector>
#include<fstream>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<cwctype>
#include<algorithm>
#include<math.h>

using namespace std;


int data[10];

bool searchB (int a){
	vector<int >sea;

	for(int i=0;i<10;i++){
		if(a>>i & 1)sea.push_back(data[i]);
	}
	if(sea.size()>1){
	for(int i=0;i<sea.size()-1;i++){
		if(sea[i]>sea[i+1])return false;
	}
	}
	return true;
}

int main(){

	int n=0;
	cin>>n;

	for(int i=0;i<n;i++){
		

	for(int j=0;j<10;j++){
		cin>>data[j];
	}
	bool suc=false;
	for(int i=0;i<2048;i++){
		if(searchB(i) && searchB(~i)){
			cout<<"YES"<<endl;
			suc=true;
			break;
		}
	}
	if(!suc)cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<set>
#include<string>
#include<queue>
#include<string.h>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<stack>
#include<sstream>
using namespace std;
int num[11];
int preA, preB, x;
bool dfs(int preA,int preB,int x,int cnt) {
	if (cnt == 11) {
		return true;
	}
	if (x > preA) {
		preA = x;
		x = num[cnt + 1];
		dfs(preA, preB, x, cnt + 1);
	}
	if (x > preB) {
		preB = x;
		x = num[cnt + 1];
		dfs(preA, preB, x, cnt + 1);
	}
	if (x < preA&&x < preB) {
		return false;
	}
}
int main() {
	int t;
	cin >> t;
	while (t--) {
		for (int i = 1; i <= 10; i++)
			cin >> num[i];
		preA = num[1];
		preB = 0;
		x = num[2];
		int cnt = 2;
		if (dfs(preA, preB, x, cnt))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

C++: #include <stdio.h>

int main(void)
{
	int tubeM[10];
	int tube1[10], tube2[10];
	int i, j, k;
	int n;
	int ans;
	
	scanf("%d", &n);
	
	while(n){
		
		for (i = 0; i < 10; i++){
			scanf("%d", &tubeM[i]);
			
			tube2[i] = 0;
		}
		
		tube1[0] = tubeM[0];
		for (i = 1, j = 0, k = 0; i < 10; i++){
			if (tubeM[i] > tube1[j]){
				tube1[j + 1] = tubeM[i];
				j++;
			}
			else {
				tube2[k] = tubeM[i];
				k++;
			}
		}
		
		ans = 0;
		for (i = 1; tube2[i] != 0; i++){
			if (tube2[i - 1] > tube2[i]){
				ans = 1;
				break;
			}
		}
		
		if (ans == 0){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
		
		n--;
	}
	
	return (0);
}

C++: #include <bits/stdc++.h>

using namespace std;

int a[10];

bool dfs(int i, int l, int r)
{
    if (i == 10) return true;

    if (l < a[i] && dfs(i + 1, a[i], r)) return true;
    if (r < a[i] && dfs(i + 1, l, a[i])) return true;

    return false;
}

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

    while (n--) {
        for (int i = 0; i < 10; ++i) cin >> a[i];
        cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
    }
}

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

using namespace std;

bool solve(vector<int> balls, vector<int> &b,vector<int> &c, int index) {
    
    if (index >= 10) return true;
    if (b.back() < balls[index]) {
        b.push_back(balls[index]);
        index++;
        return solve(balls, b, c, index);
    }
    if (c.back() < balls[index]) {
        c.push_back(balls[index]);
        index++;
        return solve(balls, b, c, index);
    }
    return false;
}

int main(){
    int N;
    cin >> N;
    bool flag;
    vector<vector<int> > balls(N, vector<int>(10));
    
    for (int j = 0; j < N; j++) {
        for (int i = 0; i < 10; i++) {
            cin >> balls[j][i];
        }
    }
    for (int j = 0; j < N; j++) {
        vector<int> b, c;
        b.push_back(0);
        c.push_back(0);
        flag = solve(balls[j], b, c, 0);
        if (flag) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int t;
  cin >> t;
  int n[10];
  for(int i=0;i<t;i++){
    int h = 0,b = 0,c = 0;
    for(int j=0;j<10;j++) cin >> n[i]; 
    for(int j=0;j<10;j++){
      cin >> n[i];
      if(b==0) b = n[i];
      else if(b>c&&b<n) b = n[i];
      else if(c>b&&c<n) c = n[i];
      else if(b>c&&b>n&&c<n) c = n[i];
      else if(c>b&&c>n&&b<n) b = n[i];
      else if(b>n[i]&&c>n[i]){
	cout << "NO" << endl;
	h = 1;
	break;
      }
    }
    if(h==0) cout << "YES" << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;
int main()
{
	//freopen("3.txt","r",stdin);
	int n;
	cin >> n;
	int a[11];
	int b[2];
	int flag;
	b[0]=0;
	b[1]=0;
	while(n--)
	{
		flag=1;
		for(int i=0;i<10;i++)
			{
				cin >> a[i];
				sort(b,b+2);
				if(a[i]>b[1])
				{
					b[1]=a[i];
				}
				else if(a[i]<b[1]&&a[i]>b[0])
				{
					b[0]=a[i];
				}
				else if(a[i]<b[0])
					{
						flag=0;
					}
			}
		if(flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
 }
 return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int a=0,b=0;
  int c=0;
  cin>>c;
  for(int i=0;i<c;i++){
    a=0;
    b=0;
    for(int i=0;i<10;i++){
      int t;
      cin>>t;
      if(t<a&&t<b){
	cout<<"NO"<<endl;
	break;
      }
      if(a<t)a=t;
      else b=t;
      if(i==9)cout<<"YES"<<endl;
    }
  }
  return 0;
}

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

int n,len,ball[20],used[20];

int f()
{
	int t = -1;
	for (int i=1;i<=10;++i)
		if (!used[i])
		{
			if (ball[i] < t) return 0;
			t = ball[i];
		}
	t = -1;
	for (int i=1;i<=10;++i)
		if (used[i])
		{
			if (ball[i] < t) return 0;
			t = ball[i];	
		}
	return 1;
}

int dfs(int x,int l)
{
	if (l == len) return f();
	for (int i=x+1;i<=10;++i)
		if (!used[i])
		{
			used[i] = 1;
			if (dfs(i,l+1)) return 1;
			used[i] = 0;
		}
	return 0;
}

int main()
{
//	freopen("in.txt","r",stdin);
	cin>>n; 
	while (n--)
	{
		int flag = 0;
		for (int i=1;i<=10;++i) cin>>ball[i];
		for (int i=0;i<=5;++i)
		{
			memset(used,0,sizeof(used));
			len = i;
			if (dfs(0,0)) 
			{
				flag = 1;
				break;
			}
		}
		if (flag) cout<<"YES";
		else cout<<"NO";
		puts("");
	}
	return 0;
}

C++: #include <stdio.h>
#include <stdbool.h>
int balls[10];
int left[10],right[10],l=0,r=0,det;
void solve();
void dfs(int depth);
bool check();
int main(void){
	int times;
	scanf("%d",&times);
	for(int i=0;i<times;i++){
		for(int j=0;j<10;j++)
			scanf("%d",&balls[j]);
		solve();
	}
	return 0; 
}

void solve(){
	det=0;
	dfs(0);
	if(det)	puts("YES");
	else	puts("NO");
}

void dfs(int depth){
	if(det)	return;
	if(depth==9){
		if(check())	det=1;
		return;
	}
	left[l++]=balls[depth++];
	dfs(depth);
	l--;depth--;
	right[r++]=balls[depth++];
	dfs(depth);
	r--;depth--;
}

bool check(){
	bool m=1,n=1;
	for(int i=0;i<l-1;i++)
		if(left[i]>left[i+1]){
			m=0;
			break;
		}
	for(int i=0;i<r-1;i++)
		if(right[i]>right[i+1]){
			n=0;
			break;
		}
	return m&&n;
}