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 "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
        int n;
        int b = 0;
        int c = 0;
        int d = 0;
        int A[10] = {};
        int B[10] = {};
        int C[10] = {};
        cin >> n;
        for (int i = 0;i < n;i++) {
                for (int j = 0;j < 10;j++) {
                        cin >> A[j];
                }

                for (int j = 0;j < 10;j++) {
                        if (d == 0) {
                                if (j == 0) {
                                        B[0] = A[0];
                                        b++;
                                }
                                if ((A[j] > B[b]) && (B[b] > C[c])) {
                                        B[b] = A[j];
                                        b++;
                                }
                                if (A[j] > C[c]) {
                                        C[c] = A[j];
                                        c++;
                                }
                                if ((A[j] < B[b - 1]) && (A[j] < C[c - 1])) {
                                        cout << "NO" << endl;
                                        d = 1;
                                }
                        }
                }
                if (d == 0) {
                        cout << "YES" << endl;
                }
                d = 0;
        }
        return 0;
}

C++: #include <cstdio>

#define N 10

int D, Ball[N];
int R, L;

bool solve(int i) {
	if(i == N) return true;
	if(R < Ball[i]) {
		R = Ball[i];
		if( solve(i+1) ) return true;
	}
	if(L < Ball[i]) {
		L = Ball[i];
		if( solve(i+1) ) return true;
	}
	return false;
}

int main() {
	scanf("%d", &D);
	for(int i = 0; i < D; i++) {
		R = L = 0;
		for(int j = 0; j < N; j++) scanf("%d", &Ball[j]);
		R = Ball[0];
		if( solve(1) )	printf("YES\n");
		else			printf("NO\n");
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(void) {
    int N, a, b, c, x[10];
    cin >> N;
    for (; N--; ) {
        bool ok = true;
        b = c = 0;
        for (int i = 0; i < 10; i++) {
            cin >> x[i];
        }
        for (int i = 0; i < 10; i++) {
            a = x[i];
            if (a < b && a < c) {
                ok = false;
                break;
            } else if (a < b) {
                c = a;
            } else if (a < c) {
                b = a;
            } else if (b < c) {
                c = a;
            } else {
                b = a;
            }
        }
        if (ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cstdio>

using namespace std;



int main(){
	int n;

	cin >> n;
	while(n--){
		int a;
		bool p = true;
		int b = 0, c = 0;
		for(int i = 0; i < 10; i++){
			cin >> a;
			if(p){
				if(a > b){
					b = a;
				}else if(a > c){
					c = a;
				}else{
					p = false;
				}
			}
		}
		
		if(p){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
template<typename V> typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();

// clang-format on

bool dfs(vi v, int l, int r) {
  if (v.size() == 0) {
    return true;
  }
  bool hoge = false;
  if (v.back() > l) {
    vi _v  = v;
    int _l = v.back();
    _v.pop_back();
    hoge |= dfs(_v, _l, r);
  }
  if (v.back() > r) {
    vi _v  = v;
    int _r = v.back();
    _v.pop_back();
    hoge |= dfs(_v, l, _r);
  }
  return hoge;
}

main {
  int n;
  cin >> n;
  rep(_, n) {
    vi v(10);
    rep(i, 10) cin >> v[9 - i];
    cout << (dfs(v, 0, 0) ? "YES" : "NO") << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
using namespace std;

string func(stack<int>,stack<int>,stack<int>);

int main(){
		  stack<int> s,st,right,left;
		  int loop,num;

		  cin>>loop;
		  for(int i=0;i<loop;i++){

					 while(!s.empty()) s.pop();
					 while(!st.empty()) st.pop();
					 while(!right.empty()) right.pop();
					 while(!left.empty()) left.pop();
					 right.push(0);left.push(0);

					 for(int l=0;l<10;l++){
								cin>>num;
								s.push(num);
					 }
					 while(!s.empty()){
								st.push(s.top());
								s.pop();
					 }

					 cout<<func(st,right,left)<<endl;
		  }
		  return 0;
}

string func(stack<int> st,stack<int> right, stack<int> left){
		  if(st.empty()) return "YES";

		  if(right.top()<st.top()){
					 right.push(st.top());
					 st.pop();
					 if(func(st,right,left)=="YES") return "YES";
					 else{
								st.push(right.top());
								right.pop();
					 }
		  }
		  if( left.top()<st.top()){
					 left.push(st.top());
					 st.pop();
					 if(func(st,right,left)=="YES") return "YES";
					 else{
								st.push(left.top());
								left.pop();
					 }
		  }

		  return "NO";
}

C++: #include <iostream>
using namespace std;
int main(){
int a;
int b;
int n;
int c;
int d;
int e;
int f;
cin >>n;
c=0;
while(c<n){
f=0;
a=0;
b=0;
d=0;
while(d<10){
cin >>e;
if(e>a&&a>b){a=e;}
else if(e>b&&b>a){b=e;}
else if(e>a){a=e;}
else if(e>b){b=e;}
else{f=1; break;}
d=d+1;}
if(f==0){cout <<"YES"<<endl;}
if(f==1){cout <<"NO"<<endl;}
c=c+1;}}

C++: #include<iostream>
#include<cstring> 
using namespace std;
int a[10];
bool vis[10];
int main(){
	int t;
	cin>>t;
	while(t--){
		memset(vis, 0, sizeof vis);
		for(int i = 0; i < 10; i++) cin>>a[i];
		int now = 0;
		for(int i = 1; i < 10; i++){
			if(a[i] > a[now]){
				now = i;
				vis[now] = 1;
			}
		}
		bool flag = true;
		now = -1;
		for(int i = 1; i < 10; i++){
			if(!vis[i]){
				if(now == -1) now = i;
				else{
					if(a[i] < a[now]){
						flag = false;
						break;
					}
					else now = i;
				}
			}
		}
		if(flag) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}