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 <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
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 ball[10];
bool can = false;

void search(int r,int l,int n){
  //  cout << n << endl;
  if(n>=10) {
	can = true;
	return;
  }
  if(r<ball[n]) search(ball[n],l,n+1);
  if(l<ball[n]) search(r,ball[n],n+1);

}
 
int main(){
  int n;
  cin >> n;
  REP(i,n){
	REP(i,10) cin >> ball[i];
	int right=0;
	int left=0;
	can = false;
	search(right,left,0);
	if(can) cout << "Yes" << endl;
	else cout << "No" << endl;
  }

}

C++: #include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>

using namespace std;

vector<int> ball(10);

int dfs(int cnt, int l, int r){ 
    ++cnt;
    if(cnt == 10) return 1;
    if(ball[cnt] > r){ 
        if(dfs(cnt,l,ball[cnt])) return 1;
    }   
    else if(ball[cnt] > l){ 
        if(dfs(cnt,ball[cnt],r)) return 1;
    }   
    return 0;
}
int main(int argc, void *argv[]){
    int n;
    int tmp;
    
    scanf("%d", &n);
    while(n--){
        for(int i=0;i<10;i++){
            scanf("%d",&tmp);
            ball[i] = tmp;
        }   
        if(dfs(-1,0,0)) printf("YES\n"); else printf("NO\n");
    }   
}

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

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

bool dfs(const std::vector<int> &balls, std::vector<int> l, std::vector<int> r, int i){
	if(i == balls.size()){
		return true;
	}
	if(!l.empty() && l.back() > balls[i] && !r.empty() && r.back() > balls[i]){
		return false;
	}
	bool is_success = false;

	if(l.empty() || l.back() < balls[i]){
		l.push_back(balls[i]);
		is_success = dfs(balls, l, r, i + 1);
	}
	if(is_success){ 
		return true;
	}
	else if(r.empty() || r.back() < balls[i]){
		r.push_back(balls[i]);
		is_success = dfs(balls, l, r, i + 1);
	}
	if(is_success){ return true; }


	return false;
}

int main(int argc, char **argv){
	int n;
	std::vector<int> balls(10);

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif

	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
#if INPUT_FROM_FILE
			ifs >> balls[j];
#else
			std::cin >> balls[j];
#endif
		}

		std::vector<int> l, r;
		if(dfs(balls, l, r, 0)){
			std::cout << "YES" << std::endl;
		}
		else{
			std::cout << "NO" << std::endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

bool dfs(queue<int> a, stack<int> b, stack<int> c)
{
	if (a.empty()) return true;

	bool f1 = false, f2 = false;

	int item = a.front(); a.pop();

	if (b.top() < item) {
		b.push(item);
		f1 = dfs(a, b, c);
		b.pop();
	}

	if (c.top() < item) {
		c.push(item);
		f2 = dfs(a, b, c);
		c.pop();
	}

	return f1 || f2;
}

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

	while (n--) {
		queue<int> a;
		stack<int> b, c;

		b.push(0);
		c.push(0);

		for (int i = 0; i < 10; ++i) { int v; cin >> v; a.push(v); }

		cout << (dfs(a, b, c) ? "YES" : "NO") << endl;
	}
}

C++: #include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<algorithm>
#include<functional>
using namespace std;

int n;
int l=0;
int r=0;
int a=0;
int s=0;

int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{

	for(int j=0;j<10;j++)
	{
		cin>>a;
	if(a>l)l=a;
	else if(a>r)r=a;
	else break;
	s++;
	}

	if(s==10)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	
	}



	return 0;
}

C++: #include<iostream>
#include<cstdio>
#define Max_N 10

using namespace std;

int decide(int *a){
    int i = 1;
    int flag;
    int b[10]= {0};
    int c[10]= {0};
    b[0] = a[0];
    int i_b =1;
    int i_c =1;
    while(i < 10){
        if(b[i_b-1] > a[i] && c[i_c-1] > a[i]){
            flag = 1;
            break;
        }

        else if(b[i_b-1] > a[i] && c[i_c-1] < a[i]){
            c[i_c] = a[i];
            i_c++;
            flag = 0;
        }

        else if(b[i_b-1] < a[i] && c[i_c-1] > a[i]){
            b[i_b] = a[i];
            i_b++;
            flag = 0;
        }

        else{
            int minus_b = a[i]-b[i_b-1];
            int minus_c = a[i]-c[i_c-1];
            if(minus_b > minus_c){
                c[i_c] = a[i];
                i_c++;
            }
            else{
                b[i_b] = a[i];
                i_b++;
            }
            flag = 0;
        }
        i++;
    }
    return flag;
}

int main(){
    //input
    int a[Max_N];
    int n,m,k;
    scanf("%d", &n);
    int ans[n];
    for(m =0 ; m < n;m++){
        scanf("%d %d %d %d %d %d %d %d %d %d\n", &a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);
        ans[m] = decide(a);
    }
    for(m = 0; m < n; m++){
        if(ans[m] == 0){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
    return 0;
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		int a[9]={};
		int b[9]={};
		int dat,o=1,s=1;
		for(int j=0;j<=10;j++){
			cin>>dat;
		 	if(j==0){
				a[0]=dat;
			}
			else if(dat>a[s-1]){
				a[s]=dat;
				s++;
			}
			else if(dat>b[o-1]){
				b[o]=dat;
				o++;}
			else {
				cout<<"NO"<<endl;
			break;
			}
			if(j==10){
				cout<<"YES"<<endl;
				break;
						}

		}
	}
	return 0;
}

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

using namespace std;

struct Channel{
	int channels[2];
	Channel(){
		channels[0] = -1;
		channels[1] = -1;
	}
	bool update(int index, int number){
		if(number > channels[index]){
			channels[index] = number;
			return true;
		}
		else
			return false;
	}
};

int number[10];
int n;

bool dfs(Channel c, int depth){
	if(depth == 10)
			return true;
	Channel c_tmp = c;
	return (c.update(0, number[depth]) && dfs(c, depth+1))
			|| (c_tmp.update(1, number[depth]) && dfs(c_tmp, depth+1));

}

void solve(){
	if(dfs(Channel(), 0))
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

int main(){
	cin >> n;
	while(n--){		
		for(int i=0; i<10; ++i){
			cin >> number[i];
		}
		solve();
	}
	return 0;
}