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 <bits/stdc++.h>
using namespace std;
int a[15]{0}, b[10]{0};
int main(void) {
    int t;
    cin.sync_with_stdio(false);
    cin >> t;
    while (t--) {
        memset(a, 0, sizeof a);
        memset(b, 0, sizeof b);
        int cnt1 = 0, cnt2 = 0, x;
        bool flag = true;
        for (int i = 1; i <= 10; ++i) {
            cin >> x;
            if (x < a[cnt1] && x < b[cnt2]) {
                printf("NO\n");
                flag = false;
                break;
            } else if (x > a[cnt1] && x < b[cnt2]) {
                a[++cnt1] = x;
            } else if (x > b[cnt2] && x < a[cnt1]) {
                b[++cnt2] = x;
            } else if (x > b[cnt2] && x > a[cnt1]) {
                if(b[cnt2] > a[cnt1])
                    b[++cnt2] = x;
                else
                    a[++cnt1] = x;
                
            }
        }
        if (flag) printf("YES\n");
    }
    return 0;
}

C++: // This is free and unencumbered software released into the public domain.

// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non-commercial, and by any
// means.

// In jurisdictions that recognize copyright laws, the author or authors
// of this software dedicate any and all copyright interest in the
// software to the public domain. We make this dedication for the benefit
// of the public at large and to the detriment of our heirs and
// successors. We intend this dedication to be an overt act of
// relinquishment in perpetuity of all present and future rights to this
// software under copyright law.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

// For more information, please refer to <http://unlicense.org>

/****************/
/* template.hpp */
/****************/

#include <algorithm>
#include <cassert>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <numeric>

using std::abs;
using std::cerr;
using std::cout;
using std::endl;
using std::max;
using std::min;
using std::numeric_limits;
using std::swap;

struct BoolName : std::numpunct<char> {
  std::string t, f;
  BoolName (std::string t, std::string f) : t(t), f(f) {}
  std::string do_truename() const {return t;}
  std::string do_falsename() const {return f;}
};

void set_bool_name(std::string t, std::string f) {
  cout.imbue(std::locale(cout.getloc(), new BoolName(t, f)));
}

struct Initializer {
  Initializer() {
    cout << std::fixed << std::setprecision(15) << std::boolalpha;
    set_bool_name("Yes", "No");
  }
} initializer;

struct Input {
  bool eof;

  Input() : eof(false) {}

  operator char() {
    char v;
    this->eof = (std::scanf("%c", &v) != 1);
    return v;
  }

  operator int() {
    int v;
    this->eof = (std::scanf("%d", &v) != 1);
    return v;
  }

  operator long() {
    long v;
    this->eof = (std::scanf("%ld", &v) != 1);
    return v;
  }

  operator long long() {
    long long v;
    this->eof = (std::scanf("%lld", &v) != 1);
    return v;
  }

  operator double() {
    double v;
    this->eof = (std::scanf("%lf", &v) != 1);
    return v;
  }

  operator long double() {
    long double v;
    this->eof = (std::scanf("%Lf", &v) != 1);
    return v;
  }

  void ignore() const {
    getchar();
  }
} in;

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}

template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}

template<typename T, typename S> std::function<S(T)> cast() {
  return [](const T& t) { return static_cast<S>(t); };
}

/************/
/* main.cpp */
/************/

int main() {
  set_bool_name("YES", "NO");
  int t(in);
  for (int i = 0; i < t; ++i) {
    int a = 0, b = 0;
    bool f = true;
    for (int i = 0; i < 10; ++i) {
      int c(in);
      if (c < a) {
        f = false;
      } else if (c < b) {
        a = c;
      } else {
        b = c;
      }
    }
    cout << f << endl;
  }
}

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

///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{

	int n;
	cin >> n;
	while (n--)
	{
		int ball[10];

		for (int i = 0; i < 10; ++i)
		{
			cin >> ball[i];
		}

		bitset<10> direction;
		int all = 1024;
		while (all-- > 0)
		{
			direction = static_cast<bitset<10> >(all);
			bool perfect = true;
			int left = 0;
			int right = 0;
			for (int i = 0; i < 10; ++i)
			{
				if (direction[i])
				{
					if (ball[i] > left)
					{
						left = ball[i];
					}
					else
					{
						perfect = false;
						break;
					}
				}
				else
				{
					if (ball[i] > right)
					{
						right = ball[i];
					}
					else
					{
						perfect = false;
						break;
					}
				}
			}
			if (perfect)
			{
				break;
			}
		}

		if (all >= 0)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}

	return 0;
}

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

bool flag;

int main()
{
	int n;
	cin>>n;
	int a[15];
	while(n--)
	{
		for(int i=0;i<10;i++)
			cin>>a[i];
		flag=0;
		int l=-1,r=-1;
		for(int i=0;i<10;i++)
		{
			if(a[i]>l) l=a[i];
			else if(a[i]>r) r=a[i];
			else flag=1;
		 } 
		 
		if(!flag)
		 	cout<<"YES"<<endl;
		else
		 	cout<<"NO"<<endl;
	}
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll; 
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;


ll n, a, C = 0, B = 0;

int main(){
	cin >> n;
	REP(i, n){
		C = 0, B = 0;
		REP(j, 10){
			cin >> a;
			if (a > B){
				B = a;
			}
			else if (a > C){
				C = a;
			}
			else{
				cout << "NO\n";
				break;
			}
			if (j == 9){
				cout << "YES\n";
			}
		}
	}
}

C++: #include <cstdio>
#include <stack>
#define NUM 10
using namespace std;

int N;
stack<int> B,C;

int main()
{
	//freopen("in","r",stdin);
	scanf("%d",&N);
	while(N--){
		int tmp;
		bool sol=true;
		for(int i=0;i<NUM;i++){
			scanf("%d",&tmp);
			if(B.empty())
				B.push(tmp);
			else if(tmp>B.top())
				B.push(tmp);
			else if(C.empty())
				C.push(tmp);
			else if(tmp>C.top())
				C.push(tmp);
			else
				sol = false;
		}
		if(sol)
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}