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

using namespace std;

vector<int> minvec(vector<int> v1, vector<int> v2){
  if(v1.back() < v2.back()){
	return v1;
  }else{
	return v2;
  }
}

vector<int> maxvec(vector<int> v1, vector<int> v2){
  if(v1.back() < v2.back()){
	return v2;
  }else{
	return v1;
  }
}

int main(void){
  int n;
  int i,j;
  vector<int> q;
  //vector<int> out[2];
  int tmp;
  bool isok = true;
  int a=0, b=0;
  cin >> n;
  for(i=0;i<n;i++){
	for(j=0;j<10;j++){
	  cin >> tmp;
	  q.push_back(tmp);
	}

	for(j=0;j<10;j++){
	  if(q[j] > max(a, b)){
		max(a,b) == a ? a = q[j] : b = q[j];
	  }else if(q[j] < min(a,b)){
		cout << "NO" << endl;
		isok = false;
		break;
	  }else{
		min(a,b) == a ? a = q[j] : b = q[j];
	  }
	}

	if(isok) cout << "YES" << endl;
	isok = true;
	q.clear();
	a = 0; b = 0;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <functional>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

int t,n=10,a[10002],b[10002],c[10002];
bool flag;

void dfs(int dep,int db,int dc)
{
	if(!flag)return;
	if(dep==n)
	{
		flag=0;
		for(int i=1;i<db;++i)
			if(b[i]<b[i-1])
				flag=1;
		for(int i=1;i<dc;++i)
			if(c[i]<c[i-1])
				flag=1;
		return;
	}
	b[db]=a[dep];
	dfs(dep+1,db+1,dc);
	c[dc]=a[dep];
	dfs(dep+1,db,dc+1);
}
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		flag=1;
		for(int i=0;i<n;++i)
			scanf("%d",&a[i]);
		dfs(0,0,0);
		if(flag)
			printf("NO\n");
		else
			printf("YES\n");
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int N,temp;
	int b,tempb,tempc,ch;
	
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		tempb=0;
		tempc=0;
		ch=0;
		for(int j=0;j<10;j++){
			scanf("%d",&temp);
			if(tempb<temp)
			tempb=temp;
			else if(tempc<temp)
			tempc=temp;
			else{
				ch=1;
				break;
			}
		}
		if(ch==0)
		printf("YES\n");
		else
		printf("NO\n");
	}
}

C++: #include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
#include <math.h>
#include <sstream>
using namespace std;
int ball[10];
bool dfs(int i,int b,int c);
int main(void){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int s=0;s<10;s++){
            cin>>ball[s];
        }
        if(dfs(0,0,0))cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}
bool dfs(int i,int b,int c){
    if(i==10)return true;
    if(b<ball[i]){
        if(dfs(i+1,ball[i],c))return true;
    }
    if(c<ball[i]){
        if(dfs(i+1,b,ball[i]))return true;
    }
    return false;
}

C++: #include<iostream>
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(b, c, ma, kb, tc);
		 kb--;
		y[tc] = a[ma];
		 tc++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
	}
}

C++: #include<cstdio>
int main()
{
	int k;
	scanf("%d",&k);
	while(k>0)
	{
		int last1=-100,last2=-100,flag=0;
		for(int i=1;i<=10;i++)
		{
			int x;
			scanf("%d",&x);
			if(flag==0)
			{
				if(x>last1)
					last1=x;
				else if(x>last2)
					last2=x;
				else
				{
					printf("NO\n");
					flag=1;
				}
			}
		}
		if(flag==0)
			printf("YES\n");
		k--;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
 
int a[10];
int n;
 
bool dfs(int i,int left,int right){
    if(i==10) return true;
    if(a[i]>left){
        return dfs(i+1,a[i],right);
    }
    if(a[i]>right){
        return dfs(i+1,left,a[i]);
    }
    return false;
}
 
void solve(){
    for(int i=0;i<10;i++) cin >> a[i];
    if(dfs(0,0,0)) cout << "YES" << endl;
    else cout << "NO" << endl;
    return;
}
 
int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        solve();
    }
    return 0;
}

C++: /* AOJ0033 Ball */

#include <stdio.h>

#define N 10

int main(void)
{
    int n, ans, i;

    scanf("%d", &n);
    while(n--) {
        ans = 1;
        int a, b=-1, c=-1;
        for(i=1; i<=N; i++) {
            scanf("%d", &a);
            if(ans) {
                if(a > b)
                    b = a;
                else if(a > c)
                    c = a;
                else
                    ans = 0;
            }
        }

        printf("%s\n", ans ? "YES" : "NO");
    }

    return 0;
}

C++: #include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int n;
int a[10];

int main(int argc, char const* argv[])
{
	cin >> n;
	for(int i = 0; i < n; i++){
			for(int j = 0; j < 10; j++){
					cin >> a[j];
			}
			int l = 0;
			int r = 0;
			bool flag = true;
			for(int j = 0; j < 10; j++){
					if(!flag)break;
					if(a[j] <= l && a[j] <= r){
							flag = false;
					}else if(a[j] <= l && a[j] > r){
							r = a[j];
					}else if(a[j] > l && a[j] <= r){
							l = a[j];
					}else{
							if(l > r){
									l = a[j];
							}else{
									r = a[j];
							}
					}
			}
			if(!flag)cout << "NO" << endl;
			else cout << "YES" << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int ball[10];
int l,r;
bool flag;
void dfs(int num,int l,int r){
	if(num==10) return ;
//	if(flag) return ;
	if(ball[num]>l) dfs(num+1,ball[num],r);
	else if(ball[num]>r) dfs(num+1,l,ball[num]);
	else{
		flag=true;
		return ;
	}
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int i=0;i<10;i++){
			cin>>ball[i];
		}
		l=0,r=0;
		flag=false;
	    dfs(i,l,r);
		if(flag){
			cout<<"NO"<<endl;
		}else{
			cout<<"YES"<<endl;
		} 
	}
}