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

int b = INT_MIN, c = INT_MIN;

bool push(int ball) {
    if(ball > b) b = ball;
    else if (ball > c) c = ball;
    else return(false);
    return(true);
}

int main(void) {
    int num; cin >> num;
    bool ans = true;
    for(int r = 0; r < num; r++) {
        for(int c = 0; c < 10; c++) {
            int input; cin >> input;
            if(!push(input) && ans) ans = false;
        }
        if(ans) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

C++: #include <iostream>

using namespace std;

int ball_list[10];
int right_list[10];
int left_list[10];

bool flag;

void dfs(int right, int left){
  int count = right + left;

  if(count == 10){
    flag = true;
  }else{
    if(right == 0 || right_list[right-1] < ball_list[count]){
      if(right == 0){
        right_list[0] = ball_list[count];
      }else{
        right_list[right-1] = ball_list[count];
      }
      dfs(right+1, left);
    }
    if(left == 0 || left_list[left-1] < left_list[left]){
      if(left == 0){
        left_list[0] = ball_list[count];
      }else{
        left_list[left-1] = ball_list[count];
      }
      dfs(right, left+1);
    }
  }
}

int main(){
  int n;

  cin >> n;

  for(int i = 0; i < n; i++){
    flag = false;
    memset(right_list, 0, sizeof(right_list));
    memset(left_list, 0, sizeof(left_list));

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

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

  return 0;
}

C++: #include <iostream>

using namespace std;
const int kBalln = 10;
int ball[kBalln];

bool ExistAsceOrder(int i, int a, int b){
  if (i == kBalln)  return true;

  if (a < ball[i]) 
    {
      if(ExistAsceOrder(i+1,ball[i],b)) return true;
    }

  if (b < ball[i])
    {
      if(ExistAsceOrder(i+1,a,ball[i])) return true;
    }

  return false;
}

int main(){
  int n;

  cin >> n;
  for (int j = 0; j < n; ++j)
    {
      for (int i = 0; i < kBalln; ++i)
        {
          cin >> ball[i];
        }
      cout << (ExistAsceOrder(0,0,0)? "YES" : "NO") << endl;
    }
  return 0;
}

C++: #include <stdio.h>
#include <stdbool.h>
int balls[10];
int left[10],right[10],l=0,r=0,det;
void solve();
void dfs(int depth);
bool check();
int main(void){
	int times;
	scanf("%d",&times);
	for(int i=0;i<times;i++){
		for(int j=0;j<10;j++)
			scanf("%d",&balls[j]);
		solve();
	}
	return 0; 
}

void solve(){
	det=0;
	dfs(0);
	if(det)	puts("YES");
	else	puts("NO");
}

void dfs(int depth){
	if(det)	return;
	if(depth==10){
		if(check())	det=1;
		return;
	}
	left[l++]=balls[depth++];
	dfs(depth);
	l--;depth--;
	right[r++]=balls[depth++];
	dfs(depth);
	r--;depth--;
}

bool check(){
	bool m=1,n=1;
	for(int i=0;i<l-1;i++)
		if(left[i]>left[i+1]){
			m=0;
			break;
		}
	for(int i=0;i<r-1;i++)
		if(right[i]>right[i+1]){
			n=0;
			break;
		}
	return m&&n;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n,l[10],a=0,b=0;
  cin>>n;
  while(n){
    cin>>l[0]>>l[1]>>l[2]>>l[3]>>l[4]>>l[5]>>l[6]>>l[7]>>l[8]>>l[9];
    for(int i=0;i<10;i++){
      if(!(i%2)){
	if(l[i]>a)a=l[i];
	else
	  break;
      }
      else{
	if(l[i]>b)b=l[i];
        else
	  break;
      }
    }
    (a==l[8]&&b==l[9])?cout<<"YES":cout<<"NO";
    cout<<endl;
    n--;
  }
  return 0;
}

C++: #include<stdio.h>
main(){
int i,j,n;
scanf("%d",&n);
int a[n][10],b,c;
for(i=0;i<n;i++)
for(j=0;j<10;j++)
scanf("%d",&a[i][j]);
for(i=0;i<n;i++){
b=0;
c=0;
for(j=0;j<10;j++)
if(a[i][j]>b)
b=a[i][j];
else if(a[i][j]>c)
c=a[i][j];
else
break;
if(j==10)
puts("YES");
else
puts("NO");
}
return 0;
}

C++: #include<iostream>
#include<stack>
#include<queue>
using namespace std;
int main(){
  int n,i;
  queue<int> a;
  cin>>i;
  while(i--){
    for(int i=0;i<10;i++){cin >> n; a.push(n);}
    stack<int> b,c;
    b.push(0); c.push(0);
    while(a.size()){
      int n = a.front();
      if(n>b.top()) b.push(n);
      else if(n>c.top()) c.push(n);
      else break;
      a.pop();
    }
    if(a.size()) cout << "NO" << endl;
    else cout << "YES" << endl;
  }
  return 0;
}

C++: //#include <iostream>
#include <bits/stdc++.h>
#define max_n  100
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
int n,a=-1,b=-1,c,t=0;
int main(){
    scanf("%d",&n);
    while(n--){
        a=0,b=0;
        for(int i=0;i<10;i++){
            cin>>c;
            if(c>a){
                a=c;
            }else if(c>b){
                b=c;
            }else{
                t++;
            }
        }
        if(t){
            cout<<"NO"<<endl;
        }else cout<<"YES"<<endl;
    }
    return 0;
}

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

#define bottom(v) v[v.size()-1]

using namespace std;

int main() {
  int n, t;
  vector<int> v1, v2;
  cin>>n;
  
  while(n--) {
    bool isOk = true;
    for(int i = 0; i < 10; i++) {
      cin>>t;
      if(v1.empty()) v1.push_back(t);
      else {
	if(bottom(v1)<t) {
	  v1.push_back(t);
	} else if(v2.empty() || bottom(v2)<t) v2.push_back(t);
	else {
	  isOk = false;
	  break;
	}
      }
    }
    cout << (isOk ? "YES" : "NO") << endl;
    v1.clear(); v2.clear();
  }
  return 0;
}

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

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

C++: #include <iostream>
#include <algorithm>
using namespace std;
static const int N = 10;

int main(){
  int input[N], left[N], right[N], leftNum, rightNum;
  int T;
  cin >> T;
  while(T--){
    for(int i = 0; i < N; i++)
      cin >> input[i];
    leftNum = 0;
    rightNum = 0;
    leftNum++;
    for(int i = 1; i < N; i++){
      if(left[leftNum - 1] < input[i]){
        left[leftNum] = input[i];
        leftNum++;
      } else {
        right[rightNum] = input[i];
        rightNum++;
      }
    }
    if(is_sorted(right, right + rightNum)){
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}