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 <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>
#include <cstring>
#include <cstdlib>

typedef long long ll;

using namespace std;

int N;
int ball[10];

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

int main(void){
	cin >> N;

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

		for(int j=0; j<10; j++){
			cin >> ball[j];
		}
		if(dfs(0, 0, 0)) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}

	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
int l[12],r[12],q[12];
bool yon;
void dfs(int i,int j,int k){
	if(i == 10){
		yon = true;
		return ;
	}
	if(yon){
		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;
}

C++: #include <iostream>

using namespace std;
const int kBalln = 10;
int main(){
  int n;
  int ball;
  int b, c;
  bool ans;
  cin >> n;
  for (int j = 0; j < n; ++j)
    {
      b = 0; c = 0;ans = true;
      for (int i = 0; i < kBalln; ++i)
        {
          cin >> ball;
          if (b < ball)
            {
              b = ball;
            }
          else if (c < ball)
            {
              c = ball;
            }
          else
            {
              ans = false;
              // cout << "NO" << endl;
              break;
            }
        }
      cout << (ans ? "YES" : "NO") << endl;
    }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
  int n;
  bool success;

  cin >> n;
  while(n--){
    success = false;
    int b = 0, c = 0;
    int a[10];
    for(int i=0; i<10; i++){
      cin >> a[i];
    }

    for(int i=0; i<10; i++){ 
      if(b < a[i] && c < a[i]){
        if(b < c)
          c = a[i];
        else
          b = a[i];
      }
      else if(b < a[i]){
          b = a[i];
      }
      else if(c < a[i]){
          c = a[i];
      }
      else{
        success = false;
        break;
      }

      if(i == 9)
        success = true;
    }

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

C++: #include<cstdio>  
int n,l1,l2,a[15];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
	    bool f=0;l1=-1;l2=0;
		for(int j=1;j<=10;j++)
			scanf("%d",&a[j]);
		for(int j=1;j<=10;j++)
		if(!f)
		{
			if(a[j]<l1&&a[j]<l2){f=1;printf("No\n");break;}
			if(l1>l2){if(a[j]>l1)l1=a[j];else l2=a[j];} 
			else{if(a[j]>l2)l2=a[j];else l1=a[j];}
		}
		if(!f)printf("YES\n");a
	}
}

C++: #include<stdio.h>
#include<string.h>
int l[15],r[15],q[15];
bool yon;
void dfs(int i,int j,int k){
	if(i == 10){
		yon = true;
		return ;
	}
	if(yon){
		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;
		dfs(1,1,1);
		if(yon){
			printf("YES\n");
		}else{
			printf("NO\n"); 
		}
	}
	return 0;
}

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


int main()
{
	int n;
	cin >> n;
	int a[11];
	while (n--)
	{
		bool flag = true;
		int min_a = 0, min_b = 0;
		for (int i = 0; i < 10; i++)
			cin >> a[i];
		for (int j = 0; j < 10; j++)
		{
			if (a[j] > min_a)
			{
				if (min_a >= min_b)
				{
					min_a = a[j];
				}
				else
				{
					min_b = a[j];
				}
				continue;
			}
			else if (a[j] > min_b)
			{
				min_b = a[j];
			}
			else
			{
				flag = false;
				break;
			}
		}
		if (flag==true)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
    return 0;
}

C++: #include<iostream>
main(){int n,i,A,B,C;for(std::cin>>n;n-->0;puts(C-11?"YES":"NO"))for(B=C=i=0;i++<10;){std::cin>>A;if(B<A)B=A;else C=C<A?A:11;}}

C++: #include<iostream>
using namespace std;
int main(){
	int row[2],order[10],memo[10][2],n;
	cin >>n;
	for(int i=0; i<n; i++){
		for(int l=0; l<10; l++){
			cin >>order[l];
		}
		row[0] = order[0];
		row[1] = 0;
		int x = 0,l;
		for(l=1; l<10; l++){
			if(row[0]<order[l] && row[1]>order[l]){row[0] = order[l];}
			else if(row[0]>order[l] && row[1]<order[l]){row[1] = order[l];}
			else if(row[0]<order[l] && row[1]<order[l]){
				memo[x][0] = row[0];
				memo[x][1] = l;
				row[0] = order[l];
				x++;
			}
			else if(row[0]>order[l] && row[1]>order[l]){
				if(x == 0){cout <<"NO"<<endl;break;}
				else{
					x--;
					row[0] = memo[x][2];
					l = memo[x][1];
					row[1] = order[l];
				}
			}
		}
		if(l == 10){cout <<"YES"<<endl;}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
int ball[10];
int left = 0,right = 0;
bool dfs(int de,int left, int right){//??????????????§???????????????
	if(de == 9)return true;
	if(left < ball[de]){
		left = ball[de];
		return dfs(de + 1,left,right);
	}
	if(right < ball[de]){
		right = ball[de];
		return dfs(de + 1,left,right);
	}
	return false;
}

int main(){
	int n;
	std::cin >> n;
	while(n--){
		for(int i = 0; i < 10; ++i){
			std::cin >> ball[i];
		}
		left = 0, right = 0;
		if(dfs(0,0,0))std::cout << "YES" << std::endl;
		else std::cout << "NO" << std::endl;
	}
}

C++: #include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
int N, acnt, bcnt;
int x[10], A[10], B[10];

bool dfs(int cnt) {
    if (cnt == 10) return true;
    // Aに入れる
    if (A[acnt] < x[cnt]) {
        A[++acnt] = x[cnt];
        return dfs(cnt+1);
    }
    // Bに入れる
    else if (B[bcnt] < x[cnt]) {
        B[++bcnt] = x[cnt];
        return dfs(cnt+1);
    }
    return false;
}

int main(void) {
    cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 10; j++) {
            A[j] = 0; B[j] = 0;
        }
        acnt = 0; bcnt = 0;
        for (int j = 0; j < 10; j++) cin >> x[j];
        if (dfs(0)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}