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 <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int n;

	cin >> n;

	while(n--){
		int input = 0;
		int left = 0, right = 0;
		bool achieve = true;
		REP(i, 10){
			cin >> input;

			if(left > input && right > input){
				//両方入らなかったら
				achieve = false;
				break;
			}
			else{
				//どっちかにしか入らない場合
				if(left > input || right > input){
					//入る方探して入れる
					if(input > left){
						left = input;
					}
					else{
						right = input;
					}
					achieve = false;
				}
				//どっちにも入る場合
				else{
					//先に入ってる数字が大きい方に入れる
					if(left > right){
						left = input;
					}
					else{
						right = input;
					}
					achieve = true;
				}
			}
		}
		cout << (achieve ? "YES" : "NO") << endl;
	}
	return 0;
}

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

int N;
int order[10];
int l[11];
int r[11];

bool dfs(int i, int b, int c){
    
    if(i == 10)
        return true;
    
    if(order[i] > l[b-1]){
        l[b] = order[i];
        return dfs(i+1, b+1, c);
    }
        
    if(order[i] > r[c-1]){
        r[c] = order[i];
        return dfs(i+1, b, c+1);
    }  
    
    return false;
}

int main(){
    cin >> N;
    while(N--){
        
        for(int i = 0; i < 10; i++){
            cin >> order[i];
            l[i] = -1;
            r[i] = -1;
        }
        
        if(dfs(0, 1, 1))
            cout << "YES\n";
 
        else
            cout << "NO\n";
    }
    return 0;
}

C++: #include<iostream>
int num[10];
int f(int a,int b ,int c) {
	int flag = 0;
	if (a == 9)
		flag = 1;
	if (a == 0)
		return f(1, num[a], 0);
	else if (num[a] > b) {
		if (flag == 1)
			return 1;
		if (num[a] > c)
			return f(a + 1, num[a], c) + f(a + 1, b, num[a]);
		else
			return f(a + 1, num[a], c);
	}
	else if (num[a] > c) {
		if (flag == 1)
			return 1;
		return  f(a + 1, b, num[a]);
	}
	else
		return 0;
}
int main() {
	int n;
	std::cin >> n;
	for (int i = 0; i < n; i += 1) {
		int N[10];
		for (int i = 0; i < 10; i += 1) {
			std::cin >> N[i];
			num[i] = N[i];
		}
		if (f(0, 0, 0) > 0)
			std::cout << "YES" << std::endl;
		else
			std::cout << "NO" << std::endl;
	}
	return 0;
}

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

using namespace std;

int nums[10];

bool check_recursion(int i, int left, int right){
	if(i == 10) return true;
	if(nums[i] > left and check_recursion(i+1, nums[i], right)) return true;
	if(nums[i] > right and check_recursion(i+1, left, nums[i])) return true;
	
	return false;
}

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

	for(;n>0;n--){
		 scanf("%d %d %d %d %d %d %d %d %d %d",&nums[0],&nums[1],&nums[2],&nums[3],&nums[4],&nums[5],&nums[6],&nums[7],&nums[8],&nums[9]);
		 ans = check_recursion(0,0,0);
		 ans ? cout<<"YES"<<endl : cout<<"NO"<<endl;

	}
	return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define int long long

typedef long long ll;
typedef pair<int, int> Pair;

// const int kMaxN;

int N;
int D[10];
string ans;

string Search(int i, vector<int> d1, vector<int> d2) {
  if (i == 10) { return "YES"; }

  if (d1.empty() || d1.back() < D[i]) {
    d1.push_back(D[i]);
    if (Search(i+1, d1, d2) == "YES") { return "YES"; }
    d1.pop_back();
  }
  if (d2.empty() || d2.back() < D[i]) {
    d2.push_back(D[i]);
    if (Search(i+1, d1, d2) == "YES") { return "YES"; }
  }

  return "NO";
}

signed main() {
  cin >> N;

  while (N-- > 0) {
    REP(i, 10) { cin >> D[i]; }
    vector<int> d1, d2;
    ans = Search(0, d1, d2);
    cout << ans << endl;
  }

  return 0;
}

C++: #include <cstdio>
int main()
{
 int set[100][10],i,j;
 int t[100]={1};
 scanf("%d",&i);

 for(i=0;i<100;i++)
{
	for(j=0;j<10;j++)scanf("%d",&set[i][j]);
	for(j=0;j<8;j++)
	{
	if(set[i][j+2]<set[i][j+1]&&set[i][j+2]<set[i][j])t[i]=0;
	}
	
	if(t[i]==0)puts("NO");
	if(t[i]==1)puts("YES");
}

return 0;
}

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

int b[10],c[10],bi,ci,flag;

int main()
{
    int n,ball;
    scanf("%d", &n);
    for(int I=0;I<n;++I) {
        for(int i=0;i<10;++i) {
            scanf("%d", &ball);
            if (!bi) { b[bi] = ball; ++bi; continue; }
            else if (!ci) { c[ci] = ball; ++ci; continue; }
            else if (b[bi] < ball) {
                ++bi;
                b[bi] = ball;
                continue;
            } else if (c[ci] < ball) {
                ++ci;
                c[ci] = ball;
                continue;
            } else {
                ++flag;
                break;
            }
        }
        (flag) ? puts("NO") : puts("YES");
    }

    return 0;
}

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

using namespace std;


bool tansaku(vector<int> list,int index,int b,int c)
{
	if (index<10)
	{
		if (b < list[index])
		{
			if (tansaku(list, index + 1, list[index], c))
				return true;
		}
		if (c < list[index])
		{
			if (tansaku(list, index + 1, b, list[index]))
				return true;
		}
	}
	else
	{
		return true;
	}
	return false;
}
int main()
{
	vector<int> s(10);
	int b;

	cin >> b;
	for (int i = 0; i < b; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			cin >> s[j];
		}
		if (tansaku(s, 0, 0, 0))
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}

	return 0;
}

C++: #include <stdio.h>

int main(void){
	int topB,topC;
	int n,tmp;
	int valid;
	
	for (scanf("%d", &n); n--;){
		topB=topC=0;
		valid=1;
		for (int i=0; i<10; i++){
			scanf("%d", &tmp);
			if (tmp > topB) topB=tmp;
			else if (tmp > topC)topC=tmp;
			else {
				valid=0; break;
			}
		}
		printf("%s\n",valid?"YES":"NO");
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
bool solve(int, int, int);
int a[10];

int main(void){
	int n;
	char t;
	bool flag;
	cin >> n;
	do{
		n--;
		cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> a[5] >> a[6] >> a[7] >> a[8] >> a[9];
		if(solve(0,0,0)){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}while(n != 0);
	return 0;
}

bool solve(int i, int b, int c){
	if(i == 9){
		if(a[i] > b || a[i] > c)
			return (true);
		return(false);
	}
		if(solve(i + 1, a[i], c) || solve(i + 1, b, a[i])){
			return (true);
		}
	return (false);
}

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

int dfs( int, int, int );

int BallData[10];

int main()
{

	int N, ans;

	cin >> N;

	for( int i = 0; i < N; i++ ) {
		for( int j = 0; j < 10; j++ ) {
		
			cin >> BallData[j];

			ans = dfs(0, 0, 0);

		}

		if ( ans == 0 ) {
			cout << "NO" << endl;
		}
		else {
			cout << "YES" << endl;
		}

	}
	
	return 0;

}

int dfs( int i, int Left, int Right )
{

	int ans = 0;

	if( i == 10 ) ans = 1;

	if( BallData[i] > Left ) {
		ans = dfs( i + 1, BallData[i], Right );	
	}
	if( BallData[i] > Right ) {
		ans = dfs( i + 1, Left, BallData[i] );
	}

	return ans;

}