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<string>
using namespace std;
int main(){
	int n,a[10];
	cin>>n;
	for(int i=0;i<n;i++){
		bool t=true;
		for(int j=0;j<10;j++)
			cin>>a[i];
		int b,c;
		if(a[0]>a[1]){
			b=a[0];
			c=a[1];
		}
		else{
			b=a[1];
			c=a[0];
		}
		for(int j=2;j<10;j++){
			if(c>a[j])
				t=false;
			if(c<a[j]&&b>a[j])
				c=a[j];
			if(b<a[j])
				b=a[j];
		}
		if(t==true)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {

	int a, b=0, i, N, x[10], end=0;

	cin >> N;
	for(; N!=0; N--) {
		for(i=0; i<10; i++)
			cin >> x[i];
		for(i=0; i<10; i++) {
			if(i==0) {
				a=x[i];
				i++;
			}
			if(a>x[i]&&b>x[i]) {
				end++;
				break;
			}
			if(a>x[i]) {
				if(b<x[i])
					b=x[i];
			}
			else {
				if(b>x[i])
					a=x[i];
				else
					a>b ? a : b =x[i];
			}
		}

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

	return 0;

}

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

using namespace std;

int caseCnt, numbers[10], curNum;
stack<int> Left, Right;

bool used[10], result;

void clear_stack(){
    while( !Left.empty())  Left.pop();
    while(!Right.empty()) Right.pop();
}

bool dfs(int index, int left_or_right){
    if(!left_or_right){
        if(Left.empty() || numbers[index] > Left.top())
            Left.push(numbers[index]);
        else
            return false;
    }else{
        if(Right.empty() || numbers[index] > Right.top())
            Right.push(numbers[index]);
        else
            return false;
    }
    if(index == 9)return true;
    else if(dfs(index+1, 0))return true;
    else if(dfs(index+1, 1)) return true;
    else return false;
}

int main(){
    cin >> caseCnt;

    while(caseCnt--){
        result = false;
        clear_stack();

        for(int i=0; i<10; ++i) cin >> numbers[i];

        result = dfs(0, 0);
        if(result){
            cout << "YES\n";
            continue;
        }

        result = dfs(0, 1);
        if(result) cout << "YES\n";
        else       cout << "NO\n";
    }
    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std;
int ball[15];
int leftFront, rightFront;
bool isOK;
void DFS(int depth)
{
    if(depth == 10 || isOK)
    {
        isOK = true;
        return;
    }

    if(ball[depth] > leftFront)
    {
        leftFront = ball[depth];
        DFS(depth + 1);
    }

    if(ball[depth] > rightFront)
    {
        rightFront = ball[depth];
        DFS(depth + 1);
    }

    return;
}
int main(void)
{
	int n;
	scanf("%d", &n);

	while(n--)
    {
        for(int i = 0; i < 10; i++)
            scanf("%d", &ball[i]);

        isOK = false;
        leftFront = 0;
        rightFront = 0;

        DFS(0);

        if(isOK)
            printf("YES\n");
        else
            printf("NO\n");
    }

	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(void){
	int n,a,b,c;
	bool f;
	cin>>n;
	for(int i=0;i<n;i++){
		f=true;b=0;c=0;
		for(int j=0;j<10;j++){
			cin>>a;
			if(b>a&&c>a){
				f=false;
				break;
			}else if(b<a && c<a){
				if(b>=c)b=a;
				else c=a;
			}else if(b<a){
				b=a;
			}else if(c<a){
				c=a;
			}
		}
		if(f)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

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

int main(){
	int n, a, b, in;
	cin >> n;
	for(int i=0;i<n;i++){
		a = 0;
		b = 0;
		for(int j=0;j<10;j++){
			cin >> in;
			if(in>a){
				a = in;
			}
			else if(in>b){
				b = in;
			}
			else{
				cout << "NO" << endl;
				break;
			}
			if (j==9){
				cout << "YES" << endl;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;
#define FOR(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
int num[10];
int B[10];
int C[10];
bool flag;
void solve(int, int, int);

int main(void){
	int N;
	cin >> N;
	for(int k = 0; k < N; k++){
		flag = false;
		fill_n(B , 10, -1);
		fill_n(C , 10, -1);
		for(int i = 0; i < 10; i++){
			cin >> num[i];
		}
		solve(0, 0, 0);
		if(flag){cout << "YES" << endl; continue;}
		cout << "NO" << endl;
	}

	return 0;
}

void solve(int cnt,int right, int left){
	if(cnt == 10){
		flag = true;
		return;
	}
	if(num[cnt] > right) solve(cnt+1, num[cnt], left);
	if(num[cnt] > left) solve(cnt+1, right, num[cnt]);
}

C++: #include <iostream>
#define _for(i,a,b) for(int i = (a); i < b; ++i)
#define _rep(i,a,b) for(int i = (a); i <= b; ++i)
using namespace std;
int a[10+2];
bool flag = 0;
void dfs(int i, int l, int r){
    if(flag) return;
    if(i == 10) {
        flag = 1;
        return;
    }
    if(a[i] > l) dfs(i+1, a[i], r);
    if(a[i] > r) dfs(i+1, l, a[i]);
}
int main(){
    int n;
    cin>>n;
    while(n--){
        flag = 0;
        _for(i,0,10) cin>>a[i];
        dfs(0,0,0);
        if(flag) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
int main()
{
    int N; cin >> N;
    while (N--) {
        int a[10];
        stack<int> b, c;
        for (int i = 0; i < 10; ++i) cin >> a[i];
        b.push(0);
        c.push(0);
        bool ok = true;
        for (int i = 0; i < 10; ++i) {
            if (b.top() > c.top()) {
                if (b.top() < a[i]) b.push(a[i]);
                else if (c.top() < a[i]) c.push(a[i]);
                else ok = false;
            }
            else {
                if (c.top() < a[i]) c.push(a[i]);
                else if (b.top() < a[i]) b.push(a[i]);
                else ok = false;
            }
        }
        cout << (ok ? "YES" : "NO") << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int case_cnt;
int ball[12];
bool visited[12];
int maxx;
int main()
{
  cin>>case_cnt;
  while(case_cnt--)
  {
	
	  for(int i=1;i<=10;i++) 
	  {
		  cin>>ball[i];
		  visited[i]=false;
	  }
	  maxx=ball[1];
	  visited[1]=true;
	  //找到一段递增序列
	  for(int i=2;i<=10;i++) 
	  {
		 if(ball[i]>maxx)
		 {
			 visited[i]=true;
			 maxx=ball[i];
		 }
	  }
	  //剩下的数中有无不递增的。先找到剩下数中的第一个
	  maxx=-1;
	  int i;
	  for(i=2;i<=10;i++) 
	  {
		 if(visited[i]) continue;
		 if(ball[i]<maxx) break;
		 maxx=ball[i];
	  }
	  if(i==11) cout<<"YES"<<endl;
	  else cout<<"NO"<<endl;
  }
   return 0;
}