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 <queue>
#include <vector>
#include <algorithm>
#include <utility>
#include <climits>
#include <cstdlib>

using namespace std;

#define NDEBUG

#ifndef NDEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...)
#endif

int N;

const char *solve(int (&balls)[10]) {
    for (int trial = 0; trial < (1 << 10); trial++) {
        int left_top = 0, right_top = 0;
        int i;
        for (i = 0; i < 10; i++) {
            int dir = ((trial >> i) & 1);
            int ball = balls[i];
            if (dir) { // left
                if (left_top == 0) {
                    left_top = ball;
                    continue;
                }
                if (left_top > ball) {
                    break;
                }
                left_top = ball;
            } else { // right
                if (right_top == 0) {
                    right_top = ball;
                    continue;
                }
                if (right_top > ball) {
                    break;
                }
                right_top = ball;
            }
        }
        if (i == 10) {
            return "YES";
        }
    }
    return "NO";
}

int main() {
    scanf(" %d", &N);
    debug("===\n");
    debug("%d\n", N);
    for (int i = 0; i < N; i++) {
        int balls[10];
        for (int j = 0; j < 10; j++) {
            scanf(" %d", &balls[j]);
        }
        for (int j = 0; j < 10; j++) {
            debug("%d ", balls[j]);
        }
        debug("\n");
        printf("%s\n", solve(balls));
    }
}

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

using namespace std;

int a[11];

bool dfs(int I, int A, int B) {
	if (I == 10) return true;
	if (a[I] > A) {
		if (dfs (I + 1, a[I], B)) {
			return true;
		}
	}
	if (a[I] > B) {
		if (dfs(I + 1, A, a[I])) {
			return true;
		}
   	}
   	return false;
}

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

C++:  
 #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
  
 int main()
 {
   int N;
   cin>>N;
   while(N--)
   {
     int arr[10];
     int left[10],right[10];
     bool flag=true;
     int cnt1,cnt2;
     cnt1=cnt2=0;
     for(int i=0;i<10;i++) cin>>arr[i];
     for(int i=0;i<10;i++)
     {
       if(i==0) left[cnt1++]=arr[i];
       else
       {
         if(cnt2==0)
         {
           if(left[cnt1-1]<arr[i]) left[cnt1++]=arr[i];
           else right[cnt2++]=arr[i]; 
         }
         else
         {
           int left_win=arr[i]-left[cnt1-1];
           int right_win=arr[i]-right[cnt2-1];
           if(arr[i]<min(left[cnt1-1],right[cnt2-1]))
           {
             flag=false;
             break;                                          
           }    
           else if(arr[i]>left[cnt1-1]&&arr[i]<right[cnt2-1]) left[cnt1++]=arr[i];
           else if(arr[i]<left[cnt1-1]&&arr[i]>right[cnt2-1]) right[cnt2++]=arr[i];
           else
           {
             if(right_win>left_win) left[cnt1++]=arr[i];
             else right[cnt2++]=arr[i];    
           }
         }   
       }        
     }
     if(flag) cout<<"YES"<<endl;
     else cout<<"NO"<<endl;
   }
   //while(1);     
   return 0;  
 }

C++: #include<iostream>
#include<queue>
using namespace std;
int main(void){
	int num;
	queue<int> qu;
	int a=0,b=0;
	int n;

	cin>>n;
	while(n--){
		for(int i=0;i<10;i++){//ツボツーツδ仰づーツ詰ツづ淞づゥ
			cin>>num;
			qu.push(num);
		}

		while(1){
			if(a < qu.front()){
				a=qu.front();
			}else if(b < qu.front()){
				b=qu.front();
			}else{
				cout<<"NO"<<endl;
				break;
			}
			qu.pop();
			if(qu.empty()==true){
				cout<<"YES"<<endl;
				break;
			}
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>

using namespace std;

int N;
int l[15];
int b,c;
int res[1000000000000];


void solve(int k){
  for(int i=0;i<10;i++){
    if(b<l[i] && c<l[i]){
      if(l[i]-b < l[i]-c) b=l[i];
      else c=l[i];
    }
    else if(b<l[i] && c>l[i]) b=l[i];
    else if(b>l[i] && c<l[i]) c=l[i];
    else{
      res[k]=0;
      return;
    }
  }
  res[k]=1;
  return;
}


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

  for(int i=0;i<N;i++){
    b,c=0;
    scanf("%d%d%d%d%d%d%d%d%d%d",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9]);
    solve(i);
  }

  for(int i=0;i<N;i++){
    if(res[i]==0) printf("NO\n");
    else printf("YES\n");
  }


  return 0;
}

C++: #include<iostream>
#include<algorithm>
int N;
int t[10000][10];
bool d[10000];
int a, b, c;
int main() {
	std::cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 10; j++) {
			std::cin >> t[i][j];
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 10; j++) {
			if (t[i][j] > a) {
				a = t[i][j];
			}
			else if (t[i][j] > b) {
				b = t[i][j];
			}
			else {
				std::cout << "NO" << "\n";
				a = 0; b = 0;
				break;
			}
			if (j == 9) {
				std::cout << "YES" << "\n";
			}
		}
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int ball;
	int n;
	while(cin >> n){
		bool flag = true;
		int B=0, C=0;
		for(int i=0; i<n; i++){
			for(int j=0; j<10; j++){
				cin >> ball;
				if(flag){
					if(B < ball) B=ball;
					else if(C < ball) C=ball;
					else flag=false;
				}
			}
			if(flag) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
#include<ctime>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#define mem(name,value) memset(name,value,sizeof(name))
#define push_back pb
using namespace std;
typedef long long ll;

const int maxn=10;
int T,A[maxn+2],B[maxn+2],C[maxn+2];
int x,y;

bool dfs(int a)
{
    if(a==maxn) return true;
    if(A[a]<B[x-1] && A[a]<C[y-1]) return false;
    else if(A[a]>B[x-1]) B[x++]=A[a];
    else if(A[a]>C[y-1]) C[y++]=A[a];
    return dfs(a+1);
}

int main()
{
    cin>>T;
    while(T--){
        for(int i=0;i<maxn;i++)
            cin>>A[i];
        mem(B,0);
        mem(C,0);
        x=y=1;
        if(dfs(0)) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}

C++: #include <iostream>

int a[10];

int main() {
	int T;
	cin >> T;
	while (T--) {
		bool ans = true;
		for (int i = 0; i < 10; ++i) {
			cin >> a[i];
		}
		int l, r;
		l = r = 0;
		for (int i = 0; i < 10; ++i) {
			if (a[i] > l) {
				l = a[i];
			} else if (a[i] > r) {
				r = a[i];
			} else {
				and = false;
				break;
			}
		}
		cout << (ans ? "YES" : "NO") << endl;
	}
}