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<cmath>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<list>


using namespace std;

#define FOR(x) for(int i = 0; i < x; i++)

stack<short> left, right;
short a[10], n;

bool solve(short c, bool judge){
	if(c == 10) return true;
	if(left.top() < a[c]){
		left.push(a[c]);
		if(solve(c + 1, true)) return true;
	}
	if(right.top() < a[c]){
		right.push(a[c]);
		if(solve(c + 1, false)) return true;
	}
	if(judge) left.pop();
	else right.pop();
	return false;
}

int main(){
	scanf("%d", &n);
	FOR(n){
		left.push(0);
		right.push(0);
		for(i = 0; i < 10; i++)
			scanf("%d", &a[i]);
		if(solve(0, true)) printf("YES\n");
		else printf("NO\n");
		while(left.empty()) left.pop();
		while(right.empty()) right.pop();
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <stack>

using namespace std;
const int maxn = 11;
int num[maxn];

int main()
{
    int ite=0;
    scanf("%d", &ite);
    while(ite--)
    {
        for(int i=0; i<10; ++i)
        {
            scanf("%d", &num[i]);
        }

        stack<int> a, b;

        a.push(0);
        b.push(0);
        for(int i=0; i<10; ++i){
            int dif1 = num[i] - a.top(), dif2 = num[i]-b.top();
            if(dif1<0 && dif2<0) {
                printf("NO\n");
                return 0;
            }
            else if(dif1>0 && dif2>0){
                if(a.top()<b.top()) b.push(num[i]);
                else a.push(num[i]);
            }
            else{
                if(dif1>0) a.push(num[i]);
                else b.push(num[i]);
            }
        }

        printf("YES\n");
    }
    return 0;
}

C++: #include<cstdio>

using namespace std;

int ball[10];

bool dfs(int i,int b,int c){
	if(i==10)return true;
	if(ball[i]>b && dfs(i+1,ball[i],c))return true;
	if(ball[i]>c && dfs(i+1,b,ball[i]))return true;
	return false;
}

int main(){
	int lines;
	scanf("%d",&lines);
	for(int i = 0;i<lines;i++){
		for(int j=0;j<10;j++)scanf("%d",&ball[j]);
		if(dfs(0,0,0)){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
}

C++: #include<stdio.h>

int main()
{
	int loop,right,left,data;
	int i,j;
	scanf("%d",&loop);
	while(loop-->0)
	{
		right=left=j=0;
		for(i=0;i<10;i++)
		{
			scanf("%d",&data);
			if(data>right)
				right=data;
			else if(data>left)
				left=data;
			else
				j=1;
		}
		if(j==1)
			printf("NO\n");
		else
			printf("YES\n");
	}
}

C++: #include<cstdio>
#include<cstring>
int ball[11];
int temp[2][11];
bool dfs(int x)
{
	if(x>10)
		return 1;
	if(temp[0][0]==0||temp[0][temp[0][0]]<ball[x])
	{
		temp[0][++temp[0][0]]=ball[x];
		if(dfs(x+1))
			return 1;
		temp[0][0]--;
	}
	if(temp[1][0]==0||temp[1][temp[1][0]]<ball[x])
	{
		temp[1][++temp[1][0]]=ball[x];
		if(dfs(x+1))
			return 1;
		temp[0][0]--;
	}
	return 0;
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		for(int i=1;i<=10;i++)
			scanf("%d",ball+i);
		memset(temp,0,sizeof temp);
		if(dfs(1))
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,a;
  int f = 0;
  int b = 0 ,c = 0;
  cin >> n;
  for(int j = 0;j < n;j++){
    f = 0;
    b = 0;
    c = 0;
    for(int i = 0;i < 10;i++){
      cin >> a;
      if(b < a)b = a;
      else if(c < a)c = a;
      else {
	f = 1;	
      }  
    }
    if(f == 1)cout << "NO" << endl;
    else cout << "YES" << endl;
  }
  return 0;
}

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

using namespace std;

int a[10], b[2][10];
int len[2];
bool ans;


void dfs(int step) {
    if(ans) return;
    if(step == 10){
        ans = true;
    }
    for(int i = 0; i < 2; ++i){
        if(len[i] == 0 || a[step] > b[i][len[i] - 1]){
            b[i][len[i]++] = a[step];
            dfs(step + 1);
            --len[i];
        }
    }
}

void solve() {
    ans = false;
    for(int i = 0; i < 10; ++i) {
        cin >> a[i];
    }
    dfs(0);
}

int main() {
    int T;
    cin >> T;
    while(T--) {
        solve();
        cout << (ans ? "YES" : "NO") << endl;
    }
    return 1;
}

C++: public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] boll = new int[10];
		for(int k = 0; k < n; k++) {
			for(int i = 0; i < 10; i++) {
				boll[i] = scan.nextInt();
			}
			int judg = 0;
			for(int i = 0; i < n; i++) {
				int right,left;
				right = boll[0];
				left = 0;
				for(int m = 1; m < 10; m++) {
					if(right > boll[m]) {
						if(left < boll[m]) {
							left = boll[m];
						}
						else {
							judg = 0;
							break;
						}
					}
					else if(right < boll[m]) {
						right = boll[m];
					}
					judg = 1;
				}
				if(judg == 0) {
					System.out.println("NO");
				}
				else {
					System.out.println("YES");
				}
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

C++: #include <iostream>
using namespace std;
int a[10];

bool dfs(int i,int l,int r){
	if(i>=10)return 1;
	if(l>a[i]&&r>a[i])return 0;
	if(l<a[i]){
		if(dfs(i+1,a[i],r))return 1;
	}
	if(r<a[i]){
		return dfs(i+1,l,a[i]);
	}
	return 0;
}

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

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

int B[11]={0};
int C[11]={0};

bool DFS(int *a,int i=0,int b=1,int c=1)
{
	bool judge=true;

	if(i==10)
		return judge;

	judge=false;

	if(B[b-1]<a[i]){
		B[b]=a[i];
		judge=DFS(a,i+1,b+1,c);
		
	}
	if(C[c-1]<a[i]){
		C[c]=a[i];
		judge=DFS(a,i+1,b,c+1);
		
	}

	return judge;
}        

int main()
{
        int N;
	int i=0;
        cin>>N;

	while(i<N){
	???int A[10];
	???for(int i=0;i<10;i++){
	??? cin>>A[i];
          }

          if(DFS(A)==true){
           cout<<"YES"<<endl;
          }
          else{
           cout<<"NO"<<endl;
          }

	???i++;
        }
                
	
        return 0;
}

C++: #include <cstdio>
using namespace std;
int l[12],r[12],q[12];
bool yon;
void dfs(int i,int j,int k){
	if(i == 10){
		yon = true;
		return ;
	}
	if(q[i] > l[j-1]){
		l[j] = q[i];
		dfs(i+1,j+1,k);
	}
	if(q[i] > r[k-1]){
		r[k] = q[i];
		dfs(i+1,j,k+1);
	}
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--){
		for(int i=1;i<=10;i++){
			scanf("%d",&q[i]);
		}
		yon = false;
		l[0] = -1;
		r[0] = -1;
		dfs(1,1,1);
		if(yon){
			printf("YES\n");
		}else{
			printf("NO\n"); 
		}
	}
	return 0;
}