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 a[10];
int n;
 
bool dfs(int i,int left,int right){
    if(i==10) return true;
    if(a[i]>left){
        if(dfs(i+1,a[i],right)) return true;
    }
    if(a[i]>right){
        if(dfs(i+1,left,a[i])) return true;
    }
    return false;
}
 
void solve(){
    for(int i=0;i<10;i++) cin >> a[i];
    if(dfs(0,0,0)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return;
}
 
int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        solve();
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int bfs(int, int, int);
int a[10];
int main(void){

	int n;

	cin >> n;
	for (int n_count = 0; n_count < n; n_count++){

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

			cin >> a[i];
		}

		if (bfs(0, 0, 0) == 1)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
}

int bfs(int i, int l, int r){

	int ans = 0;

	if (i == 10)
		ans = 1;

	if (l < a[i])
		ans = bfs(i + 1, a[i], r);

	if (r < a[i])
		ans = bfs(i + 1, l, a[i]);

	return ans;
}

C++: //???1601-2 ????±????(616342287) 12:28:09
#include <iostream>
#include <fstream>
#include <stack>
#include <vector>
#include <cstring>
using namespace std;
int a[11];
int b[11];
int c[11];
int flag;
void dfs(int x,int y,int z)
{
  if(x==10)
  {
    flag=1;
    return;
  }
  if(a[x]<b[y]&&a[x]<c[z])
      return;
  if(a[x]>b[y])
  {
      b[y+1]=a[x];
      dfs(x+1,y+1,z);
      b[y+1]=0; 
  }
  if(a[x]>c[z])
  {
      c[z+1]=a[x];
      dfs(x+1,y,z+1);
      c[z+1]=0; 
  }
}
int main()
{
//  freopen("3.txt","r",stdin);
  int n;
  cin >> n;
  while(n--)
  {
  flag=0;
  memset(b,0,sizeof(b));
  memset(c,0,sizeof(c));
  for(int i=0;i<10;i++)
      cin >> a[i];
  dfs(0,0,0);
  if(flag)
      cout << "YES" << endl;
  else
      cout << "NO" << endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
  int n, num, count, before;

  cin >> n;

  for(int i = 0; i < n; i++){
    count = 0;
    before = 0;
    for(int j = 0; j < 10; j++){
      cin >> num;
      if(num < before){
        count++;
        if(count >= 2){
          cout << "NO" << endl;
          break;
        }
      }else{
        count = 0;
      }
      before = num;
    }
    if(count < 2) cout << "YES" << endl;
  }

  return 0;
}

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

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int bTop = 0, cTop = 0;
        for (int j = 0; j < 10; j++) {
            int input;
            cin >> input;
            if (bTop >= cTop) {
                if (input > bTop) {
                    bTop = input;
                } else if (input > cTop) {
                    cTop = input;
                } else {
                    cout << "NO" << endl;
                    break;
                }
            } else {
                if (input > cTop) {
                    cTop = input;
                } else if (input > bTop) {
                    bTop = input;
                } else {
                    cout << "NO" << endl;
                    break;
                }
            }
            if (j == 9) {
                cout << "YES" << endl;
            }
        }
    }
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>

using namespace std;
typedef long long ll;


int a[10];

bool put(int cur,int lt, int rt) {
	if (cur == 10)
		return true;
	if (a[cur] < lt && a[cur] < rt)
		return false;
	bool lres= false,rres=false;
	if( a[cur] > lt) {
		lres = put(cur + 1, a[cur], rt);
	}
	if( a[cur] > rt) {
		rres = put(cur + 1, lt, a[cur]);
	}
	if (lres || rres)
		return true;
	else
		return false;
}

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

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int a[10];
bool ans;

void dfs(int idx, int l, int r) {
   if (idx == 10) {
      ans = true;
      return;
   }

   int val = a[idx];
   if (l < val) dfs(idx+1, val, r);
   if (r < val) dfs(idx+1, l, val);
}

int main() {
   int N;
   cin >> N;
   while (N--) {
      for (int i = 0; i < 10; i++) {
         cin >> a[i];
      }
      ans = false;
      dfs(0, -1, -1);
      puts(ans ? "YES" : "NO");
   }

   return 0;
}

C++: #include <iostream>

using namespace std;

int main(void) {
    int N, a, b, c, x[10];
    cin >> N;
    for (; N--; ) {
        bool ok = true;
        for (int i = 0; i < 10; i++) {
            cin >> x[i];
        }
        b = c = 0;
        for (int i = 0; i < 10; i++) {
            a = x[i];
            if (a < b && a < c) {
                ok = false;
                break;
            } else if (a < b) {
                c = a;
            } else if (a < c) {
                b = a;
            } else if (b < c) {
                c = a;
            } else {
                b = a;
            }
        }
        if (ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #include <stdio.h>

#include <stack>

int main(void){
    using namespace std;
    stack<int> a,b;
    int n,j,i,ball,flag;
    scanf("%d",&n);
    for(j=0; j<n; j++){
        flag=0;
        for(i=0; i<10; i++){
            scanf("%d",&ball);
            if(a.empty()){
                a.push(ball);
            }else if(a.top() < ball){
                a.push(ball);
            }else if(b.empty()){
                b.push(ball);
            }else if(b.top() < ball){
                b.push(ball);
            }else{
                flag=1;
            }
        }
        while(!a.empty()){
            a.pop();
        }
        while(!b.empty()){
            b.pop();
        }
        if(flag==0){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}

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

using namespace std;

int main() {
	vector<int> left;
	vector<int> right;
	vector<int> all;

	bool flag = true;

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else
							flag = false;
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}

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

	return 0;
}