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>
#define CAPACITY 9
using namespace std;
int b, c;

bool dfs(int pos, int ary[], bool flag) {
    if(pos < 0) {
        return(false);
    }
    
    flag = dfs(pos - 1, ary, flag);
    
    if(pos == CAPACITY) {
        flag = true;
    }
    if(ary[pos] > b) {
        b = ary[pos];
    } else if(ary[pos] > c) {
        c = ary[pos];
    } else {
        return(false);
    }
    cout << "B = " << b << "C = " << c << endl;
    
    return(flag);
}

int main(void) {
    int num;
    
    cin >> num;
    int ary[10];
    
    for(int r = 0; r < num; r++) {
        for(int c = 0; c < 10; c++) {
            cin >> ary[c];
        }
        b = ary[0];
        c = INT_MIN;
        if(dfs(CAPACITY, ary, true)) {
            cout << "YES";
        } else {
            cout << "NO";
        }
        cout << endl;
    }
    
    return(0);
}

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

int main(void){
  int N,temp,flag;
  vector<int> A,B(1,0),C(1,0);
  cin >> N;
  for(int i=0; i<N; ++i){
    while(!A.empty()){
      for(int j=0; j<10; ++j){
	cin >> temp;
	A.push_back(temp);
      }
      temp = A.front();
      if(temp>=*B.end()) B.push_back(temp);
      if(temp>=*C.end()) C.push_back(temp);
      else{
	cout << "NO" << endl;
	flag = 1;
	break;
      }
      A.pop_back();
    }
    if(flag!=1)
      cout << "YES" << endl;
    flag=0;
  }
}

C++: #include<iostream>
#include<vector>
using namespace std;
bool a[15]; 
int d[15];
vector<int> b,c;
int judge; 
void dfs(int n){
	if(n==10){
		for(int i=0;i<10;i++){
			if(a[i]==false){//进c 
				c.push_back(d[i]);
			}
			else{
				b.push_back(d[i]);
			}
		}
		int ok=1;
		for(int j=0;j<b.size()-1;j++){
			if(b[j]>b[j+1]){
				ok=0;
				break;
			}
		}
		for(int j=0;j<c.size()-1;j++){
			if(c[j]>c[j+1]){
				ok=0;
				break;
			}
		}
		if(ok)judge=1;
	}
	else{
		a[n]=true;
		dfs(n+1);
		a[n]=false;
		dfs(n+1);
	}
}
int main(){
	int n;
	cin>>n;
	while(n--){
		b.clear();c.clear(); 
		judge=0;
		for(int i=0;i<10;i++){
			cin>>d[i];
		}
		dfs(0);
		if(judge){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}

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

int main(){
	int ball[10];
	int cell[2][10]={0};
	int n,i,k,cell_1=0,cell_2=0,flag[1000]={0};
	
	scanf("%d",&n);
	
	for(k=0;k<n;k++){
		for(i=0;i<10;i++)scanf("%d",&ball[i]);
		
		cell[0][0]=0;
		cell[1][0]=0;

		for(i=0;i<10;i++){
			if(cell[0][cell_1-1] < ball[i]){
				cell[0][cell_1]=ball[i];
				cell_1++;
			}
			else if(cell[1][cell_2-1] < ball[i]){
				cell[1][cell_2]=ball[i];
				cell_2++;
			}
			else flag[k]=1;
		}	
	}
	
	cell_1=0;
	cell_2=0;
	
	for(i=0;i<n;i++){
		if(flag[i]==0)printf("YES\n");
		else printf("NO\n");
	}
	
	return 0;
}

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

int main()
{
	int n;
	cin >> n;
	for(int x=0;x<n;x++){
		bool flag=true;
		int a,b=0,c=0;
		for(int i=0;i<10;i++){
			cin >> a;
			for(int j=a-1;j>=0;j--){
				if(b==j){
					b=a;
					break;
				}
				if(c==j){
					c=a;
					break;
				}
				if(j==0){
					flag = false;
					break;
				}
			}
		}
		if(flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int a[10];
bool dfs(int i,int j,int k){
	if(k==10||(i<a[k]&&dfs(a[k],j,k+1))||(j<a[k]&&dfs(i,a[k],k+1)))return true;
	return false;
}
int main() {
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		for(int j=0;j<10;j++)cin>>a[j];
		cout<<(dfs(0,0,0)?"YES":"NO");
	}
	return 0;
}

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

using namespace std;

bool flag = false;
int a, b;
vector<int> Vec(10);

void dfs(int pos)
{
	if(pos >= 10)
	{
		flag = true;
		return;
	}
	if(Vec[pos] > a)
	{
		a = Vec[pos];
		dfs(pos + 1);
	}
	if(Vec[pos] > b)
	{
		b = Vec[pos];
		dfs(pos + 1);
	}
}

void solve()
{
	int N;
	cin >> N;
	while(N--)
	{
		a = 0;
		b = 0;
		flag = false;
		for(int i = 0; i < 10; ++i)
		{
			cin >> Vec[i];
		}
		dfs(0);
		if(flag)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

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

int main(){
	int n;
	scanf(" %d", &n);
	for(int i=0; i<n; ++i){
		int b[10];
		for(int j=0; j<10; ++j) scanf(" %d", &b[j]);
		
		bool ans=false;
		//bitloopで全探索
		for(long j=(1<<10)-1; j>=0; --j){
			int left[11], right[11];
			int x=1, y=1;
			left[0]=right[0]=0;
			//printf("%ld\n", j);
			
			bool flag=true;
			
			for(int k=0; k<10; ++k){
				if( (j>>k)&1 ){ //右に入れる
					if(left[x-1] < b[k]) left[x++]=b[k];
					else flag=false;
				}
				else{
					if(right[y-1] < b[k]) right[y++]=b[k];
					else flag=false;
				}
				if(!flag) break;			
			}
			
			if(flag){
				ans=true;
				break;
			}
		}
		
	if(ans) printf("YES\n");
	else printf("NO\n");
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }


int main() {
    int t; cin >> t;
    while(t--) {
        vector<int> ball(10, 0);
        for(int i = 0; i < 10; ++i) cin >> ball.at(i);
        priority_queue<int> aque;
        priority_queue<int> bque;
        bool flg2 = true;
        for(int i = 0; i < 10; ++i) {
            bool flg = false;
            if(!aque.empty()) {
                if(aque.top() <= ball.at(i)) {
                    aque.push(ball.at(i));
                    flg = true;
                }
            }else {
                aque.push(ball.at(i));
                flg = true;
            }
            if(!flg) {
                if(!bque.empty()) {
                    if(bque.top() <= ball.at(i)) {
                        bque.push(ball.at(i));
                        flg = true;
                    }
                }else {
                    bque.push(ball.at(i));
                    flg = true;
                }
            }
            if(!flg) {
                flg2 = false;
                break;
            }
        }
        if(flg2) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

C++: #include<iostream>
using namespace std;
int X,Y;
const int N=10;
int D,ball[N];

bool solve(int i){
	if(i==N)return true;//iがボールの個数に追いついたら終了
	if(X<ball[i]){//入るボールが入ってるボールより大きければ
	X=ball[i];//ボールを入れる
		if(solve(i+1))return true;
	
	}
	if(Y<ball[i]){
	Y=ball[i];
		if(solve(i+1))return true;
	}
	return false;

}
//solve関数　終わる条件→
//solve関数に入った初めの処理→
//solve関数に入って２回目の処理→


int main(){
	cin>>D;
	for(int l=0;l<D;l++){
		for(int i=0;i<N;i++)cin>>ball[i];
		X=ball[0];//一つ目のボールを右に入れておく
			if(solve(1))cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
}	

return 0;
}