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 <vector>
int ball[10];
int left = 0,right = 0;
bool dfs(int de,int left, int right){//??????????????§???????????????
	if(de == 9)return true;
	if(left < ball[de]){
		left = ball[de];
		return dfs(de + 1,left,right);
	}
	if(right < ball[de]){
		right = ball[de];
		return dfs(de + 1,left,right);
	}
	return false;
}

int main(){
	int n;
	std::cin >> n;
	while(n--){
		for(int i = 0; i < 10; ++i){
			std::cin >> ball[i];
		}
		left = 0, right = 0;
		if(dfs(0,0,0))std::cout << "YES" << std::endl;
		else std::cout << "NO" << std::endl;
	}
}

C++: #include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
int N, acnt, bcnt;
int x[10], A[10], B[10];

bool dfs(int cnt) {
    if (cnt == 10) return true;
    // Aに入れる
    if (A[acnt] < x[cnt]) {
        A[++acnt] = x[cnt];
        return dfs(cnt+1);
    }
    // Bに入れる
    else if (B[bcnt] < x[cnt]) {
        B[++bcnt] = x[cnt];
        return dfs(cnt+1);
    }
    return false;
}

int main(void) {
    cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 10; j++) {
            A[j] = 0; B[j] = 0;
        }
        acnt = 0; bcnt = 0;
        for (int j = 0; j < 10; j++) cin >> x[j];
        if (dfs(0)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
int num[10];
int left=-100000000000,right=-100000000000;
int dfs(int m){
	if(m==10)
	return 1;
	if(num[m]>=left){
		int nleft=left;
		left=num[m];
		if(dfs(m+1))
		return 1;
		left=nleft;
	}
	if(num[m]>=right){
		int nright=right;
		right=num[m];
		if(dfs(m+1))
		return 1;
		right=nright;
	}
	return 0;
}
int main(){
	int n;
	scanf("%d",&n);
	while(n--){
		for(int i=0;i<10;i++){
			scanf("%d",&num[i]);
		}
		if(dfs(0))
		printf("YES\n");
		else
		printf("NO\n");
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>

using namespace std;

int main(void)
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int k=0; k<n; k++) {
        int a[10];
        for(int i=0; i<10; i++) cin >> a[i];
        int b=-1, c=-1;
        bool f = 0;
        for(int i=0; i<10; i++) {
            if(b<a[i]) {
                b = a[i];
            } else if(c<a[i]) {
                c = a[i];
            } else {
                f = 1;
                break;
            }
        }
        printf("%s\n", f ? "NO" : "YES");
    }

    return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    int n; cin>>n;
    rep(i,n){
        vi v(11,0); pii pr; bool check=true;
        rep(i,10)cin>>v[i];
        pr.first=v[0];
        pr.second=v[1];
        for(int j=2; j<10;j++){
            int left=(-pr.first+v[j]); int right=(-pr.second+v[j]);
            if(pr.first>v[j]&&pr.second>v[j])check=false;
            else if(right>left&&v[j]>pr.first)pr.first=v[j];
            else if(right<left&&v[j]>pr.second)pr.second=v[j];
            else if(left>0&&right<0)pr.first=v[j];
            else if(left<0&&right>0)pr.second=v[j];
            else check=false;
            
        }
        if(check)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}

C++: #include <iostream>

using namespace std;

bool s( int ord[], int const i, int const bef = -1 )
{
    if ( i > 10 )
        return true;

    if ( bef != -1 && bef > ord[i] )
        return false;

    return s( ord, i+1, ord[i] ) || s( ord, i+2, ord[i] ) && s( ord, i+2, ord[i+1] );
}

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

    for( int iii=0; iii<n; ++iii ) {
        int ord[10];
        for( int i=0; i<10; ++i )
            cin >> ord[i];

        cout << ( s( ord, 0 ) || s( ord, 1 ) ? "YES" : "NO" ) << endl;
    }
}

C++: #include<iostream>
#include<cstring>
using namespace std;
void dfs(int b[11],int c[11],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[11], int c[11], int m, int k, int t)
{
	int ma = m;
	int kb = k;
	int tc = t;
	int i;
	int x[11], y[11];             //用x,y去中间值，好进行回溯
	if (ma == 10)
		flag=1;
	else
	{
		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])
		{ 
			tc++;
			y[tc] = a[ma];
			ma++;
			dfs(x, y, ma, kb, tc);
		}
		else if (x[kb] < a[ma] && y[tc] > a[ma])
		{
			kb++;
			x[kb] = a[ma];
			ma++; 
			dfs(x, y, ma, kb, tc);
		}
		else if (x[kb] < a[ma] && y[tc] < a[ma])
		{
			kb++;
			x[kb] = a[ma];
			ma++;
			dfs(x, y, ma, kb, tc);
			ma--; kb--;
            tc++;
			y[tc] = a[ma];
			ma++;
			dfs(x, y, ma, kb, tc);
			ma--; tc--;
		}
	}
}

C++: //
//  0033.cpp
//  
//
//  Created by Yoshida Satoshi on 2017/11/16.
//
//

#include <iostream>
using namespace std;

void tsumu(int l,int r,int* in,int j,bool *ans){
    if(j==9){
        *ans=true;
        return;
    }
    if(in[j]>l) tsumu(in[j],r,in,j+1,ans);
    if(in[j]>r) tsumu(l,in[j],in,j+1,ans);
    
    return;
}

int main(){
    int N;
    int in[10];
    int l;
    int r;
    bool ans;
    
    cin>>N;
    for(int i=0;i<N;i++){
        ans=false;
        l=r=0;
        for(int j=0;j<10;j++){
            cin>>in[j];
        }
        tsumu(l,r,in,0,&ans);
        if(ans) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        
    }
    return 0;
}