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 main(void){

  int b[5];
  int c[5];

  int n;
  cin >> n;
  while(n--){

    int a[10];
    int j = 0;
    int k = 0;
    for( int i = 0 ; i < 10 ; i++ ){
      cin >> a[i];
      if( i % 2 == 0 ){
	b[j++] = a[i];
      }
      if( i % 2 == 1 ){
	c[k++] = a[i];
      }
    }
    int cnt_b = 0;
    int cnt_c = 0;
    for( int i = 0 ; i < 4 ; i++ ){
      if( b[i] < b[i+1] )cnt_b++;
      if( c[i] < c[i+1] )cnt_c++;
    }
    if( cnt_b == 4 && cnt_c == 4 ) cout << "YES" << endl;
    else cout << "NO" << endl; 
  }
 return 0;
}

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

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    int t;
    cin>>t;
    while(t--){
        int ball[10];
        for(int i=0;i<10;i++){
            cin>>ball[i];
        }

        int left=0;
        int right=0;

        bool ok=true;
        bool direction=true;
        while(ok){
            for(int i=0;i<10;i++){
                if(direction){
					
                    if(ball[i]>left){
                        left=ball[i];
                        direction=!direction;
                    }
					
                    else{
                        ok=false;
                        break;
                    }
                }

                else{

                    if(ball[i]>right){
                        right=ball[i];
                        direction=!direction;
                    }

                    else{
                        ok=false;
                        break;
                    }
                }
            }
            break;
        }

        if(ok) cout<<"YES";
        else cout<<"NO";
        if(t) cout<<endl;
    }

    return 0;
}

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

using namespace std;

int main() {

	int j, n, end=0;
	stack<int> B, C;
	int A[10];

	cin >> n;
	for(; n!=0; n--) {
		for(int i=0; i<10; i++) {
			cin >> A[i];
		}
		B.push(0);
		C.push(0);
		for(int i=0; i<10; i++) {
			j=A[i];
			if(B.top()==0)
				B.push(j);
			else {
				if(B.top()>j) {
					if(C.top()>j) {
						end++;
						break;
					}
					else 
						C.push(j);
				}
				else {
					if(C.top()>j)
						B.push(j);
					else
						(j-B.top()>j-C.top()) ? C.push(j) : B.push(j);
				}
			}
		}

		if (end!=0)
			cout << "NO" << endl;
		else
			cout << "YES" << endl;
		end=0;
	}

	return 0;

}

C++: #include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int N,i,a,j,s,t,u;
	cin >> N;
	for (i = 0; i < N; i++) {
		s = 0;
		t = 0;
		u = 0;
		for (j = 0; j < 10; j++) {
			cin >> a;
			if (a > s) {
				s = a;
			}
			else if (a<s&&a>t) {
				t = a;
			}
			else if (a < s&&a < t) {
				u = 1;
			}
		}
		if (u == 0) {
			cout << "YES" << endl;
		}
		else if (u == 1) {
			cout << "NO" << endl;
		}
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  while(n--) {
    int a[10],b=0,c=0,i;
    for(i=0; i<10; i++) cin >> a[i];
    for(i=0; i<10; i++) {
      if(a[i]>b && a[i]>c) {
	if(b>c) b=a[i];
	else c=a[i];
      }
      else if(a[i]>b && a[i]<c) b=a[i];
      else if(a[i]<b && a[i]>c) c=a[i];
      else break;
    }
    if(i==10) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<iostream>

using namespace std;

int N;
int num[10];
bool flag = false;

void dfs(int a, int b, int cnt){
    if(cnt==10) flag = true;
    if(a < num[cnt]) dfs(num[cnt], b, cnt+1);
    if(b < num[cnt]) dfs(a, num[cnt], cnt+1);
}

int main(){
    scanf("%d\n", &N);
    for(int i=0; i<N; i++){
        flag = false;
        for(int j=0; j<10; j++) scanf("%d", num+j);
        dfs(0,0,0);
        if(flag) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
void dfs(int b[10],int c[10],int m,int k,int t);//a中，b中，c中游标
int a[10];
int flag;
int main()
{
	int N;
	cin >> N;
	while (N--)
	{
		for (int i = 0; i < 10; i++)
			cin >> a[i];
		int b[10];
		int c[10];
		b[0] = 0;
		c[0] = 0;
		flag = 0;
		dfs(b, c, 0, 0, 0);
		if (flag== 1)
			cout << "YES" << endl;
		else 
			cout << "NO" << endl;
	}
	return 0;
}
void dfs(int b[10], int c[10], int m, int k, int t)
{
	int ma = m;
	int kb = k;
	int tc = t;
	int i;
	int x[10], y[10];             //用x,y去中间值，好进行回溯
	if (ma == 10)
		flag=1;
	for (i = 0; i <=kb; i++)
	{
		x[i] = b[i];	
	}
	for (i = 0; i <= tc; i++)
	{
        y[i] = c[i];
	}
	/*if (x[kb] > a[ma] && y[tc] > a[ma])  //两个都大  不要直接return 应该返回 找其他的枝丫
		return 0;*/
	if (x[kb] > a[ma] && y[tc] < a[ma])
	{
		y[tc] = a[ma];
		ma++; tc++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
	}
	if (x[kb] < a[ma] && y[tc] > a[ma])
	{
		x[kb] = a[ma];
		ma++; kb++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
	}
	if (x[kb] < a[ma] && y[tc] < a[ma])
	{
		x[kb] = a[ma];
		ma++; kb++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
		ma--; kb--;
		y[tc] = a[ma];
		ma++; tc++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
		ma--; tc--;
	}
}

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

void DFS(int* arr, int pos, int* res, int index, bool& flag) {
	if (pos >= 10||flag)
	{
		return;
	}
	if ((index==0) || (index >= 1 && res[index - 1] < arr[pos]))
	{
		res[index] = arr[pos];
		arr[pos] = 0;
	}
	DFS(arr, pos+1, res, index+1, flag);
	if (flag)
	{
		return;
	}
	int pre = 0;
	int cur = 0;
	flag = true;
	for (int i = 0; i < 10; i++)
	{
		if (arr[i]!=0)
		{
			pre = pre == 0 ? arr[i] : cur;
			cur = arr[i];
			if (cur < pre)
			{
				flag = false;
				break;
			}
		}
	}
}

int main()
{
	int N, arr[11], res[10];
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			cin >> arr[j];
		}
		bool flag = false;
		DFS(arr, 0, res, 0, flag);
		if (flag)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
	return 0;
}

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

int main() {
	int n, x, z;
	cin >> n;

	for (int i = 0; i < n; i++) {
		vector< vector<int> > v{ {0} };
		for (int j = 0; j < 10; j++) {
			cin >> x;
			z = v.size();
			for (int k = 0; k < z; k++) {
				if (v[k].back() < x) {
					v[k].push_back(x);
					break;
				}

				if (k == z - 1) {
					v.push_back({ x });
					break;
				}
			}

			if (v.size() == 3) {
				x = -1;
				break;
			}
		}

		if (x == -1) {
			cout << "NO";
		}
		else {
			cout << "YES";
		}
		cout << endl;
	}
	return 0;
}