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 <bits/stdc++.h>
using namespace std;
int A[15];
bool dfs(int n, int a, int b)
{
    bool ret = false;
    if(n == 10) return (true);
    if(A[n] > a) ret |= dfs(n + 1, A[n], b);
    if(A[n] > b) ret |= dfs(n + 1, a, A[n]);
    return (ret);
}
int main()
{
    int N;
    cin >> N;
    while(N--) {
        for(int i = 0; i < 10; i++) cin >> A[i];
        if(dfs(0, 0, 0)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return (0);
}

C++: #include<cstdio>

int main(void){
	int n,i,j;
	int a[1024][10];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<10;j++){
			scanf("%d",&a[i][j]);
		}
	}
	
	for(i=0;i<n;i++){
		int b[10],c[10];
		b[0]=a[i][0];
		bool x=true;
		int k=0,l=0;
		for(j=1;j<10;j++){
			if(a[i][j]>b[k]){
				k++;
				b[k]=a[i][j];
			}else {
				c[l]=a[i][j];
				l++;
			}
		}

		for(j=0;j<l-2;j++){
			if (c[j]>c[j+1]){
				x=false;
			}
		}
		if(x==true){
			printf("YES\n");
		} else{
			printf("NO\n");
		}	
	}
	return 0;
}

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

int main() {
	int n;
	deque<int> b,c;
	cin >> n;
	for ( int i = 0; i < n; i++ ){
		int dummy;
		cin >> dummy;
		b.push_back( dummy );
		cin >> dummy;
		c.push_back( dummy );
		for ( int j = 0; j < 8; j++ ){
			cin >> dummy;
			if ( dummy > b[b.size()-1] )	b.push_back( dummy );
			else if ( dummy > c[c.size()-1] )	c.push_back( dummy );
			else {
				cout << "NO" << endl;
				goto END;
			}
		}
		cout << "YES" << endl;
END:;
	}
	
	return 0;
}

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

using namespace std;

int caseCnt, numbers[10], curNum;
stack<int> Left, Right;

bool used[10], result;

void clear_stack(){
    while( !Left.empty())  Left.pop();
    while(!Right.empty()) Right.pop();
}

bool dfs(int index, int left_or_right){
    if(!left_or_right){
        if(Left.empty() || numbers[index] > Left.top()){
            Left.push(numbers[index]);
        }else{
            //cout << "false\n";
            return false;
        }
    }else{
        if(Right.empty() || numbers[index] > Right.top()){
            Right.push(numbers[index]);
        }else{
            //cout << "false\n";
            return false;
        }
    }
    if(index == 9){
        //cout << "true\n";
        return true;
    }else if(dfs(index+1, 0)){
        //cout << "true\n";
        return true;
    }else if (dfs(index+1, 1)){
        //cout << "true\n";
        return true;
    }else{
        //cout << "false\n";
        return false;
    }
}

int main(){
    cin >> caseCnt;

    while(caseCnt--){
        result = false;
        clear_stack();

        for(int i=0; i<10; ++i) cin >> numbers[i];

        result = dfs(0, 0);
        if(result){
            cout << "YES\n";
            continue;
        }

        result = dfs(0, 1);
        if(result) cout << "YES\n";
        else       cout << "NO\n";
    }
    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

int main(){
    int n,b,B=0,C=0;
    
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        B=0;C=0;
        for(int j=0;j<10;j++){
            scanf("%d",&b);
            if(min(B,C)<b){
                if(B>C && B<b)B=b;
                else C=b;
            }else{
                B=11;C=11;
            }
        }
        if(B==10 || C==10)
            puts("YES");
        else
            puts("NO");
    }
    return 0;
}

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

using namespace std;

int N;
int balls[10];
bool dfs(int n, int a, int b){
if(n==10)return true;
if(balls[n]>a) return dfs(n+1,balls[n],b);
if(balls[n]>b) return dfs(n+1,a,balls[n]);
return false;
}
int main(){
cin>>N;
for(int i=0;i<N;i++){
for(int j=0;j<10;j++){
cin>>balls[j];
}
if(dfs(0,0,balls[0]))cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}

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

using namespace std;

int main() {
    int N;
    cin >> N;
    while(N--) {
        vector<int> v(10);
        for(int i = 0; i < 10; ++i) cin >> v[i];
        bool ok = false;
        for(int pat = 0; pat < (1<<10); ++pat) {
            bool sorted = true;
            int prev = -1;
            for(int i = 0; i < 10; ++i) {
                if(pat & (1<<i)) {
                    if(v[i] < prev) {
                        sorted = false;
                        break;
                    }
                    prev = v[i];
                }
            }
            prev = -1;
            for(int i = 0; i < 10; ++i) {
                if(~pat & (1<<i)) {
                    if(v[i] < prev) {
                        sorted = false;
                        break;
                    }
                    prev = v[i];
                }
            }
            if(sorted) {
                ok = true;
                break;
            }
        }

        cout << (ok?"YES":"NO") << endl;
    }
    return 0;
}

C++: #include<stdio.h>

int arr[10];
int b[10],c[10];
int visited[10]; 
int dfs(int n,int nb,int nc)
{
	int sign=0,sign1=0;
	if(n==10)
		return 1;	
	else
	{
		if(nb==0)
		{
			b[nb]=arr[n];
			sign=dfs(n+1,nb+1,nc);
			
		}
		else 
		{	
			if(arr[n]>b[nb-1])
			{
				b[nb]=arr[n];
				sign=dfs(n+1,nb+1,nc);
				
			}
		}
		if(nc==0)
		{
			c[nc]=arr[n];
			sign1=dfs(n+1,nb,nc+1);
			
		}
		else
		{
			if(arr[n]>c[nc-1])
			{
				c[nc]=arr[n];
				sign1=dfs(n+1,nb,nc+1);
			
			}
		}
	}
	return sign||sign1;
}
int main()
{
	int N;
	scanf("%d",&N);
	while(N--)
	{
		int i,sign=0;
		for(i=0;i<10;i++)
			scanf("%d",&arr[i]);
		sign=dfs(0,0,0);
		if(sign)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n; cin >> n ;
	for(int i=0;i<n;i++){
		int a[10] ;
		for(int j=0;j<10;j++) cin >> a[j] ;
		int stackA[10]={a[0],0}; int stackB[10]={0};
		int na=0;int nb=0;int flag=0;
		for(int j=1;j<10;j++){
			if(flag==1) break;
			if(a[j]>stackA[na-1]) stackA[na++]=a[j];
			else if(nb==0) stackB[nb++]=a[j];
			else if(a[j]>stackB[nb-1]) stackB[nb++]=a[j];
			else flag=1;
		};
		if(flag==1) cout << "NO\n" ;
		else cout << "YES\n" ;
	};
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#define INF 1000000000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define all(x) (x).begin(),x.end()
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

int main(){
  int n,x;
  cin>>n;
  rep(i,n){
    bool ok=true;
    int right,left=-INF;
    cin>>right;
    REP(i,1,10){
      //cout<<right<<" "<<left<<endl;
      cin>>x;
      if(right>x){
	if(left<x){
	  left=x;
	}else{
	  //cout<<x<<endl;
	  ok=false;
	  break;
	}
      }else{
	right=x;
      }
      
    }
    if(ok)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}