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 <iostream>
#include <algorithm>

using namespace std;

int n;
int a[1000][11];
int stock[2][11];
int usea[11];

int dfs(int num, int r_num, int l_num) {
	int res = 0;

	if (usea[num] > stock[0][r_num]) {
		if (num == 9)
			return 1;
		stock[0][r_num + 1] = num;
		res = dfs(num + 1, r_num + 1, l_num);
		stock[0][r_num + 1] = -1;
		return res;
	}
	else if (usea[num] > stock[1][l_num]) {
		if (num == 9)
			return 1;
		stock[1][l_num + 1] = num;
		res = dfs(num + 1, r_num, l_num + 1);
		stock[1][l_num + 1] = -1;
		return res;
	}
	else {
		return 0;
	}
}


int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> a[i][j];
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			usea[j] = a[i][j];
		}
		stock[0][0] = -1;
		stock[0][1] = usea[0];
		stock[1][0] = -1;
		if (dfs(0, 1, 0)) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
		stock[0][0] = -1;
		stock[0][1] = -1;
		stock[1][0] = -1;
	}

	return 0;
}

C++: #include<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
bool sorted(vector<int> a){
	for(int x=0;x<a.size()-1;++x){
		if(a[x]>a[x+1])return false;
	}
	return true;
}
int main(){
	int n;
	cin>>n;
	for(int x=0;x<n;++x){
		vector<int> a,b;
		for(int x=0;x<10;++x){
			int j;cin>>j;
			if(x%2==0){
				a.push_back(j);
			}else{
				b.push_back(j);
			}
		}
		if(sorted(a) && sorted(b)){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}		
	}
	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>
#include<cstdlib>
#include<cmath>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;

int N;

int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };

int ball[10];

int B = 0, C = 0;

int bfs(int n) {
	if (n = 9) {
		return true;
	}

	if (B < ball[n]) {
		return bfs(n + 1);
	}
	if (C < ball[n]) {
		return bfs(n + 1);
	}
	
	return false;

}

void input(void) {
	for (int i = 0; i < 10; i++) {
		CI ball[i];
	}
	return;
}


int main(void) {
	CI N;

	for (int i = 0; i < N; i++) {
		input();
		if (bfs(0)) {
			CO "YES" E
		}
		else {
			CO "NO" E
		}
	}
	
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(void) {
    int N, a, b, c;
    cin >> N;
    for (; N--; ) {
        b = c = 0;
        bool ok = true;
        for (int i = 0; i < 10; i++) {
            cin >> a;
            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<cstdio>
/*
2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
3 5 4 6 1 2 7 8 9 10
4 5 6 7 8 9 1 2 3 10
*/
int n;
int a[12];

int  dsf(int x, int num){
    //将所在数字???-1
    a[x] = -1;
    //向后遍?数?，?足条件?将num???当前数字，并且?用本方法。

    int flag2 = 0;

    for(int i = x; i < 10; i++){

        if(a[i] == num + 1){

            num = a[i];
            dsf(i,num);

            flag2 ++;//只要?行??条件，????1
        }
    }
    if(flag2 == 0)//?明数?中元素不符合条件
             return 0;
    if(flag2 > 2)
             return 0;
    return 1;
}
int main(){

    scanf("%d",&n);
    int i=1;
    while(i <= n){
        int flag = 1;

        //存数据
        for(int x = 0; x < 10; x++){
            scanf("%d",&a[x]);
        }

        //?用方法，将?足条件的数字改?-1
        for(int x = 0; x < 10; x++){
            if(a[x] != -1)
                if(dsf(x,a[x]) == 0)                     //只要??数?中有一个元素不符合条件，?跳出，避免将所有数据?入并???-1
                    break;
        }

        //遍?数?的数?是否都?-1
        for(int x = 0; x < 10; x++){

            if(a[x] != -1)
                flag = 0;
        }
        //判断并?出?果
        if(flag == 1) printf("YES\n");
            else printf("NO\n");

        i++;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int A[15];
int L[15];int R[15];
int n;

bool dfs(int i, int j, int k)
{
	
	if(i==10) return true;
	if(A[i] > L[j-1])
	{
		L[j] = A[i];
		if(dfs(++i,++j,k))
			return true;
	}
	if(A[i] > R[k-1])
	{
		R[k] = A[i];
		if(dfs(++i,j,++k))
			return true;	
	}	
	return false;
}
void solve()
{

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

int main()
{
	
	cin >>n;
	while(n--)
	{
		for(int i =0; i<10; i++)
			cin >> A[i];
		L[0] = R[0] = 0;		
		solve();
	}
}

C++: #include"iostream"
#include"stdio.h"
using namespace std;
int ball[11];
bool flag;
 
void Dfs(int i,int left,int right)
{
    if(flag) return;
    if(i==10) {flag=true;return;}
 
    if(ball[i]>left)
        Dfs(i+1,ball[i],right);
    if(ball[i]>right)
        Dfs(i+1,left,ball[i]);
}
 
int main()
{
    int t;
    while(scanf("%d",&t)==1)
    {
        while(t--){
            flag=false;
            for(int i=0;i<10;i++)
                cin>>ball[i];
            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;

	cin >> N;

	for (int i = 0; i < N; i++){
		int  b = 1, c = 1;
		int num[10];
		int B[11] = { 0 }, C[11] = { 0 };
		bool flag = false;
		

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

		for (int i = 0; i < 10; i++){
			if (B[b-1] < num[i]){
				//cout << "B" << B[b-1] << ' '<< num[i]<< endl;
				B[b] = num[i];
				b++;
			}
			else{
				//cout << "C" << C[c - 1] << ' ' << num[i] << endl;
				if (C[c-1] < num[i]){
					C[c] = num[i];
					c++;
				}
				else{
					flag = true;
					break;
				}

			}
		}

		if (flag == false) cout << "YES" << endl;
		if (flag == true) cout << "NO" << endl;
	}
}