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>
using namespace std;
int ch[12],one,two=0,g,q;

int DFS(int g){
if(g == 10)
    {
        q=0;
        return 1;
    }
else
{
    for(int i = g; i < 10; i++){
            if(q==0)return 1;
            if(ch[i] > one)
                {
                    one = ch[i];
                    DFS(i+1);
                }
            else if( ch[i] > two)
                {
                    two = ch[i];
                    DFS(i+1);
                }
            else if(ch[i] < two && ch[i] < one)
                {
                    return 0;
                }
    }
return 0;
}
}
int main()
{
    int n;
    cin >> n;
    while(n--){
     for(int i = 0; i < 10; i++)
        cin >> ch[i];
     one = ch[0];
     q=1;
     if(DFS(1)) cout << "Yes" << endl;
     else cout << "NO" << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <algorithm>
#define HEIGHT 10

using namespace std;

int a[HEIGHT];

void solve(){
	bool f=true;
	int right,left;
	right = left = 0;
	for(int i=0;i<HEIGHT;i++){
		if(right<a[i] && left<a[i]){
			if(right<left){
				left = a[i];
			} else {
				right = a[i];
			}
		} else if(right<a[i]){
			right = a[i];
		} else if(left<a[i]){
			left = a[i];
		} else {
			f = false;
			break;
		}
	}
	if(f) printf("Yes\n");
	else printf("No\n");
}
			
int main(){
	
	int lp;
	scanf("%d",&lp);
	
	for(int i=0;i<lp;i++){
		for(int j=0;j<HEIGHT;j++){
			scanf(" %d",&a[j]);
		}
		solve();	
	}
	return 0;
}

C++: #include <stdio.h>

int a[10];
int flag;

void dfs(int b_top,int c_top,int num) {

  if(num==10) {

    flag=1;
    return;

  }

  if(b_top<a[num]) dfs(a[num],c_top,num+1);

  if(c_top<a[num]) dfs(b_top,a[num],num+1);

  return;

}

int main(void) {

  int n;

  int i;


  scanf("%d",&n);

  for(i=0;i<n;i++) {

    scanf("%d %d %d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);

    flag=0;

    dfs(0,0,0);

    if(flag==1) printf("YES\n");
    else printf("NO\n");

  }

  return 0;

}

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

int main() {
	int n, x, z;
	cin >> n;

	for (int i = 0; i < n; i++) {
		vector< vector<int> > v{ {0} };
		for (int j = 0; j < 10; j++) {
			cin >> x;
			z = v.size();
			for (int k = 0; k < z; k++) {
				if (v[k].back() < x) {
					v[k].push_back(x);
					break;
				}

				if (k == z - 1) {
					v.push_back({ x });
					break;
				}
			}

			if (v.size() == 3) {
				x = -1;
				break;
			}
		}

		if (x == -1) {
			cout << "NO";
		}
		else {
			cout << "YES";
		}
		cout << endl;
	}
	return 0;
}

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

bool f(void){
	int x[10], a=0, b=0;
	for (int i=0; i<10;i++)
		cin>>x[i];
	for (int i=0; i<10; i++){
		int e=x[i];
		if (e>a) a=e;
		else if (e>b) b=e;
		else return false;
	}
	return true;
}

int main(void){

	int n;
	cin>>n;
	while (n--){
		if (f()) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include<cstdio>

#define INF 0x7fffffff
int T;
int A[12];

int main()
{
	scanf("%d",&T);
	while(T--)
	{
		for(int i=1;i<=10;i++)
			scanf("%d",&A[i]);
		int x=INF,y=INF;
		bool f=1;
		for(int i=10;i>=1;i--)
		{
			if(A[i]>x&&A[i]>y)
			{
				f=0;
				break;
			}
			if(A[i]<x)
				x=A[i];
			else
				y=A[i];
		}
		if(f) printf("YES\n");
		else printf("NO\n");
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int kuru[10];
bool solve(int l,int r,int co,int now);
int main(){
  int n;
  cin>>n;
  while(n--){
    for(int i=0;i<10;i++){
      cin>>kuru[i];
    }
    if(solve(0,0,0,0))cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}
bool solve(int l,int r,int co,int now){
  if(co==10)return true;
  if(l<kuru[now]){
    if(solve(kuru[now],r,co+1,now+1))return true;
    else return false;
  }
  if(r<kuru[now]){
    if(solve(l,kuru[now],co+1,now+1))return true;
    else return false;
  }
  else if(r>kuru[now] && l>kuru[now])return false;
}

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


bool saiki(int ball[],int ttB,int ttC,int res){
	if(res==10)return true;
	if(ball[res]>ttB){
		return saiki(ball,ball[res],ttC,res+1);
	}
	if(ball[res]>ttC){
		return saiki(ball,ttB,ball[res],res+1);
	}
	return false;
}

int main(void){
	int a,b;
	int ball[11];
	int ttB=0,ttC=0;
	int res=0;
	int n;
	scanf("%d",&n);
	for(a=0;a<n;a++){
		memset(ball,0,sizeof(ball));
		ttB=0;
		ttC=0;
		res=0;
		for(b=0;b<10;b++){
			scanf("%d",&ball[b]);
		}
		if(saiki(ball,ttB,ttC,res)==true)printf("Yes\n");else printf("No\n");
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pi acos(-1)
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define rep(i,x,n) for(int i=x;i<n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
using namespace std;
typedef pair<int,int>P;
const int MAXN=100010;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int a[12],b[12],cnt,book[12];
bool flag;
void dfs(int k)
{
	if(k == 11)
	{
		int last = 0;
		for(int i=1;i<=10;i++)
		{
			if(!book[i])
			{
				if(a[i] < last)
				return ;
				last = a[i];
			}
		}
		flag = 1;
		return ;
	}
	for(int i=k+1;i<=10;i++)
	{
		if(a[i] > b[cnt - 1])
		{
			book[i] = 1;
			dfs(i+1);
			book[i] = 0;
		}
	}
}
int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		for(int i=1;i<=10;i++)
		cin >> a[i];
		for(int i=1;i<=10;i++)
		{
			cnt = 1;
			dfs(i);
			if(flag)
			{
				cout << "YES\n";
				break;
			}
		}
		if(!flag)
		cout << "NO\n";
		flag = 0;
	}
 	return 0;
}

C++: #include <cstdio>

const int N_BALL = 10;

int balls[N_BALL];

bool solve(int l_top, int r_top, int n) {
  if (n == N_BALL) return true;

  int l_top_ = balls[n];
  if (l_top > l_top_) return false;
  if (solve(l_top_, r_top, n+1)) return true;

  int r_top_ = balls[n];
  if (r_top > r_top_) return false;
  if (solve(l_top, r_top_, n+1)) return true;

  return false;
}

int main() {
  int N;
  scanf("%d", &N);

  for (int i = 0; i < N; i++) {
    for (int bi = 0; bi < N_BALL; bi++) scanf("%d", &balls[bi]);

    if (solve(-1, -1, 0)) printf("YES\n");
    else printf("NO\n");
  }

  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
#include <functional>
const int INF =1e5;
const int MOD = 1e9 + 7;
using namespace std;
typedef pair<int,int> P;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define pb push_back
vector<int> a;
vector<int> b;
int v[10];
bool dfs(int,int,int);

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