Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var num int
	fmt.Scan(&num)

	for i := 0; i < num; i++ {
		sc.Scan()
		line := sc.Text()

		insertCheck(line)
	}
}

func insertCheck(line string) {
	var B, C []int

	for _, v := range strings.Split(line, " ") {
		ball, _ := strconv.Atoi(v)
		switch {
		case len(B) == 0:
			B = append(B, ball)
		case B[len(B)-1] < ball:
			B = append(B, ball)
		case B[len(B)-1] >= ball:
			switch {
			case len(C) == 0:
				C = append(C, ball)
			case C[len(C)-1] < ball:
				C = append(C, ball)
			case C[len(C)-1] >= ball:
				fmt.Println("NO")
				return
			}
		}
	}
	fmt.Println("YES")
}

C++: #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define int long long

typedef long long ll;
typedef pair<int, int> Pair;

// const int kMaxN;

int N;
int D[10];
string ans;

string Search(int i, vector<int> d1, vector<int> d2) {
  if (i == 10) { return "Yes"; }

  if (d1.empty() || d1.back() < D[i]) {
    d1.push_back(D[i]);
    if (Search(i+1, d1, d2) == "Yes") { return "Yes"; }
    d1.pop_back();
  }
  if (d2.empty() || d2.back() < D[i]) {
    d2.push_back(D[i]);
    if (Search(i+1, d1, d2) == "Yes") { return "Yes"; }
  }

  return "No";
}

signed main() {
  cin >> N;

  while (N-- > 0) {
    REP(i, 10) { cin >> D[i]; }
    vector<int> d1, d2;
    ans = Search(0, d1, d2);
    cout << ans << endl;
  }

  return 0;
}

C++: #include <iostream>
using namespace std;
 
int main() {
    int n, balls[10]; cin >> n;
    while(n--){
        for(int i = 0; i < 10; i++) cin >> balls[i];
         
        bool sortable = false;
        for(int i = 0; i < (1 << 10); i++){
            int bit = i;
            bool ok = true;
             
            int top[2] = {0,0}; //top[0]: B, top[1]: C
            for(int j = 0; j < 10; j++){
                if(top[bit & 1] > balls[j]){
                    ok = false; break;
                }
                top[bit & 1] = balls[j];
                bit >>= 1;
            }
             
            if(ok) {
                sortable = true; break;
            }
        }

        cout << (sortable ? "YES" : "NO") << endl;
    }
}

C++: #include<cstdio>
#define NUM 10
using namespace std;
bool solve(int data[NUM], int id, int l, int r){
  if(id == NUM)
    return true;
  else if(data[id] > l && data[id] > r)
    return solve(data,id+1,data[id],r) || solve(data,id+1,l,data[id]);
  else if(data[id] < l){
    if(data[id] < r)
      return false;
    else
      return solve(data,id+1,l,data[id]);
  }
  return solve(data,id+1,data[id],r);
}
int main(){
  int N;
  scanf("%d",&N);
  int data[NUM];
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < NUM ; j++)
      scanf("%d",&data[j]);
    if(solve(data,0,0,0))
      printf("YES\n");
    else
      printf("NO\n");
  }
}

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;
   while(cin>>N)
   {
     int arr[10];
     bool flag=true;
     for(int i=0;i<10;i++) cin>>arr[i];
     for(int i=0;i<8;i++)
     {
       if(arr[i]>arr[i+1]&&arr[i+1]>arr[i+2])
       {
         flag=false;
         break;                                      
       }        
     }     
     if(flag) cout<<"YES"<<endl;
     else cout<<"NO"<<endl;
   }
   //while(1);     
   return 0;  
 }

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

int main(){
	int b, c, n;
	int a;
	bool executable;
	cin >> n;
	for(int i=0;i<n;i++){
		c=0;
		executable = true;
		cin>>a;
		b=a;
		for(int j=1;j<10;j++){
			cin>>a;
			if(a-b < 0){
				if(a-c < 0){
					executable = false;
					break;
				}else{
					c = a;
				}
			}else{
				if(a-c < 0){
					b = a;
				}else{
					if(a-b < a-c){
						b = a;
					}else{
						c = a;
					}
				}
			}
		}
		if(executable){
			cout << "YES\n";
		}else{
			cout << "NO\n";
		}
	}
	return 0;
}

C++: main(){
	int topB,topC;
	int n,tmp;
	int valid;
	
	for (scanf("%d", &n); n--;){
		topB=topC=0;
		valid=1;
		for (int i=0; i<10; i++){
			scanf("%d", &tmp);
			if (tmp > topB) topB=tmp;
			else if (tmp > topC)topC=tmp;
			else {
				valid=0; break;
			}
		}
		printf("%s\n",valid?"YES":"NO");
	}
	return 0;
}

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(k == 0){
                pre = current;
            }else{
                if(pre > current){
                    if(second_pre == -1){
                        second_pre = current;
                    }else{
                        if(second_pre > current){
                            printf("NO\n");
                            NO_FLG = true;
                            break;
                        }else{
                            second_pre = current;
                        }
                    }
                }else{
                	pre = current;
                }
            }
        }
        if(!NO_FLG)printf("YES\n");

    }
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
bool separate(int* A, int i, vector<int> vB, vector<int> vC)
{
	if (i == 10){
		return (5 == vB.size() && 5 == vC.size());
	}
	if (vB.size() < 5){
		vector<int> vTmpB(vB);
		if (vTmpB.empty() || (!vTmpB.empty() && vTmpB.back() < A[i])){
			vTmpB.push_back(A[i]);
			if (separate(A, i + 1, vTmpB, vC))
				return true;
		}
	}

	if (vC.size() < 5){
		vector<int> vTmpC(vC);
		if (vTmpC.empty() || (!vTmpC.empty() && vTmpC.back() < A[i])){
			vTmpC.push_back(A[i]);
			if (separate(A, i + 1, vB, vTmpC))
				return true;
		}
	}

	return false;
}
int main()
{
	int n;
	cin >> n;
	int A[10] = {};
	while(n--){
		for (int j = 0; j < 10; ++j)
			cin >> A[j];
		vector<int> vB, vC;
		if (separate(A, 0, vB, vC)) cout << "YES\n";
		else cout << "NO\n";
	}
	return 0;
}

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

int ball[10];

//ball[m]?????\????????±b,c???????????????ball???????????????left,right
bool dfs(int m,int left, int right){
    if(m==10) return true;
    if(ball[m]>left){
        if(dfs(m+1,ball[m],right)) return true;
    }
    if(ball[m]>right){
        if(dfs(m+1,left,ball[m])) return true;
    }
    return false;
}

void solve(){
    for(int i=0;i<10;i++){
        cin>>ball[i];
    }
    if(dfs(0,0,0)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

int main(){
    int n;cin>>n;
    for(int i=0;i<2;i++){
        solve();
    }
    return 0;
}