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>
using namespace std;

int main() {

  int n;
  cin >> n;

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

    int b = 0;
    int c = 0;
    int input;
    bool flag = false;
    for ( int j = 0; j < 10; j++ ) {
      cin >> input;

      if ( input < b && input < c ) flag = true;
      if ( flag ) continue;

      if ( input < b ) {
	c = input;
      }else if ( input < c ) {
	b = input;
      }else {
	if ( b < c ) {
	  c = input;
	}else {
	  b = input;
	}
      }

    }

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

  }

  return 0;

}

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

int boll[15];
int dig[2];

bool dfs(int d)
{
    if(d==10) return true;
    int tmp;
    for(int i=0; i<2; ++i)
    {
        if(boll[d]>dig[i])
        {
            tmp = dig[i];
            dig[i] = boll[d];
            if(dfs(d+1)) return true;
            dig[i] = tmp;
        }
    }
    return false;
}

void solve()
{
    dig[0] = dig[1] = -1;
    bool ans = dfs(0);
    printf("%s\n", ans?"YES":"NO");
}

int main()
{
    int n;
    scanf("%d\n", &n);
    while(n--)
    {
        for(int i=0; i<10; ++i) scanf("%d", &boll[i]);
        solve();
    }
    return 0;
}

C++: #include<cstdio>

int ball[11], B[11], C[11];
int cnt1, cnt2;
bool flagb, flagc, flag;

void dfs(int cur) {
    if (flag)return;
    if (cur ==10) {
        flagb = 1, flagc = 1;
        if (cnt1 > 1) {
            for (int i = 0; i < cnt1 - 1; i++)
                if (B[i] > B[i + 1]) {
                    flagb = 0;
                    break;
                }
        }
        if (cnt2 > 1) {
            for (int i = 0; i < cnt2 - 1; i++)
                if (C[i] > C[i + 1]) {
                    flagc = 0;
                    break;
                }
        }

        if (flagb && flagc) {
            flag = 1;
            return;
        }
        return;
    }
    B[cnt1++] = ball[cur];
    dfs(cur + 1);
    cnt1--;
    C[cnt2++] = ball[cur];
    dfs(cur + 1);
    cnt2--;
}

void solve() {
    flag = 0;
    dfs(0);
    if (flag)printf("YES\n");
    else printf("NO\n");
}

int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        cnt1 = 0, cnt2 = 0;
        for (int i = 0; i < 10; i++)
            scanf("%d", &ball[i]);
        solve();
    }
    return 0;
}

C++: #include <stdio.h>

#include <stack>

int main(void){
    using namespace std;
    stack<int> a,b;
    int n,j,i,ball,flag;
    scanf("%d",&n);
    for(j=0; j<n; j++){
        flag=0;
        for(i=0; i<10; i++){
            scanf("%d",&ball);
            if(a.empty()){
                a.push(ball);
            }else if(a.top() < ball){
                a.push(ball);
            }else if(b.empty()){
                b.push(ball);
            }else if(b.top() < ball){
                b.push(ball);
            }else{
                flag=1;
            }
        }
        if(flag==0){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int N;
int num[10];
int lnum,rnum;
bool dfs(int n){
	if(n==10) return true;
	if((num[n]<lnum)&&(num[n]<rnum)) return false;
	else{
		if((num[n]>=lnum)&&(num[n]<rnum)){
			lnum=num[n];
			if(dfs(n+1)) return true;
		}
		if((num[n]>=rnum)&&(num[n]<lnum)){
			rnum=num[n];
			if(dfs(n+1)) return true;
		}
		else{
			int temp=lnum;
			lnum=num[n];
			if(dfs(n+1)) return true;
			else{
				lnum=temp;
				rnum=num[n];
				if(dfs(n+1)) return true;
			}
		}
	}
	return false;
}
void solve(){
	cin>>N;
	for(int i=0;i<N;i++)
	{
	    for(int j=0;j<10;j++)
	    cin>>num[j];
	    if(dfs(0)) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}
int main(){
	solve();
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main(){
  int N;
  cin >> N;
  int boll[10];
  for(int i=0;i<10;i++) cin >> boll[i];
  stack<int> B,C;
  B.push(0); C.push(0);
  for(int i=0;i<N;i++){
    for(int j=0;j<10;j++){
      if(B.top()>=C.top()){
        if(boll[j]>B.top()) B.push(boll[j]);
        else if(boll[j]>C.top()) C.push(boll[j]);
        else{
          cout << "NO" << endl;
          break;
        }
      } else {
        if(boll[j]>C.top()) C.push(boll[j]);
        else if(boll[j]>B.top()) B.push(boll[j]);
        else{
          cout << "NO" << endl;
          break;
        }
      }
      if(j==9) cout << "YES" << endl;
    }
  }
  return 0;
}

C++: #include <iostream>

int ball[10];
bool ans;

void solve();

void dfs(int i, int right, int left);

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

void solve(){
    ans = false;
    dfs(0, 0, 0);
    return;
}

void dfs(int i, int right, int left){
    if(i == 10){
        ans = true;
        return;
    }
    
    if(ball[i] < right && ball[i] < left)
        return;
    
    if(ball[i] > right)
        dfs(i + 1, ball[i], left);
    else
        dfs(i + 1, right, ball[i]);
    
    if(ans)
        return;
    
    return;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){
    rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" ");
    return os;
}

int main(){
    int n; cin >> n;
    while(n--){
        int v[10];
        rep(i,10) cin >> v[i];
        bool ok = false;
        rep(mask,1<<10){
            int a=-1, b=-1;
            bool f = true;
            rep(i,10){
                if(mask>>i & 1){
                    if(a==-1 || a < v[i]) a = v[i];
                    else f = false;
                } else {
                    if(b==-1 || b < v[i]) b = v[i];
                    else f = false;
                }
            }
            if(f){
                ok = true;
                break;
            }
        }
        puts(ok ? "YES" : "NO");
    }
}