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 <bits/stdc++.h>

using namespace std;

vector<int> a;
stack<int> b, c;

bool dfs(int i)
{
	if (i == 10) return true;

	bool res1 = false, res2 = false;

    if (b.empty() || b.top() < a[i]) {
        b.push(a[i]);
        res1 = dfs(i + 1);
        b.pop();
    }

    if (c.empty() || c.top() < a[i]) {
        c.push(a[i]);
        res2 = dfs(i + 1);
        c.pop();
    }

	return res1 || res2;
}

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

	while (n--) {
		a.clear();
		while (b.size()) b.pop();
		while (c.size()) c.pop();

        for (int i = 0; i < 10; ++i) { int v; cin >> v; a.push_back(v); }

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

C++: #include <iostream>

using namespace std;

int main(void){

  int a,b,c,out;
  int n;
  cin >> n;
  while(n--){

    a = b = c = out = 0;

    for( int l = 10 ; l > 0 ; l-- ){
      cin >> a;
      if( b < a ){
	b = a;
      }
      else if( c < a ){
	c = a;
      }
      else out = a;
    }
    if( out == 0 )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(i-21?"YES":"NO"))for(i=B=C=0;std::cin>>A,i++<10;)if(B<A)B=A;else C<A?C=A:i=20;}

C++: #include<iostream>
using namespace std;
int T,num[20],flag,numa[20],numb[20];

void dfs(int t,int ta,int tb)
{
    if(flag)
        return ;
    if(t>=10)
    {
        flag=1;
        return ;
    }
    if(num[t]>numa[ta])
    {
        numa[ta+1]=num[t];
        dfs(t+1,ta+1,tb);
        if(flag)
            return ;
    }
    if(num[t]>numb[tb])
    {
        numb[tb+1]=num[t];
        dfs(t+1,ta,tb+1);
    }
}

int main()
{
    cin>>T;
    while(T--)
    {
        flag=0;
        numa[0]=0,numb[0]=0;
        for(int i=0;i<10;++i)
            cin>>num[i];
        dfs(0,0,0);
        if(flag)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}

C++: #include <iostream>
using namespace std;
int N,a[10];
bool ans;
bool test(int i){
	int b=0,c=0;
	for(int j=0;j<10;j++){
		if(i>>j&1){
			if(b>a[j])return false;
			else b=a[j];
		}else{
			if(c>a[j])return false;
			else c=a[j];
		}
	}
	return true;
}
int main()
{
    cin>>N;
	while(N--){
		ans=false;
		for(int i=0;i<10;i++)cin>>a[i];
		for(int i=0;i<1<<10;i++){
			if(test(i)){
				ans=true;
				break;
			}
		}
		if(ans)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
    return 0;
}

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

int balls[10];

bool dfs(int left, int right, int currentID){
	if(currentID > 9) return true;
	
	bool ok = false;
	if (left < balls[currentID]){
		ok = dfs(balls[currentID], right, currentID+1);
	}
	if (right < balls[currentID]){
		ok = dfs(left, balls[currentID], currentID+1);
	}
	return ok;
}

int main() {
	int n; cin >> n;
	
	while(n--){
		for (int i = 0; i < 10; i++) cin >> balls[i];
		cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
	}
}

C++: #include <iostream>
using namespace std;
int N;
int V[10];

int dfs(int a, int b, int d) {
    if(d==10) return 1;
    int atry = 0, btry = 0;
    if(a < V[d]) atry = dfs(V[d], b, d+1);
    if(b < V[d]) btry = dfs(a, V[d], d+1);
    if(atry == 0 && btry == 0) return 0;
}

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

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

using namespace std;

bool Solution()
{
    
    
    int left = 0;
    int right = 0;
    
    int a[10];
    
    for (int i = 0; i < 10; i++)
    {
        cin>>a[i];
    }
        
        for (int i = 0; i < 10; i++)
        {
            if (a[i] > left) // at the beginning, compare with first ball and the ball before first ball (empty)
            {
                left = a[i];
            }
            else if (a[i] > right)
            {
                right = a[i];
            }
            else                 //when can not enter to the both bottles to the end, then return false
            {
                return false;
            }
        }
    
    return true;
}

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

C++: #include<cstdio>
using namespace std;
int main(){
	int t;
	scanf("%d", &t);
	while(t--){        
		int a, b = -1, c = -1;
		bool flag = true;
		for(int i = 1; i <= 10; i++){
			scanf("%d", &a);
			if(flag){
				if(a > b)   //????¬?????????????b??¶?????¢??? 
					b = a;
				else if(a > c)
					c = a;
				else
					flag = false;
			}
		}
		printf("%s\n", flag? "YES" :"NO");
	}
	return 0;
}

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


int main() {
  int n;
  int data[10];
  cin >> n;
  while ( n > 0 ) {
    n--;
    int flag = 1;
    for ( int i = 0; i < 10; i++ ) cin >> data[i];
    int b = 0,c = 0;
    for ( int i = 0; i < 10; i++ ) {
      if ( b < data[i] ) b = data[i];
      else if ( c < data[i] ) c = data[i];
      else flag = 0;
    }
    if ( flag ) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	while(n--){
		stack<int> B, C;
		B.push(0);
		C.push(0);
		int data[10];
		int tmp;
		int i;
		for(int i = 0; i < 10; i++){
			cin >> data[i];
		}
		for(i = 0; i < 10; i++){
			tmp = data[i];
			if(tmp > B.top() && tmp > C.top()){
				if(B.top() >= C.top()){
					B.push(tmp);
				}else{
					C.push(tmp);
				}
			}else if(tmp > B.top()){
				B.push(tmp);
			}else if(tmp > C.top()){
				C.push(tmp);
			}else{
				break;
			}
		}

		if(i == 10){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
}

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;
			i = HEIGHT;
		}
	}
	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 <bits/stdc++.h>

using namespace std;

int a[10];

bool dfs(int i, int l, int r)
{
    if (i == 10) return true;

    if (l < a[i] && dfs(i + 1, a[i], r)) return true;
    if (r < a[i] && dfs(i + 1, r, a[i])) return true;

    return false;
}

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

    while (n--) {
        l = r = 0;
        for (int i = 0; i < 10; ++i) cin >> a[i];
        cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
    }
}