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 <vector>

using namespace std;

int  s[10];

int main()
{
	//freopen("in.txt", "r", stdin);

	int case_t, case_num;
	scanf("%d", &case_num);
	for (case_t=1; case_t<=case_num; case_t++) {
		int i;
		for (i=0; i<10; i++)
			scanf("%d", &s[i]);

		int min1 = -1, min2 = -1;

		for (i=0; i<10; i++) {
			if (s[i]<min1 && s[i]<min2)
				break;
			if (s[i]>min1 && s[i]>min2) {
				if (min1 < min2)
					min2 = s[i];
				else
					min1 = s[i];
			}
			else if (s[i]>min1)
				min1 = s[i];
			else
				min2 = s[i];

		}
		if (i<10) printf("NO\n");
		else printf("YES\n");


	}

	return 0;
}

C++: #include<stdio.h>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

bool flag = true;

void solve(queue<int> left, queue<int> right, queue<int> all) {
	if (all.size() > 0) {
		if (left.size() > 0) {
			if (all.front() > left.back()) {
				left.push(all.front());
				all.pop();
				solve(left, right, all);
			}
			else {
				if (right.size() > 0) {
					if (all.front() > right.back()) {
						right.push(all.front());
						all.pop();
						solve(left, right, all);
					}
					else if(all.size() == 0){
					
					}
					else {
						flag = false;
					}
				}
				else {
					right.push(all.front());
					all.pop();
					solve(left, right, all);
				}
			}
		}
		else {
			left.push(all.front());
			all.pop();
			solve(left, right, all);
		}
	}
}

int main() {

	int n;
	cin >> n;
	for (; n > 0; n--) {
		queue<int> all;
		queue<int> left;
		queue<int> right;
		for (int i = 0; i < 10; i++) {
			int temp;
			cin >> temp;
			all.push(temp);
		}
		solve(left, right, all);
		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}



	
				   
}

C++: #include <cstdio>
#include <stack>
#define NUM 10
using namespace std;

int N;


int main()
{
	//freopen("in","r",stdin);
	scanf("%d",&N);
	while(N--){
		int tmp;
		bool sol=true;
		stack<int> B,C;
		for(int i=0;i<NUM;i++){
			
			scanf("%d",&tmp);
			if(B.empty())
				B.push(tmp);
			else if(tmp>B.top())
				B.push(tmp);
			else if(C.empty())
				C.push(tmp);
			else if(tmp>C.top())
				C.push(tmp);
			else
				sol = false;
		}
		if(sol)
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}

C++: #include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

vector<int> v(10);

int l,r;
int flag;

void dfs(int d){

    if(d==10){
        flag=1;
        return;
    }

    if(flag) return;

    int x = v[d];

    if(x>l){

        int tmp = l;
        l=x;
        dfs(d+1);
        l=tmp;

    }

    if(flag) return;

    if(x>r){

        int tmp = r;
        r=x;
        dfs(d+1);
        r = tmp;

    }

}

int main(){

    int N;

    cin >> N;

    for(int t=0;t<N;++t){

        for(int i=0;i<10;++i)cin >> v[i];

        l = r = flag = 0;

        dfs(0);

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

    }

    return 0;

}

C++: #include<iostream>
using namespace std;
int main(void)
{
int n;
cin>>n;

for(int i=0;i<n;i++)
{
	int a[10]={0};
	for(int j=0;j<10;j++)
	{
	int x;
	cin>>x;
	a[j]=x;
	}
	int b=a[0],c=a[0],k;
		for(k=1;k<10;k++)
		{
			if(b<a[k])b=a[k];
			else if(c<a[k])c=a[k];
			else 
			{
			cout<<"NO"<<endl;
			break;
			}
		}
		if(k==10)cout<<"YES"<<endl;
	/*for(int i=0;i<10;i++)
	{
	cout<<b[i]<<" ";

	}
	cout<<endl;
	for(int i=0;i<10;i++)
	{
	cout<<c[i]<<" ";
	}
	for(int i=0;i<10-1;i++)
	{
		if(b[i]>b[i+1] && b[i+1]!=0 || c[i]>c[i+1] && c[i+1]!=0)
		{
		cout<<"NO"<<endl;
		break;
		}
	else 
		{
		cout<<"YES"<<endl;
		break;
		}
	}*/
}
return 0;
}

C++: #include<algorithm>
#include<stdio.h>
#include<vector>
#include<queue>

using namespace std;

int A[13] = { 0 };

bool solve(int a, int b,int c) {
	if (++c == 10)
		return true;
	else {
		bool r = false;
		if (a < A[c])
			r = solve(A[c], b, c);
		if (b < A[c] && r == false)
			r = solve(a,A[c], c);
		
		return r;
	}
}

int main(void) {
	A[10] = A[11] = A[12] = 100;
	int n = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++)
			scanf("%d", &A[j]);
		if (solve(A[0], 0, 0))
			printf("YES\n");
		else
			printf("NO\n");
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

bool flag;
int a[10], b[10], c[10];

void dfs(int ap, int bp, int cp){
  
  // cout << ap << ' ' << bp << ' ' << cp << endl;

  if(ap == 10){
    flag = true;
    return;
  }

  if(ap < 2){
    if(ap){
      b[0] = a[ap];
      dfs(ap + 1, bp + 1, cp);
      b[bp] = 0;
    }
    else{
      c[0] = a[ap];
      dfs(ap + 1, bp, cp + 1);
      c[cp] = 0;
    }
  }
  else{

    if(a[ap] > b[bp - 1]){
      b[bp] = a[ap];
      dfs(ap + 1, bp + 1, cp);
      b[bp] = 0;
    }
    
    if(a[ap] > c[cp - 1]){
      c[cp] = a[ap];
      dfs(ap + 1, bp, cp + 1);
      c[cp] = 0;
    }

  }

  return;

}

int main(){

  int n;

  cin >> n;

  for(int i = 0; i < n; ++i){
    
    flag = false;

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

    cout << (flag ? "YES" : "NO") << endl;

  }

}

C++: #include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
int a[10];
for(int j=0;j<10;j++)scanf("%d",&a[i]);
bool ans=true;
for(int j=0;j<10;j++){
for(int k=j+1;k<10;k++){
for(int l=k+1;l<10;l++){
if(a[j]>a[k]&&a[k]>a[l])ans=false;
}
}
}
if(ans)printf("YES\n");
else printf("NO\n");
}
return 0;
}

C++: #include <cstdio>

using namespace std;

int ball[10];

bool dfs(int left, int right, int n) {
  if (n == 10) return true;
  return ((left < ball[n]) && dfs(ball[n], right, n + 1)) ||
    ((right < ball[n]) && dfs(left, ball[n], n + 1));
}

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

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

    if (dfs(0, 0, 0)) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
  
  return 0;
}

C++: using namespace std;

#include <cstdio>

int a[10];

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

int main(){
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			scanf("%d", &a[j]);
		}
		printf("%s\n", dfs(0, 0, 0) ? "YES" : "NO");
	}
	return 0;
}

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

int value[10];

string dfs(int left,int right,int i)
{
	if(i == 10) return "YES";
	if(left < value[i])
	{
		return dfs(value[i],right,i+1);
	}
	if(right < value[i])
	{
		return dfs(left,value[i],i+1);
	}
	return "NO";
}


int main()
{
	int n;
	cin >> n;
	
	while(n--)
	{
		for(int i=0;i<10;i++)	
		{
			cin >> value[i];	
		}
		cout << dfs(0,0,0) << endl;
	}

	return 0;
}