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 <stack>
#include <tuple>
using namespace std;

int main() {
	int n, balls[10]; cin >> n;
    while(n--){
        for(int i = 0; i < 10; i++){
            cin >> balls[i];
        }
        
        bool sortable = false;
        stack<tuple<int, int, int> > states;
        
        states.push(make_tuple(0,0,0));
        while(!states.empty()){
        	tuple<int, int, int> now = states.top();
        	closed.insert(now);
        	states.pop();
        	
        	int idx = get<0>(now);
        	if(idx < 9){
        		if(get<1>(now) < balls[idx]){
        			if(idx + 1 == 9){
        				sortable = true; break;
        			}
        			states.push(make_tuple(idx+1,balls[idx],get<2>(now)));
        		}
        		if(get<2>(now) < balls[idx]){
        			if(idx + 1 == 9){
        				sortable = true; break;
        			}
        			states.push(make_tuple(idx+1,get<1>(now),balls[idx]));
        		}
        	}        	
        }
         
        if(sortable) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

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

#include <cstdio>
#include <stack>

using namespace std;

const int MAX_W = 103, MAX_H = 103;

int num[10];
bool res = false;
stack<int> left, right;

void dfs(int i){
    if(i == 10){
        res = true;

        return;
    }

    if(num[i] > left.top()) {
        left.push(num[i]);
        dfs(i+1);
        left.pop();
    }

    if(num[i] > right.top()){
        right.push(num[i]);
        dfs(i+1);
        right.pop();
    }
}

void solve(){

    left.push(0);
    right.push(0);
    dfs(0);
    if(res) printf("YES\n");
    else printf("NO\n");
}

int main(){
    int T;
    scanf("%d", &T);
    while(T--){

        for(int i = 0;i < 10;i++){
            scanf("%d", &num[i]);
        }
        res = false;
        solve();
    }
    return 0;
}

/*
2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
 */

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

int main(){
    int n,tmp,a = 0,b = 0;
    bool judge;
    cin >> n;
    while(n--){
        judge = true;
        a = 0;
        b = 0;
        for(int i=0;i<10;i++){
            cin >> tmp;
            if(tmp > a) a = tmp;
            else if(tmp > b) b = tmp;
            else judge = false;
        }
        if(judge) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

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

stack<int> B, C;
int A[10];

bool dfs(int index)
{
  bool ret = false;
  char s[11];

  if (index >= 10) {
    return true;
  }

  for (int i = 0; i < 11; i++) {
    if (i < index) s[i] = '>';
    else s[i] = 0;
  }

  if (B.empty() || B.top() < A[index]) {
    B.push(A[index]);
    // printf("%spush %d into B\n", s, A[index]);
    ret = dfs(index + 1);
    // printf("%s%s. pop %d from B\n", s, ret ? "succeeded" : "failed", A[index]);
    B.pop();
  }
  if (!ret && (C.empty() || C.top() < A[index])) {
    C.push(A[index]);
    // printf("%spush %d into C\n", s, A[index]);
    ret = dfs(index + 1);
    // printf("%s%s. pop %d from C\n", s, ret ? "succeeded" : "failed", A[index]);
    C.pop();
  }

  return ret;
}

bool solve()
{
  while (!B.empty()) B.pop();
  while (!C.empty()) C.pop();

  B.push(A[0]);
  bool ret = dfs(1);
  B.pop();

  return ret;
}

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

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      scanf("%d", A + j);
    }

    if (solve()) {
      printf("Yes\n");
    }
    else {
      printf("No\n");
    }
  }

  return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
	int n,a[10],f,s;
	bool flg=true;
	
	cin>>n;
	
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			cin>>a[j];
		}
		f=0;s=0;flg=true;
		for(int j=0;j<10;j++){
			if(a[j]<f){
				if(a[j]<s)flg=false;
				else s=a[j];
			}else f=a[j];
		}
		if(flg)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}

}

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;
			}
			if (s1.top() < a){
				s1.push(a);
				continue;
			}
			yes=false;
		}
		if (yes)
			cout << "YES"<<endl;
			else
				cout << "NO" << endl;
	}
	return 0;
}

C++:  
 #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
  
 int main()
 {
   int N;
   cin>>N
   while(N--)
   {
     int arr[10];
     bool flag=true;
     for(int i=0;i<10;i++) cin>>arr[i];
     for(int i=0;i<8;i++)
     {
       if(arr[i]>arr[i+1]&&arr[i+1]>arr[i+2])
       {
         flag=false;
         break;                                      
       }        
     }     
     if(flag) cout<<"YES"<<endl;
     else cout<<"NO"<<endl;
   }
   //while(1);     
   return 0;  
 }

C++: #include<cstdio>
#include<algorithm>
#define null -1
using namespace std;
int a[15], b[15], c[15];

bool dfs(int amax, int bmax, int index)
{
    bool flag1 = false, flag2 = false;
    if(index >= 10) return true;
    if(a[index] > amax) {
        flag1 = dfs(a[index], bmax, index+1);
    }
    if(!flag1 && a[index] > bmax) {
        flag2 = dfs(amax, a[index], index+1);
    }
    if(flag1 || flag2) {
        return true;
    } else {
        return false;
    }
}

void solve()
{
    bool ok = dfs(-1, -1, 0);
    if(ok) printf("YES\n");
    else printf("NO\n");
}

int main()
{
    int n;
    scanf("%d", &n);
    while(n--) {
        fill(a, a+15, -1);
        for(int i = 0; i < 10; i++) {
            scanf("%d", &a[i]);
        }
        solve();
    }

    return 0;
}