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>

using namespace std;

int main()
{
	int N;
	cin >> N;
	
	int input[10];
	
	for (int i=0; i<N; i++) {
		for (int j=0; j<10; j++) cin >> input[j];
		
		int a[11] = {0};
		int b[11] = {0};
		
		bool success = true;
		
		for (int j=0, a_top=1, b_top=1; j<10; j++) {
			if (a[a_top-1] < input[j]) a[a_top++] = input[j];
			else if (b[b_top-1] < input[j]) b[b_top++] = input[j];
			else { success = false; break; }
		}
		if (success) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int num[2] = {0};
		int flag = 1;
		for (int j = 0; j < 10; j++) {
			int k;
			cin >> k;
			if (num[0] < k && num[1] < k) {
				num[num[0] < num[1]] = k;
			}
			else if (num[0] < k && num[1] >= k) {
				num[0] = k;
			}
			else if (num[0] >= k && num[1] < k) {
				num[1] = k;
			}
			else {
				flag = 0;
			}
		}
		if (flag) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

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

using namespace std;

int ball_list[10];
int right_list[10];
int left_list[10];

bool flag;

void dfs(int right, int left){
  int count = right + left;

  if(count == 10){
    flag = true;
  }else{
    if(right == 0 || right_list[right-1] < ball_list[count]){
      if(right == 0){
        right_list[0] = ball_list[count];
      }else{
        right_list[right] = ball_list[count];
      }
      dfs(right+1, left);
    }
    if(left == 0 || left_list[left-1] < ball_list[count]){
      if(left == 0){
        left_list[0] = ball_list[count];
      }else{
        left_list[left] = ball_list[count];
      }
      dfs(right, left+1);
    }
  }
}

int main(){
  int n;

  cin >> n;

  for(int i = 0; i < n; i++){
    flag = false;
    memset(right_list, 0, sizeof(right_list));
    memset(left_list, 0, sizeof(left_list));

    for(int j = 0; j < 10; j++){
      cin >> ball_list[j];
    }
    
    dfs(0, 0);

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

  return 0;
}

C++: #include <stdio.h>

int n;
int data[10];
int ans[100];

bool solve(int i, int l, int r){
  if(i==10)
    return true;
  if(data[i] > l)
    return solve(i+1,data[i],r);
  if(data[i] > r)
    return solve(i+1,l,data[i]);
  return false;
}
int main(){
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 10; j++){
      scanf("%d", &data[j]);
      if(solve(0,0,0)){
        ans[i] = 1;
      }else{
        ans[i] = 0;
      }
    }
  }
  for(int i = 0; i < n; i++){
    if(ans[i])
      printf("YES\n");
    else
      printf("NO\n");
  }
}

C++: #include<cstdio>
#include<cstring>
int in[12],a[12],b[12];
int dfs(int *a, int cur_a, int *b, int cur_b, int cur)
{
    if(cur == 10) return 1;
    int yes = 0;
    if(cur_a < 9 && (!cur_a || in[cur] > a[cur_a-1])){
        a[cur_a] = in[cur];
        if(dfs(a,cur_a+1,b,cur_b,cur+1)) return 1;
    }
    if(cur_b < 9 && (!cur_b || in[cur] > b[cur_b-1])){
        b[cur_a] = in[cur];
        if(dfs(a,cur_a,b,cur_b+1,cur+1)) return 1;
    }
    return 0;
}
int main()
{
    int n;
    scanf("%d",&n);
    while(n--){
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for(int i = 0; i < 10; i++)
            scanf("%d",&in[i]);
        if(dfs(a,0,b,0,0)) printf("YES\n");
        else printf("NO\n");
    }
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){
	vector<int> pile1;
	vector<int> pile2;
	int n;
	cin>>n;
	int num[10];
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			cin>>num[j];
		}
		pile1.push_back(num[0]);
		for(int k=1;k<10;k++){
			int a = pile1[pile1.size()-1];
			if(pile2.size() != 0){
				int b = pile2[pile2.size()-1];
				if(num[k]>a) pile1.push_back(num[k]);
				else if(num[k]>b) pile2.push_back(num[k]);
				else{
					cout<<"NO"<<endl;
					break;
				}
			}else{
				if(num[k]>a) pile1.push_back(num[k]);
				else pile2.push_back(num[k]); 
			}
			if(k==9) cout<<"YES"<<endl;
		}
	}
	return 0;
}

C++: #include <cstdio>
int a;
int main(void){
    int n;
    scanf("%d",&n);

    for(int i=1;i<=n;i++){
        int b=-1,c=-1;
        bool flag=0;
        for(int j=1;j<=10;j++){
            scanf("%d",&a);
            if(b<a&&c<a&&!flag){
                if(b<c){
                    c=a;
                }
                else{
                    b=a;
                }
            }
            else if(b<a&&c>a&&!flag){
                b=a;
            }
            else if(b>a&&c<a&&!flag){
                c=a;
            }
            else{
                    flag=1;
                continue;
            }
        }
        if(flag) printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}

C++: #include<stdio.h>

int b=0,c=0;

int unname(int *ball,int i)
{
	if(i==10) return 1;
	if(c<ball[i]){
		c=ball[i];
		i++;
		return unname(ball,i);
	}
	if(b<ball[i]){
		b=ball[i];
		i++;
		return unname(ball,i);
	}
	return 0;
}

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

C++: #include<iostream>
using namespace std;
#define MAX_N 100
#define MIN_N -10000000
int N;
int A[MAX_N][10];
int B = MIN_N, C = MIN_N;
int count;
bool b;

void solve(int i){ 
    if(count >= 10){//结束条件 
        return;
	}
	if(B > A[i][count] && C > A[i][count]){//不满足条件 
		b = false;
		return;
	}
	if(B < A[i][count] && C > A[i][count]){//大于B小于C 
		B = A[i][count];
		count++;
		solve(i);
	}
	if(B > A[i][count] && C < A[i][count]){//大于C小于B 
		C = A[i][count];
		count++;
		solve(i);
	}
	if(B <= A[i][count] && C <= A[i][count]){//比B和C任意中数字还要大 ，放在数字大的那边 
		if(B >= C){
			B = A[i][count];
		}
		else{
			C = A[i][count];
		}
		count++;
		solve(i);
	}
}
int main(){
	while(cin>>N && N != 0){
		for(int i = 0;i < N;i++){
			for(int j = 0;j < 10;j++){
				cin>>A[i][j];
			}
		}
		for(int i = 0;i < N;i++){
			b = true;
			count = 0;
		    solve(i); 
		    if(b){
			    cout<<"YES"<<endl; 
		    }
	    	else{
			    cout<<"NO"<<endl;
		    }
    	}
	}
}