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 <cmath>
#include <string>
#include <vector>

using namespace std;

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

  int ball_num = 10;
  for(int i=0;i<n;i++){
    vector<int> a;
    bool flag = true;
    for(int j=0;j<ball_num;j++){ 
      int tmp;
      cin >> tmp;
      a.push_back(tmp);
    }

    int b=0;
    int c=0;
    for(int i=0;i<ball_num;i++){
      if(b<=c){
	swap(b, c);
      }
      
      // b > c

      if(b < a[i]){
	b = a[i];
      }else{
	if(c < a[i]){
	  c = a[i];
	}else{
	  flag = false;
	}
      }

      if(flag==false){
	break;
      }
    }

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

  

}

C++: #include<iostream>

using namespace std;

int balls[15];

bool dfs(int ball_index, int right, int left) {
    if (ball_index == 10) return true;

    int last_ball = balls[ball_index];
    if (last_ball > right) return dfs(ball_index+1, last_ball, left);
    if (last_ball > left)  return dfs(ball_index+1, right, last_ball);

    return false;
}

void solve() {
    for (int i = 0; i < 10; i++) {
        cin >> balls[i];
    }

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

int main(int argc, char const* argv[]) {

    int n;
    cin >> n;

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

    return 0;
}

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

using namespace std;

vector<int> nums;
int h, w;

bool dfs(int idx, int x, int y) {
	if (idx == 10) {
		return true;
	}
	bool ok = false;
	int z = nums[idx];
	if (x < z) {
		ok = dfs(idx + 1, z, y);
		if (ok) {
			return true;
		}
	}
	if (y < z) {
		ok = dfs(idx + 1, x, z);
		if (ok) {
			return true;
		}
	}

	return false;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		nums.assign(10, 0);
		for (int j = 0; j < 10; j++) {
			cin >> nums[j];
		}
		bool ok = dfs(0, -1, -1);
		cout << (ok ? "YES" : "NO") << endl;
	}
	return 0;
}

C++: /*
input:
2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
output:
YES
NO
*/

#include <cstdio>

//&#36755;入
int a[10];

//深度&#20248;先放第K个球
bool dfs(int k, int B, int C){
	//若10个球都放完
	if(k == 10) return true;
	if(a[k] > B){
		//能放&#36827;B道
		if(dfs(k + 1, a[k], C))
			return true;
	}
	if(a[k] > C){
		//能放&#36827;C道
		if(dfs(k + 1, B, a[k]))
			return true;
	}
	//都不能放
	return false;
}

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

int main(int argc, char const *argv[]){

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

	return 0;
}

C++: #include<iostream>
using namespace std;
int bfs(int, int, int);
int a[11];
int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		for (int i2 = 0; i2 < 10; i2++){
			cin >> a[i2];
		}
		a[10] = 0;
		int ans=bfs(0, 0, 0);
		if (ans == 0){
			cout << "NO" << endl;
		}
		else{
			cout << "YES" << endl;
		}
	}
	
}
int bfs(int i, int l, int r){
	int ans = 0;
	if (i == 10){
		ans = 1;
	}
	if (l < a[i]){
		ans = bfs(i + 1, a[i], r);
	}
	if (r < a[i]){
		ans = bfs(i + 1, l, a[i]);
	}
	return ans;
}

C++: #include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
    int N,pre,current,second_pre;
    bool NO_FLG;

    scanf("%d",&N);
    for(int i=0;i<N;i++){
        pre = -1;
        second_pre = -1;
        NO_FLG = false;
        for(int k = 0; k < 10; k++){
            scanf("%d",&current);
            if(pre > current){
				if(second_pre == -1){
					second_pre = current;
				}else{
					if(second_pre > current){
						NO_FLG = true;
						break;
					}else{
						second_pre = current;
					}
				}
			}else{
				pre = current;
			}
        }
        if(NO_FLG==false){
        	printf("YES\n");
        }else{
        	printf("NO\n");
        }
    }
    return 0;
}

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


int main(void){
    int n;
    int ball;
    int B_last, C_last;
    bool flag;
    cin>>n;
    vector<int> B(1,0);
    vector<int> C(1,0);
    for(int i=0;i<n;i++){
        flag=true;

        for(int j=0;j<10;j++){
            cin>>ball;
            B_last=B[B.size()-1];
            C_last=C[C.size()-1];
            if(B_last>=C_last){
                if(ball>B_last){
                    B.push_back(ball);
                }
                else if(ball>C_last){
                    C.push_back(ball);
                }
                else{
                    flag=false;
                }
            }
            else{
                if(ball>C_last){
                    C.push_back(ball);
                }
                else if(ball>B_last){
                    B.push_back(ball);
                }
                else{
                    flag=false;
                }
            }
        }
        if(flag){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
        B.clear();
        C.clear();
        B.push_back(0);
        C.push_back(0);
    }
    return 0;
}

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

int main(){
	
	
	int n;
	int b[10];
	
	cin>>n;
	while(n>0){
		stack<int> s1,s2;
		int f=0;
		for(int i=0;i<10;i++)
			cin>>b[i];
		for(int i=0;i<10;i++){
			if(s1.empty())
			s1.push(b[i]);
			else if(s1.top()<b[i])
			s1.push(b[i]);
			else if(s2.empty())
			s2.push(b[i]);
			else if(s2.top()<b[i])
			s2.push(b[i]);
			else
				f=1;
		}
		if(f==0)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
		n--;
			
	}
}

C++: #include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD
 
int main(){
  int n;
  cin>>n;
  while(n--){
    int left=-1,right=-1;
    bool flag = true;
    REP(i,10){
      int x;
      cin>>x;
      if(x>right){
        right = x;
      }else if(x>left){
        left = x;
      }else{
        flag = false;
        break;
      }
    }
    if(flag){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
  }
  return 0;
}