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<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
  int n;
  cin>>n;
  REP(i,n){
    int x[10]={};
    bool f=true;
    REP(i,10)cin>>x[i];
    stack<int> B,C;
    B.push(x[0]);
    REP(i,9){
      if(x[i+1]<B.top()){
        if(C.empty()||(x[i+1]>C.top()&&!C.empty())){
          C.push(x[i+1]);
        }else{
          f=false;
          break;
        }  
      }else B.push(x[i+1]);
    }
    cout<<(f?"YES":"NO")<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
using namespace std;
const int maxn = 10001;
char a[maxn];
stack<int> p1 , p2;
bool dfs(int index , int n)
{
    for(int i = 0 ; i < 2 ; i ++){
        if(i == 1 && index < n){
            if(!p1.empty() && p1.top() > a[index]){
                return false;
            }else{
                p1.push(index);
                return dfs(index + 1 , n);
            }
        }
        else if(i == 2 && index < n){
            if(!p2.empty() && p2.top() > a[index]){
                return false;
            }else{
                p2.push(index);
                return dfs(index + 1 , n);
            }
        }
    }
}

int main()
{
    #ifdef DoubleQ
    freopen("in.txt" , "r" , stdin);
    #endif // DoubleQ
    int n;
    cin >> n;
    while(n --){
        for(int i = 0 ; i < 10 ; i ++){
            cin >> a[i];
        }


        bool res = dfs(0 , n);
        /*
        for(int i = 0 ; i < n ;i ++){
            for(int j = 0 ; j < m ; j ++){
                cout << g[i][j] << " ";
            }
            cout << endl;
        }
        */
        if(res) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

C++: #include<iostream>
using namespace std;
int arr[10];
bool dfs(int);
int l,r;
int main(){
	int t;
	cin>>t;
	while(t--){
		for(int i=0;i<10;i++)
			cin>>arr[i];
		l=r=0;
		if(dfs(0))
			cout<<"YES\n";
		else cout<<"NO\n";
	}
	return 0;
}
bool dfs(int t){
	if(t==10) return 1;
	int t1=l;
	if(arr[t]>l){
		l=arr[t];
		if(dfs(t+1))
			return 1;
		l=t1;
	}
	int t2=r;
	if(arr[t]>r){
		r=arr[t];
		if(dfs(t+1))
			return 1;
		r=t2;
	}
	return 0;
}

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

using namespace std;

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

    for(int att = 0; att < n; att++) {
        int balls[10];      // ボールのリスト
        stack<int> r, l;    // 筒の状態をプールするstack
        bool isOK = true;   // 分配可能フラグ
        
        for(auto b : balls) {
            cin >> b;
            
            if(!isOK) continue;
            if      (r.empty() || r.top() < b)  { r.push(b); }
            else if (l.empty() || l.top() < b)  { l.push(b); }
            else                                { isOK = !isOK; }
        }
        cout << (isOK ? "YES" : "NO") << endl;
    }
    
    return 0;
}

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

int a[10];
bool flag;

void dfs(int n, int l, int r){
	if(n == 10){
		flag = true;
		return;
	}

	if(a[n] > l){
		dfs(n+1, a[n], r);
	}
	if(a[n] > r){
		dfs(n+1, l, a[n]);
	}

	return;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			cin >> a[j];
		}
		flag = false;
		dfs(0, 0, 0);
		if(flag){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
int main (){
       int N,a[20]={0},b[20]={0},t;
       cin>>N;
       for(int j=0;j<N;j++){
       int ac=0,bc=0;
       for(int i=0;i<10;i++){
              cin>>t;
              if(a[ac]<t){
                 a[ac+1]=t;
                 ac++;
               }
               else if(b[bc]<t){
                  b[bc+1]=t;
                  bc++;
                }
       
                else break;
           
           }
           if(ac+bc==10){
                 cout<<"YES"<<endl;
            }
           else cout<<"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==9){
		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 <vector>

using namespace std;

int B[10];

bool solve() {
    vector<int> a, b;
    a.push_back(0);
    b.push_back(0);
    for (int i = 0; i < 10; i++) {
        if (a.back() < B[i]) {
            a.push_back(B[i]);
        } else if (b.back() < B[i]) {
            b.push_back(B[i]);
        } else {
            return false;
        }
    }
    return true;
}

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> B[j];
        }
        cout << (solve() ? "YES" : "NO") << endl;
    }
    return 0;
}

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

int main()
{
	std::vector<int> a;
	std::vector<int> b;

	int n = 0;
	std::cin >> n;

	while (n--)
	{
		bool is_failure = false;

		int datas[10] = { 0 };
		std::cin >> datas[0] >> datas[1] >> datas[2] >> datas[3] >> datas[4] >> datas[5] >> datas[6] >> datas[7] >> datas[8] >> datas[9];

		std::stack<int> stack_a{};
		std::stack<int> stack_b{};

		for (auto data : datas)
		{
			if (stack_a.empty())
			{
				stack_a.push(data);
				continue;
			}

			if (stack_a.top() < data)
			{
				stack_a.push(data);
				continue;
			}

			if (stack_b.empty())
			{
				stack_b.push(data);
				continue;
			}

			if (stack_b.top() < data)
			{
				stack_b.push(data);
				continue;
			}

			is_failure = true;
			break;
		}

		if (false == is_failure)
		{
			std::cout << "YES" << std::endl;
		}
		else
		{
			std::cout << "NO" << std::endl;
		}
	}

	return 0;
}