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 <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int a[10];
int b[10];
bool flag;
int c[10];
void dfs(int aa,int bb,int cc)
{
    if(bb+cc==10)
    {
        flag=true;
        return ;
    }
    if(bb==0||(a[aa]>b[bb-1]&&b[bb]==0))
    {
        b[bb]=a[aa];
        dfs(aa+1,bb+1,cc);
        b[bb]=0;
    }
    if(cc==0||(a[aa]>c[cc-1]&&c[cc]==0))
    {
        c[cc]=a[aa];
        dfs(aa+1,bb,cc+1);
        c[cc]=0;
    }
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        for(int i=0;i<10;i++)
            cin>>a[i];
        flag=false;
        dfs(0,0,0);
        if(flag)
            printf("YES\n");
        else
            printf("NO\n");


    }
    return 0;
}

C++: #include <cstdio>
using namespace std;
int A[10];
int N;
int flag;

void dfs(int x, int l, int r) {
  if (x == 10) return;
  if (flag) return;
  if (A[x] > l)
    dfs(x + 1, A[x], r);
  else if (A[x] > r)
    dfs(x + 1, l, A[x]);
  else {
    flag = 1;
    return;
  }
}

int main() {
  scanf("%d", &N);
  while (N--) {
    for (int i = 0; i < 10; i++) scanf("%d", &A[i]);
    flag = 0;
    dfs(0, 0, 0);
    if (flag)
      printf("NO\n");
    else
      printf("YES\n");
  }
}

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

using namespace std;

int ball[11];
int a[11],b[11];
bool ans;

bool dfs(int i,int p,int q)
{
	 if(ball[i] < a[p] && ball[i] < b[q]) return false;
	 if(i == 9) return true;
	 bool tmp = false;
	 if(a[p] < ball[i])
	 {
		 a[p+1] = ball[i];
		 tmp = (tmp || dfs(i+1,p+1,q));
	 }
	 if(b[q] < ball[i])
	 {
	 	b[q+1] = ball[i];
		 tmp = (tmp || dfs(i+1,p,q+1));
	 }
	 return tmp;
}


int main ()
{
	int n;
	cin >> n;
	for(int i= 0;i<n;i++)
	{
		a[0]=0,b[0]=0;
		for(int j = 0;j < 10;j++) cin >> ball[j];
		a[1] = ball[0];
		ans = dfs(1,0,0);
		if(ans) 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] );
}

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>
using namespace std;
int main(){
	int N;
	cin >> N;
	while(N--){
		int pipe[2] = {0};
		int i=0;
		bool f=false;
		for(; i < 10; i++){
			int num;
			cin >> num;
			if(pipe[1] > pipe[0]){
				
				if(num > pipe[1]){
					pipe[1] = num;
				}else if(num > pipe[0]){
					pipe[0] = num;
				}else{
					f=true;
				}
				
			}else{
				if(num > pipe[0]){
					pipe[0] = num;
				}else if(num>pipe[1]){
					pipe[1] = num;
				}else{
					f=true;
				}
			}
			
		}
		if(!f) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

C++: #include <cstdio>

using namespace std;

bool dfs(int a[],int anum,int bpre,int cpre,int p){
	int ret = 0;
	if(p == anum){
		return 1;
	}
	if(bpre == -1 || a[p] > bpre){
		ret += dfs(a,anum,a[p],cpre,p + 1);
	}
	if(cpre == -1 || a[p] > cpre){
		ret += dfs(a,anum,bpre,a[p],p + 1);
	}
	return ret;
}

bool solve(int a[]){
	return dfs(a,10,-1,-1,0);
}

int main(void){
	int n, i, j, a[10];
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		for(j = 0;j < 10;j++){
			scanf("%d",&a[j]);
		}
		if(solve(a)){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}

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

int l=0, r=0;
bool flag=true;

void solve(int N) {
	int a = 0;
	while (N > 0) {
		for (int i = 0; i < 10; i++) {
			cin >> a;
			if (a > l)
				l = a;
			else if (a > r)
				r = a;
			else 
				flag = false;
		}
		if (flag == true)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
		flag = true;
		N--;
	}
}
int main() {
	int n = 0;
	cin >> n;
	solve(n);
	return 0;
}

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

int l,r,x,ball[11],le[11],ri[11],ans,n;
int dfs(int i,int l,int r){
    if(i > 9){
        return ans=1;
    }
    if(le[l]<ball[i]){
        le[++l]=ball[i++];
        dfs(i,l,r);
    }
    else if(ri[r]<ball[i]){
        ri[++r]=ball[i++];
         dfs(i,l,r);
    }
    else
        ans=0;
}
void solve(){
    cin>>n;
    while(n--){
        
        for(int j = 0;j < 10;j++)
            cin>>ball[i];
        ans= 0;
        dfs(0,0,0);
        if(ans)
            cout>>"YES">>endl;
        else
            cout>>"NO">>endl;
        
    }
}

C++: #include <iostream>
#include <queue>
using namespace std;
int ball[10];
int dfs(int k,int B,int C)
{
    if(k == 10)
        return 1;
    if(ball[k] > B)
        return dfs(k + 1,ball[k],C);
    if(ball[k] > C)
        return dfs(k + 1,B,ball[k]);
    return 0;
}
int main(void)
{
    int n;
    cin>>n;
    while(n--){
        int i;
        queue<int> left,right;
        for(i = 0;i < 10;i++)
            cin>>ball[i];
        if(dfs(0,0,0))
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

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

int BALLNUM = 10;

	static int data[10];
class balldata
{
private:
	//static std::vector <int> data;
	//int ballnum;
public:
	balldata(int datanum);
	static void enter();
	static void answer();
	static bool check();
	static bool check(int num,int right,int left);
};




int main()
{
	balldata ball(BALLNUM);

int N;
	std::cin >> N;
	for (int i = 0; i < N; i++)
	{
		ball.enter();
		ball.answer();
	}
}


balldata::balldata(int datanum)
{
	//ballnum = datanum;
	//data.resize(datanum);
}



void balldata::enter()
{
	for (int i = 0; i < 10; i++)
	{
		std::cin >> data[i];
	}
	return;
}

bool balldata::check(int num,int right,int left)
{
	//if (num == data.size())return true;
	if (num == 10)return true;
	if (balldata::check(num + 1, right, data[num])&&left<data[num]){ return true; }
	if (balldata::check(num + 1, data[num], left)&&right<data[num]){ return true; }

	return false;
}
bool check()
{
	return balldata::check(0, 0, 0);
}

void balldata::answer()
{ 
	if (balldata::check(0, 0, 0))
	{
		std::cout << "YES" << std::endl;
	}
	else
	{
		std::cout << "NO" << std::endl;
	}
}