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

int N;
int balls[15];

int solve() {
    vector<int> A, B;
    for(int i = 0; i < 10; i++) {
        if(i == 0) {
            A.push_back(balls[i]);
        } else {
            if(B.size() == 0) {
                if(A[A.size()-1] > balls[i]) {
                    B.push_back(balls[i]);
                } else {
                    A.push_back(balls[i]);
                }
            } else {
                if(A[A.size()-1] < balls[i] && B[B.size()-1] < balls[i]) {
                    if(A[A.size()-1] > B[B.size()-1]) {
                        A.push_back(balls[i]);
                    } else {
                        B.push_back(balls[i]);
                    }
                } else if(A[A.size()-1] < balls[i] && B[B.size()-1] > balls[i]) {
                    A.push_back(balls[i]);
                } else if(A[A.size()-1] > balls[i] && B[B.size()-1] < balls[i]) {
                    B.push_back(balls[i]);
                } else {
                    cout << "NO" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "YES" << endl;
    return 0;
}


int main() {
    cin >> N;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < 10; j++) {
            cin >> balls[j];
        }
        solve();
    }

    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int num[2] = {0};
		int flag = 1;
		for (int j = 0; j < 10; j++) {
			int k;
			cin >> k;
			if (num[0] < k && num[1] < k) {
				num[num[0] < num[1]] = k;
			}
			else if (num[0] < k && num[1] >= k) {
				num[0] = k;
			}
			else if (num[0] >= k && num[1] < k) {
				num[1] = k;
			}
			else {
				flag = 0;
				break;
			}
		}
		if (flag) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

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

int main()
{
	int n,A,B,f,ball;
	cin >> n;
	
	for(int i=0;i<n;i++){
		A=0;
		B=0;
		f=0;
		for(int j=0;j<10;j++){
			cin >> ball;
			if(ball<A && ball<B) f=1;
			else if(A<ball && ball<B) A=ball;
			else if(ball<A && B<ball) B=ball;
			else if(A<B) B=ball;
			else A=ball;
		}
		
		if(f==0) cout << "YES" << endl;
		else cout << "NO" << endl;
		
	}
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int n;
int a[11];

void rec(int idx, int old) {
   if (idx == 10) return;
   if (a[idx] > old) {
      rec(idx + 1, a[idx]);
   } else {

   }
}

int main() {
   cin >> n;
   rep (k, n) {
      rep (i, 10) {
         cin >> a[i];
      }
      // rec(0, -1);
      bool printed = false;
      rep (mask, (1<<10)) {
         bool ok = true;
         int oldA = -1, oldB = -1;
         rep (j, 10) {
            if ((mask>>j)&1) {
               if (a[j] > oldA) {
                  oldA = a[j];
               } else {
                  ok = false;
               }
            } else {
               if (a[j] > oldB) {
                  oldB = a[j];
               } else {
                  ok = false;
               }
            }
         }
         if (ok) {
            puts("YES");
            printed = true;
            break;
         }
      }
      if (!printed) puts("NO");
   }

   return 0;
}

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

int main(){
    stack<int> b, c;
    int a[10];
    bool which[11];
    int data[11];
    int index;
    int n, m, A;
    int i, j;
    cin >> n;
    for(i=0;i<n;i++){
        index = 0;
        for(j=0;j<10;j++){
            cin >> m;
            a[j] = m;
            data[j+1] = 0;
        }
        b.push(0);
        c.push(0);
        while(index>=0){
            A = a[index];
            if(b.top() < A && (data[A] != 1 && data[A] != 3)){
                b.push(A);
                data[A] += 1;
                which[A] = true;
            }else if(c.top() < A && (data[A] != 2 && data[A] != 3)){
                c.push(A);
                data[A] += 2;
                which[A] = false;
            }else{
                index--;
                if(index < 0){
                    break;
                }else if(which[a[index]]){
                    b.pop();
                }else{
                    c.pop();
                }
                continue;
            }
            index++;
            if(index > 9){
                cout << "YES" << endl;
                break;
            }
        }
        if(index < 0){
            cout << "NO" << endl;
        }
    }
}

C++: #include<cstdio>
#include<algorithm>

using namespace std;

int N;
int l[15];
int b,c;


void solve(){
  for(int i=0;i<10;i++){
    if(b<l[i] && c<l[i]){
      if(l[i]-b < l[i]-c) b=l[i];
      else c=l[i];
    }
    else if(b<l[i] && c>l[i]) b=l[i];
    else if(b>l[i] && c<l[i]) c=l[i];
    else{
      printf("NO\n");
      return;
    }
  }
  printf("YES\n");
  return;
}


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

  for(int i=0;i<N;i++){
    b,c=0;
    scanf("%d%d%d%d%d%d%d%d%d%d",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9]);
    solve();
  }

  return 0;
}