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<stdio.h>
#include<vector>
#include<utility>
#include<queue>
#include<math.h>
#include<string>
#include<stack>
#include<typeinfo>
using namespace std;
typedef pair<int, int> P;
int main() {
	int n,ball[10],under;
	cin >> n;
	for (int data = 0; data < n; ++data) {
		for (int i = 0; i < 10; ++i) cin >> ball[i];
		under = ball[0];
		ball[0] = 0;
		for (int i = 1; i < 10; ++i) {
			if (under < ball[i]) {
				under = ball[i];
				ball[i] = 0;
			}
		}
		int k;
		for (k = 1; k < 10; ++k) {
			if (ball[k] == 0)continue;
			else {
				under = ball[k];
				ball[k] = 0;
				break;
			}
		}
		char bo = true;
		for (int i = k + 1; i < 10; ++i) {
			if (ball[i] == 0)continue;
			else if (under < ball[i]) {
				under = ball[i];
				ball[i] = 0;
			}
			else {
				bo = false;
				break;
			}
		}
		if (bo)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#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 ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

int main() {
	int n;
	cin>>n;
	while (n--){
	bool yes=true;
		stack<int> s1;
		stack<int> s2;
		s1.push(0);
		s2.push(0);
		REP(i, 10){
			int a;
			cin >> a;
			if (s1.top() <= s2.top()){
				if (s1.top() < a)
					s1.push(a);
					continue;
			}
			if (s2.top() < a){
					s2.push(a);
					continue;
			}
			yes=false;

		}
		if (yes)
			cout << "YES"<<endl;
			else
				cout << "NO" << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <queue>
using namespace std;
int ball[10];
int dfs(int k,int B,int C)
{
    if(k == 9)
        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 <algorithm>
#include <string>
#include <cmath>
#include <stack>
using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int ball[10];
		for(int i = 0; i < 10; i++)cin >> ball[i];
		int b = 0,c = 0;
		for(int i = 0; i < 10; i++){
			if(b > ball[i] && c > ball[i]){
				cout << "NO" << endl;
				goto no;
			}else if(b < ball[i] && c > ball[i])b = ball[i];
			else if(b > ball[i] && c < ball[i])c = ball[i];
			else if(b > c)b = ball[i];
			else c = ball[i];
		}
		cout << "YES" << endl;
		no:;
	}
}

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

int a[10],b[10],c[10];

void initial()
{
	for(int i=0;i<10;i++)
	{
		b[i]=-1;
        c[i]=-1;
	}
}
bool judge()
{
  int p=0,q=0,i;
  initial();
  b[0]=a[0];
  for(i=1;i<10;i++)
  {
	  if(a[i]>b[p])b[++p]=a[i];
	  else if(q==0)c[q++]=a[i];
	  else if(a[i]>c[q-1])c[q++]=a[i];
	  else 
	  {
		  return false;
		  break;
	  }
  }
  if(i==10)
	  return true;
}

int main()
{
	int num;
	cin>>num;
	while(num--)
	{
		for(int i=0;i<10;i++)
			cin>>a[i];
		puts(judge()?"YES":"NO");
	}
return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

using vi = vector<int>;
using vs = vector<string>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repback(i,n) for(int i=(int)n-1;i>=0;i--)
#define repa(i,a,n) for(int i=a;i<(int)(n);i++)
typedef pair<int, int> P;
typedef queue<int> qi;
typedef long long ll;
const ll INF = 1e7, MAX_N = 99, MAX_M = 1000, MAX_W = 100, MAX_H = 100;

int asc(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}
void clear(std::queue<int>& q)
{
    std::queue<int> empty;
    std::swap(q, empty);
}

int N;
int balls[10];
qi qa, qb;
bool possible = false;

void bfs(int i) {
    //完遂可能
    if (i == 10) {
        possible = true;
        return;
    }
    //Aに球をのせられる場合
    if (qa.empty() || qa.back() < balls[i]) {
        qa.push(balls[i]);
        bfs(i + 1);
    }
    //Bに球をのせられる場合
    if (qb.empty() || qb.back() < balls[i]) {
        qb.push(balls[i]);
        bfs(i + 1);
    }
    //完遂不可能
    else return;
}
int main() {
    //入力
    cin >> N;
    rep(p, N) {
        rep(k, 10) cin >> balls[k];
        possible = false;
        clear(qa); clear(qb);
        bfs(0);
        if (possible) cout << "YES" << endl;
        if (!possible) cout << "NO" << endl;
    }
    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++){
			if(j==10){
				cout<<"YES"<<endl;
				break;
						}
			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 if(dat<a[s-1] && dat<b[o-1]){
				cout<<"NO"<<endl;
			break;
			}
					}
	}
	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=1,cell_2=1,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]=ball[0];
		cell[1][0]=ball[1];

		for(i=2;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;
		}	
	}
	for(i=0;i<n;i++){	
		if(flag[i]==0)printf("YES\n");
		else printf("NO\n");
	}
	
	return 0;
}

C++: #include <iostream>

const size = 10;

int num[size];

bool dfs(int beforeB, int beforeC, int depth) {
	if(depth == 10)
		return true;
	
	if(num[depth] > beforeB)
		return dfs(num[depth], beforeC, depth + 1);
	else if(num[depth] > beforeC)
		return dfs(beforeB, num[depth], depth + 1);
	else
		return false;
}

int main() {
	int n = 0;
	std::cin >> n;
	
	for(int i = 0; i < n; ++i) {
		for(auto&& x : num)
			std::cin >> x;
		
		std::cout << dfs(0, 0, 0) ? "YES" : "NO" << std::endl;
	}
}