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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  cin >> n;
  while(n--) {
    int s=0,t=0;
    int i;
    for (i=0;i<10;i++) {
      int a;
      cin >> a;
      if (a>s)
        s=a;
      else if (a>t)
        t=a;
      else
        break;
    }
    if (i==10)
      cout << "YES" << endl;
    else
      cout <<"NO" <<endl;
  }
}

C++: #include <iostream>
using namespace std;
int main(void){
    int N, x, b, c, cnt;
    cin >> N;
    while(N != 0){
        b = 0;
        c = 0;
        cnt = 0;
        for(int i = 0; i < 10; i++){
            cin >> x;
            if(x > b){
                b = x;
                cnt++;    
            }   
            else if(x > c){
                c = x;
                cnt++;   
            }
            else break;
        }
        if(cnt == 10)   cout << "YES" << endl;
        else    cout << "NO" << endl;
        N--;
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;

const int INF = 1 << 29;
typedef pair<int, int> P;

int n;
int dp[10][10][10] = {0};
int balls[10];

int dfs(int left, int right, int num)
{
	if(num == 10) return 1;
	if(dp[left][right][num]) return dp[left][right][num];
	int ret1 = 0, ret2 = 0;
	if(left <= balls[num]) ret1 = dfs(balls[num], right, num+1);
	if(right <= balls[num] && ret1 != 1) ret2 = dfs(left, balls[num], num+1);
	return dp[left][right][num] = (ret1 == 1 || ret2 == 1 ? 1 : -1);
}

int main(void)
{
	while(cin >> n && n)
	{
		for (int i = 0; i < n; i++)
		{
			memset(dp, 0, sizeof(dp));
			for (int j = 0; j < 10; j++)
			{
				int x; cin >> x; x--;
				balls[j] = x;
			}
			cout << (dfs(0,0,0) == 1?"YES":"NO")<< endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string.h>
using namespace std;
int main(void)
{
  int n;
  cin>>n;
  int num1[10];
  for(int i=0;i<n;i++)
    {
      int count=0;
      for(int j=0;j<10;j++)
	{
	  cin>>num1[j];
	}
      for(int k=0;k<10-1;k++)
	{
	  int num2[10];
	  if(num1[k]>num1[k+1])
	    {
	      int l=0;
	      num2[l]=num1[k];
	      l++;
	    }
	  if(num1[k]>num1[k+1] && num2[k]>num2[k+1] && num2[k+1]!=0)count++;
	}
      if(count>0)cout<<"NO"<<endl;
      else cout<<"YES"<<endl;
      for(int m=0;m<10;m++)
	{
	  num1[m]=0;
	}
    }
  return 0;
}

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

int ball[10];

bool solve(int i, int a, int b){
	if (i == 10) return true;
	bool ans = false;
	if (a < ball[i]) ans = solve(i + i, ball[i], b);
	if (b < ball[i])ans = solve(i + i, a, ball[i]);
	return ans;
}

int main(){
	int n;
	cin >> n;

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

	return 0;
}
//beatmaniaIIDX 23th copula

C++: #include<stdio.h>
int a[10];
int bstack[10];
int btop;
int cstack[10];
int ctop;
bool dfs(int i)
{
    bool b1=false,b2=false;
    if(i==10)
        return true;
    if(btop==-1 || bstack[btop]<a[i])
    {
        btop++;
        bstack[btop]=a[i];
        i++;
        b1=dfs(i);
        btop--;
    }
    if(ctop==-1 || cstack[ctop]<a[i])
    {
        ctop++;
        cstack[ctop]=a[i];
        i++;
        b2=dfs(i);
        ctop++;
    }
    return b1|b2;
}
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        for(int i=0;i<10;i++)
        {
            scanf("%d",&a[i]);
        }
        btop=-1;
        ctop=-1;
        if(dfs(0))
            printf("YES\n");
        else
            printf("NO\n");
    }
}

C++: #include<iostream>
using namespace std;
string solve(int data[]){
	for(int i=0;i<4;i++){
		if(data[2*i +1] > data[2*i+3])
		if(data[2*i] > data[2*i * 2]){
		} else{
		 return "NO";
		}
		
		}
		return "YES";
}


int main(){
	int times,data[10];
	cin >> times;
	for(int i=0;i<times;i++){
		for(int k=0;k<10;k++)
		cin >> data[k];
	
		cout << solve(data) << endl;
		
		
	}

}

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

int main(){
int a[10];
int n,b=0,c=0;
cin>>n;
for(int i=0;i<n;i++){
b=0;c=0;
for(int j=0;j<10;j++)cin>>a[j];
for(int j=0;j<10;j++){
if(a[j]>b){b=a[j];}
if(a[j]<b&&a[j]>c){c=a[j];}
if(a[j]<b&&a[j]<c){
cout<<"NO"<<endl;
break;}
if(j==9){
cout<<"YES"<<endl;
break;}
}
}}

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

int main() {
	int n, a;
	vector<int> A;
	vector<vector<int>> AA;
	cin >> n;
	bool check[] = { 0 };
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> a;
			A.push_back(a);
		}
		AA.push_back(A); A.clear();
	}
	for (int i = 0; i < AA.size(); i++) {
		int b = 0, c = 0;
		for (int j = 0; j < AA[i].size(); j++) {
			if (b >= c) {
				if (AA[i][j] > b)b = AA[i][j];
				else {
					if (AA[i][j] > c)c = AA[i][j];
					else {
						check[i] = 0; break;
					}
				}
			}
			else {
				if (AA[i][j] > c)c = AA[i][j];
				else {
					if (AA[i][j] > b)b = AA[i][j];
					else {
						check[i] = 0; break;
					}
				}
			}
			if (j == AA[i].size() - 1)check[i] = 1;
		}
	}
	for (int i = 0; i < AA.size(); i++) {
		if (check[i])cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
    int n;cin>>n;
    while(n--){
        int b=0,c;cin>>c;
        for(int i=1;i<=9;i++){
            int t;cin>>t;
            if(c<t)c=t;
            else if(b<t)b=t;
            else {c=0;break;}
        }
        cout<<(c?"YES":"NO")<<endl;
    }
    return 0;
}

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

int a[10],x[11][11][10];

int dfs(int B,int C,int m){//a[m]????????????????£????
	if(m==10){
		return 0;
	}else if(x[B][C][m]>=0){
		return x[B][C][m];
	}else if(a[m]>B){
		if(dfs(a[m],C,m+1)==0){
			x[B][C][m]=0;
			return 0;
		}else if(a[m]>C){
			if(dfs(B,a[m],m+1)==0){
				x[B][C][m]=0;
				return 0;
			}else{
				x[B][C][m]=1;
				return 1;
			}
		}else{
			x[B][C][m]=1;
			return 1;
		}
	}else if(a[m]>C){
		if(dfs(B,a[m],m+1)==0){
			x[B][C][m]=0;
			return 0;
		}else{
			x[B][C][m]=1;
			return 1;
		}
	}else{
		x[B][C][m]=1;
		return 1;
	}
}

int main(){
	int n;
	cin>>n;
	for(int q=0;q<n;++q){
		for(int i=0;i<10;++i){
			cin>>a[i];
			a[i];
		}
		for(int i=0;i<11;++i){
			for(int j=0;j<11;++j){
				for(int k=0;k<10;++k){
					x[i][j][k]=-1;
				}
			}
		}
		if(dfs(0,0,0)==0){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
}