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 <algorithm>
using namespace std;

int ary[20];
int main(){
	int N,b=0,c=0;
	cin>>N;
	for(int i=1;i<=N;i++){
		b=c=0;
		for(int j=1;j<=10;j++){
			cin>>ary[j];
		}
		bool fla=true;
		for(int j=1;j<=10;j++){
			if(b<c) swap(b,c);
			if(ary[j]>b) b=ary[j];
			else if(ary[j]>c) c=ary[j];
			else{
				fla=false;
				break;
			}
		}
		if(fla) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int ch[12],one,two=0,g,q;

int DFS(int g){
if(g == 10)
    {
        q=0;
        return 1;
    }
else
{
    for(int i = g; i < 10; i++){
            if(q==0)return 1;
            if(ch[i] > one)
                {
                    one = ch[i];
                    DFS(i+1);
                }
            else if( ch[i] > two)
                {
                    two = ch[i];
                    DFS(i+1);
                }
            else if(ch[i] < two && ch[i] < one)
                {
                    return 0;
                }
    }
return 0;
}
}
int main()
{
    int n;
    cin >> n;
    while(n--){
     for(int i = 0; i < 10; i++)
        cin >> ch[i];
     one = ch[0];
     q=1;
     if(DFS(1)) cout << "Yes" << endl;
     else cout << "NO" << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <algorithm>
#define HEIGHT 10

using namespace std;

int a[HEIGHT];

void solve(){
	bool f=true;
	int right,left;
	right = left = 0;
	for(int i=0;i<HEIGHT;i++){
		if(right<a[i] && left<a[i]){
			if(right<left){
				left = a[i];
			} else {
				right = a[i];
			}
		} else if(right<a[i]){
			right = a[i];
		} else if(left<a[i]){
			left = a[i];
		} else {
			f = false;
			break;
		}
	}
	if(f) printf("Yes\n");
	else printf("No\n");
}
			
int main(){
	
	int lp;
	scanf("%d",&lp);
	
	for(int i=0;i<lp;i++){
		for(int j=0;j<HEIGHT;j++){
			scanf(" %d",&a[j]);
		}
		solve();	
	}
	return 0;
}

C++: #include <stdio.h>

int a[10];
int flag;

void dfs(int b_top,int c_top,int num) {

  if(num==10) {

    flag=1;
    return;

  }

  if(b_top<a[num]) dfs(a[num],c_top,num+1);

  if(c_top<a[num]) dfs(b_top,a[num],num+1);

  return;

}

int main(void) {

  int n;

  int i;


  scanf("%d",&n);

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

    scanf("%d %d %d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);

    flag=0;

    dfs(0,0,0);

    if(flag==1) printf("YES\n");
    else printf("NO\n");

  }

  return 0;

}

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

int main() {
	int n, x, z;
	cin >> n;

	for (int i = 0; i < n; i++) {
		vector< vector<int> > v{ {0} };
		for (int j = 0; j < 10; j++) {
			cin >> x;
			z = v.size();
			for (int k = 0; k < z; k++) {
				if (v[k].back() < x) {
					v[k].push_back(x);
					break;
				}

				if (k == z - 1) {
					v.push_back({ x });
					break;
				}
			}

			if (v.size() == 3) {
				x = -1;
				break;
			}
		}

		if (x == -1) {
			cout << "NO";
		}
		else {
			cout << "YES";
		}
		cout << endl;
	}
	return 0;
}

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

bool f(void){
	int x[10], a=0, b=0;
	for (int i=0; i<10;i++)
		cin>>x[i];
	for (int i=0; i<10; i++){
		int e=x[i];
		if (e>a) a=e;
		else if (e>b) b=e;
		else return false;
	}
	return true;
}

int main(void){

	int n;
	cin>>n;
	while (n--){
		if (f()) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include<cstdio>

#define INF 0x7fffffff
int T;
int A[12];

int main()
{
	scanf("%d",&T);
	while(T--)
	{
		for(int i=1;i<=10;i++)
			scanf("%d",&A[i]);
		int x=INF,y=INF;
		bool f=1;
		for(int i=10;i>=1;i--)
		{
			if(A[i]>x&&A[i]>y)
			{
				f=0;
				break;
			}
			if(A[i]<x)
				x=A[i];
			else
				y=A[i];
		}
		if(f) printf("YES\n");
		else printf("NO\n");
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int kuru[10];
bool solve(int l,int r,int co,int now);
int main(){
  int n;
  cin>>n;
  while(n--){
    for(int i=0;i<10;i++){
      cin>>kuru[i];
    }
    if(solve(0,0,0,0))cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}
bool solve(int l,int r,int co,int now){
  if(co==10)return true;
  if(l<kuru[now]){
    if(solve(kuru[now],r,co+1,now+1))return true;
    else return false;
  }
  if(r<kuru[now]){
    if(solve(l,kuru[now],co+1,now+1))return true;
    else return false;
  }
  else if(r>kuru[now] && l>kuru[now])return false;
}

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


bool saiki(int ball[],int ttB,int ttC,int res){
	if(res==10)return true;
	if(ball[res]>ttB){
		return saiki(ball,ball[res],ttC,res+1);
	}
	if(ball[res]>ttC){
		return saiki(ball,ttB,ball[res],res+1);
	}
	return false;
}

int main(void){
	int a,b;
	int ball[11];
	int ttB=0,ttC=0;
	int res=0;
	int n;
	scanf("%d",&n);
	for(a=0;a<n;a++){
		memset(ball,0,sizeof(ball));
		ttB=0;
		ttC=0;
		res=0;
		for(b=0;b<10;b++){
			scanf("%d",&ball[b]);
		}
		if(saiki(ball,ttB,ttC,res)==true)printf("Yes\n");else printf("No\n");
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pi acos(-1)
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define rep(i,x,n) for(int i=x;i<n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
using namespace std;
typedef pair<int,int>P;
const int MAXN=100010;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int a[12],b[12],cnt,book[12];
bool flag;
void dfs(int k)
{
	if(k == 11)
	{
		int last = 0;
		for(int i=1;i<=10;i++)
		{
			if(!book[i])
			{
				if(a[i] < last)
				return ;
				last = a[i];
			}
		}
		flag = 1;
		return ;
	}
	for(int i=k+1;i<=10;i++)
	{
		if(a[i] > b[cnt - 1])
		{
			book[i] = 1;
			dfs(i+1);
			book[i] = 0;
		}
	}
}
int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		for(int i=1;i<=10;i++)
		cin >> a[i];
		for(int i=1;i<=10;i++)
		{
			cnt = 1;
			dfs(i);
			if(flag)
			{
				cout << "YES\n";
				break;
			}
		}
		if(!flag)
		cout << "NO\n";
		flag = 0;
	}
 	return 0;
}

C++: #include <cstdio>

const int N_BALL = 10;

int balls[N_BALL];

bool solve(int l_top, int r_top, int n) {
  if (n == N_BALL) return true;

  int l_top_ = balls[n];
  if (l_top > l_top_) return false;
  if (solve(l_top_, r_top, n+1)) return true;

  int r_top_ = balls[n];
  if (r_top > r_top_) return false;
  if (solve(l_top, r_top_, n+1)) return true;

  return false;
}

int main() {
  int N;
  scanf("%d", &N);

  for (int i = 0; i < N; i++) {
    for (int bi = 0; bi < N_BALL; bi++) scanf("%d", &balls[bi]);

    if (solve(-1, -1, 0)) printf("YES\n");
    else printf("NO\n");
  }

  return 0;
}