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<queue>
#include<vector>
using namespace std;

int main(){
	int num;
	cin>>num;
	int error=0;
	for(int x=0;x<num;x++){
		error=0;
		queue<int> A;
		vector<int> B;
		vector<int> C;
		for(int i=0;i<10;i++){
			int nn;
			cin>>nn;
			A.push(nn);
		}
		C.push_back(0);
		for(int i=0;i<A.size();i++){
			if(i==0){
				B.push_back(A.front());
				A.pop();
				continue;
			}
			if(A.front()>B.back()){
				B.push_back(A.front());
				A.pop();
			}else if(A.front()>C.back()){
				C.push_back(A.front());
				A.pop();
			}else{
				error=1;
				break;
			}
		}
		if(error==0)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

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

bool solver(queue<int> q, int a, int b){
    bool result = false;
    if(q.empty()) {
        return true;
    }
    int tmp = q.front();
    if(tmp > a){
        q.pop();
        result = solver(q, tmp, b);
        q.push(tmp);
    }
    if(result) return true;
    tmp = q.front();
    if(tmp > b){
        q.pop();
        result = solver(q, a, tmp);
        q.push(tmp);
    }
    if(result) return true;
    return false;
}

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

    for(int i=0; i<n; i++){
        queue<int> q;
        for(int j=0; j<10; j++){
            int tmp;
            cin >> tmp;
            q.push(tmp);
        }
        cout << (solver(q,0,0)?"YES":"NO") << endl;
    }
    return 0;
}

C++: /*
テヲテδ欲ツ法ツづ可づヲツづィツ嘉ーツつッツづ慊つキ(ツつ?づィツ本ツ妥ヲ2ツ氾?づ?P.24ツつセツづヲツ！)
- ツ債カツづ個暗ェツ氾板湘」ツづ個仰?づ個値ツづ? ツ右ツづ個暗ェツ氾板湘」ツづ個仰?づ個値ツづーツ個ゥツ氾、ツづ猟づ?
  ツ妥・ツつォツつ「ツ値ツづ個個環づ個陛サツづ? ツ仰?づーツ禿シツづェツづァツづェツづゥツづ按づァツ禿シツづェツつスツ陛サツつェツつ「ツつ「.
- ツつアツづェツづ? ツ渉ャツつウツつ「ツ値ツづ個個環づーツ残ツつオツつスツ陛サツつェ, ツ古」ツ々ツつィツ督セツづ可づ按づゥツつゥツづァツづ?つキ.
- ツ「ツ妥・ツつォツつ「ツ陛サツづ可禿シツづェツづァツづェツづゥツづ按づァツ禿シツづェツづゥツ」ツ?ィツ「ツつサツづェツづ?つセツづ淞づ按づァツ渉ャツつウツつ「ツ陛サツづ可禿シツづェツづゥツ」ツ?ィツ「ツつサツづェツづ?づ?ダツδ?づ按づァNOツ」ツづーツδ仰ーツプツづ?繰ツづィツ陛板つオツづ慊つオツづ・ツつ、.
 */
#include <iostream>
using namespace std;

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

  while(T--){
    int b = 0; //ツ?ゥツづ個つ?づ?
    int c = 0; //ツ?ィツづ個つ?づ?
    bool ans = true; //ans == trueツづ按づァYES, ans == falseツづ按づァNO

    for(int i = 0; i < 10; i++){
      int a;
      cin >> a;

      //ツつキツづ?づ丑Oツづ?づュツつゥツづ?づ?つ「ツづゥツづ按づァ, ツ渉按猟敖づーツつケツつクcontinue
      if(!ans) continue;

      //ツ?ゥツづ個個環づ個暗ェツ氾板湘」ツづ個値ツづヲツづィ, ツ?ィツづ個個環づ個暗ェツ氾板湘」ツづ個値ツづ個陛サツつェツ妥・ツつォツつ「
      if(b < c){
        if(c < a)      c = a;       //ツ妥・ツつォツつ「ツ陛サ(ツ?ィ)ツづ可湘ヲツつケツづァツづェツづゥツづ按づァツ湘ヲツつケツづゥ(ツつサツづ個陛サツつェツ古」ツ々ツ督セツつセツつゥツづァ)
        else if(b < a) b = a;
        else           ans = false; //ツ渉ャツつウツつ「ツ陛サ(ツ?ゥ)ツづ可づ?湘ヲツつケツづァツづェツづ按つゥツづ?つスツづァ, NOツづ?づ按づゥ
      }
      //ツ?ゥツづ個個環づ個暗ェツ氾板湘」ツづ個値ツづヲツづィ, ツ?ィツづ個個環づ個暗ェツ氾板湘」ツづ個値ツづ個陛サツつェツ渉ャツつウツつ「
      else{
        if(b < a)      b = a;       //ツ妥・ツつォツつ「ツ陛サ(ツ?ゥ)ツづ可湘ヲツつケツづァツづェツづゥツづ按づァツ湘ヲツつケツづゥ(ツつサツづ個陛サツつェツ古」ツ々ツ督セツつセツつゥツづァ)
        else if(c < a) c = a;
        else           ans = false; //ツ渉ャツつウツつ「ツ陛サ(ツ?ィ)ツづ可づ?湘ヲツつケツづァツづェツづ按つゥツづ?つスツづァ, NOツづ?づ按づゥ
      }
    }

    if(ans) cout << "YES\n";
    else    cout << "NO\n";
  }
}

C++: #include <iostream>

using namespace std;

int a[10];
bool flag;

void dfs(int n, int l, int r) 
{
    if (n == 10) {
        flag = true;
        return ;
    }

    if (a[n] > l)
        dfs(n + 1, a[n], r);
    if (a[n] > r)
        dfs(n + 1, l, a[n]);

    return ;
}

int main()
{
    int n;

    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++)
            cin >> a[j];

        flag = false;
        dfs(0, 0, 0);
        if (flag)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}

C++: #include<stdio.h>
#include<string.h>
int a[13],vis[13],flag;
void dfs(int x,int l,int r)
{
    int i;
    if(x==11)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()
{
int T,i,j,k;
scanf("%d",&T);
while(T--)
{
flag=0;
for(i=1;i<=10;i++)
scanf("%d",&a[i]);
memset(vis,0,sizeof(vis));
dfs(1,0,0);
if(flag)printf("NO\n");
else printf("YES\n");
}
return 0;
}

C++: #include<iostream>

int ball[10];
bool res;

void dfs(int i, int ls, int rs){
	if (i == 10){
		res = true;
		return;
	}

	if (ball[i] > ls)dfs(i + 1, ball[i], rs);
	if (ball[i] > rs)dfs(i + 1, ls, ball[i]);
}

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

	for (int i = 0; i < n; i++){
		for (auto &i : ball)std::cin >> i;
		res = false;
		dfs(0, 0, 0);
		std::cout << (res ? "YES" : "NO") << std::endl;
	}
	return 0;
}

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

int a[10];
bool flag;

void dfs(int x, int l, int r){
	if(x == 10){
		flag = true;
		return;
	}
	if(a[x] > l)
		dfs(x+1, a[x], r);
	else if(a[x] > r)
		dfs(x+1, l, a[x]);
	else flag = false;
}
int main(){
	int N;
	scanf("%d", &N);
	while(N--){
		memset(a, 0, sizeof(a));
		for(int i = 0; i < 10; i++) scanf("%d", &a[i]);
		flag = false;
		dfs(0, 0, 0);
		if(flag) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++: //
//  AOJ 0033 Ball
//
//  Created by TaoSama on 2015-02-19
//  Copyright (c) 2014 TaoSama. All rights reserved.
//
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
#define CLR(x,y) memset(x, y, sizeof(x))

using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;

int a[15];
bool dfs(int k, int b, int c) {
	if(k == 11) return true;
	if(a[k] > b) if(dfs(k + 1, a[k], c)) return true;
	if(a[k] > c) if(dfs(k + 1, b, a[k])) return true;
	return false;
}

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
//	freopen("out.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(0);

	int t; cin >> t;
	while(t--) {
		for(int i = 1; i <= 10; ++i) cin >> a[i];
		if(dfs(1, 0, 0))	cout << "YES" << endl;
		else	cout << "NO" << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cstdio>

using namespace std;



int main(){
	int n;

	cin >> n;
	while(n--){
		int a;
		bool f = true;
		vector<int> b, c; 
		for(int i = 0; i < 10; i++){
			cin >> a;
			if(f || b[b.size()-1] < a){
				b.push_back(a);
				f = false;
			}else{
				c.push_back(a);
			}
		}
		bool check = true;
		for(int i = 1; i < b.size() && check; i++){
			if(b[i] < b[i-1]){
				check = false;
			}
		}
		for(int i = 1; i < c.size() && check; i++){
			if(c[i] < c[i-1]){
				check = false;
			}
		}
		
		if(check){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}