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>
#include <tuple>
using namespace std;
 
int main() {
    int n, balls[10]; cin >> n;
    while(n--){
        for(int i = 0; i < 10; i++) cin >> balls[i];
         
        enum {IDX, B, C};
        stack<tuple<int, int, int> > states;

        bool sortable = false;
        states.push(make_tuple(0,0,0));
        while(!states.empty()){
            tuple<int, int, int> now = states.top();
            states.pop();

            int idx = get<IDX>(now);
            if(idx < 10){
                if(get<B>(now) < balls[idx]){
                    if(idx == 9){
                        sortable = true; break;
                    }
                    states.push(make_tuple(idx+1,balls[idx],get<C>(now)));
                }
                if(get<C>(now) < balls[idx]){
                    if(idx == 9){
                        sortable = true; break;
                    }
                    states.push(make_tuple(idx+1,get<B>(now),balls[idx]));
                }
            }
        }

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

C++: #include <stdio.h>
#include <iostream>

using namespace std;

int n;
int data[11];
int l,r;
bool fla;

void solve(){
    scanf("%d",&n);
    while(n--){

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

        l = 0;
        r = 0;
        fla = true;

        for(int i = 1; i <= 10; i++){
            if(data[i] > l && data[i] > r){
                if(l > r){
                    l = data[i];
                }else{
                    r = data[i];
                }
            }else if(data[i] > l && data[i] < r){
                l = data[i];
            }else if(data[i] > r && data[i] < l){
                r = data[i];
            }else{
                fla = false;
                break;
            }
        }

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

    }
}

int main(void){

    solve();

    return 0;
}

C++: #include <cstdio>

int b[13];

int main()
{
	int n;
	int l=0,r=0,i=0;
	int flag=true;
	scanf("%d",&n);
	++n;
	while (--n)
	{
		for (i=0;i<10;++i)
		{		
			scanf("%d",b+i);
			if (b[i]<l&&b[i]<r)
			{
				printf("NO\n");
				flag=false;
				break;
			}
			else if (b[i]>l&&b[i]<r)
			{
				l=b[i];
			}
			else if (b[i]<l&&b[i]>r)
			{
				r=b[i];
			}
			else if (b[i]>l&&b[i]>r)
			{
				if(b[i]-r>b[i]-l)
				{
					l=b[i];
				}
				else
				{
					r=b[i];
				}
			}
			else
			{
				printf("NO\n");
				flag=false;
				break;
			}
// 			printf("%d~ l,r=%d,%d\n",i,l,r);
		}
		if (flag)
		{
			printf("YES\n");
		}
		else
		{
			++i;
			while (i<10)//跳&#35835;！！
			{
				scanf("%d",b+i);
				++i;
			}
		}
		flag=true;
		l=r=0;
	}
	return 0;
	

}

C++: #include <iostream>

using namespace std;

int main()
{
    int n;
    int a1, a2, b1, b2;

    cin >> n;
    for (int i = 0; i < n; i++) {
        bool ck = true;

        cin >> a1 >> b1;
        for (int j = 0; j < 4; j++) {
            cin >> a2 >> b2;

            if (a2 < a1 || b2 < b1) {
                ck = false;
                break;
            }
            a1 = a2;
            b1 = b2;

        }

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

    return 0;
}

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

int main() {
	int n1=0,n2=0,num,temp,flg=1;
	cin>>num;
	while(num--){
		for(int i=0;i<10;i++){
			cin>>temp;
			if(temp<n1&&temp<n2) flg=0;
			if(temp>n1) n1=temp;
			else if(temp>n2) n2=temp;
		}if(flg==1) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
int main(void)
{
	int n,i,j;
	stack<int>s1,s2;
	int table[10];
	cin >> n;
	for(i=0;i<n;i++)
	{
		for(j=0;j<10;j++)
		{
			cin >> table[j];
		}
		s1.push(0);
		s2.push(0);
		for(j=0;j<10;j++)
		{
			if(s1.top()<table[j])
			{
				if(s2.top()<table[j])
				{
					if(s1.top()>s2.top())
					{
						s1.push(table[j]);
					}
					else
					{
						s2.push(table[j]);
					}
				}
				else
				{
					s1.push(table[j]);
				}
			}
			else
			{
				break;
			}
		}
		if(j==10)cout <<"YES"<< endl;
		else cout << "NO" << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
bool canbe = false;
int inp[10];

void dfs(int b, int c, int depth){
    if (depth >= 10){
	canbe = true; return;
    }
    if (inp[depth] < b && inp[depth] < c) return;

    if (inp[depth] > b) dfs(inp[depth], c, depth+1);
    if (inp[depth] > c) dfs(b, inp[depth], depth+1);
}


int n;
int main(){
    cin >> n;
    for (int i = 0; i < n; i++){
	canbe = false;
	for (int j = 0; j < 10; j++) cin >> inp[j];
	
	dfs(0, 0, 0);

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

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

int inp[10];
int n;
bool canbe = false;

void dfs(int b, int c, int depth) {
  if (depth >= 10) {
    canbe = true; return;
  }
  if (inp[depth] < b && inp[depth] < c) return;
  if (inp[depth] > b) dfs(inp[depth], c, depth+1);
  if (inp[depth] > c) dfs(b, inp[depth], depth+1);
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    canbe = false;
    for (int j = 0; j < 10; j++) cin >> inp[j];
    dfs(0,0,0);
    cout << (canbe ? "YES": "NO") << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 99999999
using namespace std;
typedef long long ll;
const int MAXN=1e9+10;
const int MAX=100+10;
int s[MAX];
int tag;
stack<int>l,r;
void dfs(int flag){
	if(tag)	return;
	if(flag==9){
		tag=1;
		return;
	}
	if(s[flag]>l.top()){
		l.push(s[flag]);
		dfs(flag+1);
		l.pop();
	}
	if(s[flag]>r.top()){
		r.push(s[flag]);
		dfs(flag+1);
		r.pop();
	}
}
int main(){
   #ifdef SIYU
   freopen("in.txt","r",stdin);
   #endif // SIYU
   //ios::sync_with_stdio(false);
   int T;
   cin>>T;
   while(T--){
   		for(int i=0;i<10;i++){
   			cin>>s[i];
   		}
   		tag=0;
   		l.push(0);
   		r.push(0);
   		dfs(0);
   		if(tag)
   			cout<<"YES"<<endl;
   		else
   			cout<<"NO"<<endl;
   }
   return 0;
}

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

int main()
{
int n;
scanf("%d", &n);
for(int testcase = 0; testcase < n; ++testcase) {
bool yes = false;
int s = 10;
vector<int> x;
x.resize(s);
for(int i = 0; i < s; ++i)
scanf("%d", &x[i]);
for(int bit = 0; bit < (1 << s); ++bit) {
bool valid = true;
for(int lr = 0; lr < 2; ++lr) {
int prev = -100;
for(int i = 0; i < s; ++i) {
if(((bit >> i) & 1) == lr) {
if(prev >= x[i]) {
valid = false;
break;
}
prev = x[i];
}
}
}
if(valid) {
yes = true;
break;
}
}
printf("%s\n", yes ? "YES" : "NO");
}
return 0;
}