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,g,q;

int DFS(int g){
if(g == 10)
    {
        q=0;
        return 1;
    }
else
{
    for(int i = g; i < 10; i++){
        for(int k = 1; k >= 0; k--)
        {
            if(q == 0) return 1;
            if(k && ch[i] > one)
                {
                    one = ch[i];
                    DFS(i+1);
                }
            else if(!k && 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];
     two = 0;
     q=1;
     if(DFS(1)) cout << "YES" << endl;
     else cout << "NO" << endl;
    }
    return 0;
}

C++: #include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>
#include <cstring>
#include <cstdlib>

typedef long long ll;

using namespace std;

struct ToLower {    char operator()(char c) { return tolower(c); }};

int main(void){
	int N;
	cin >> N;

	int ball[10];
	int a=0, b=0;
	int check = 0;

	for(int i=0; i<N; ++i){

		for(int j=0; j<10; j++){
			cin >> ball[j];
		}
		for(int j=0; j<10; ++j){
			if(ball[j] > a && ball[j] > b){
				(a > b ? a : b) = ball[j];
				continue;
			} else if(ball[j] < a && ball[j] < b){
				cout << "NO" << endl;
				check = 1;
				break;
			} else {	
				(a < b ? a : b) = ball[j];
			}
		}
		if(check == 0) cout << "YES" << endl;



	}
	return 0;
}

C++: #include <bits/stdc++.h>
/* Karen {{{
  ___  ____
 |_  ||_  _|
   | |_/ /    ,--.   _ .--.  .---.  _ .--.
   |  __'.   `'_\ : [ `/'`\]/ /__\\[ `.-. |
  _| |  \ \_ // | |, | |    | \__., | | | |
 |____||____|\'-;__/[___]    '.__.'[___||__]
}}} */
/* cpp template {{{*/
using namespace std;

#define endl '\n'

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define X real()
#define Y imag()
#define EQ(n,m) (abs((n)-(m)) < EPS)

typedef double D;
typedef long long ll;
typedef long double lb;
typedef complex<D> P;
typedef vector<P> VP;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<string, int> psi;

inline bool inside(int y,int x,int H,int W){return(y>=0&&x>=0&&y<H&&x<W);}
inline int in() {int x; std::cin >> x; return x;}

template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T>
void print(T x) {
  std::cout << x << '\n';
}
/* }}} */
/* ?????° {{{*/
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 9;
const D EPS  = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
/* }}} */

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int l, r, n = in();
  bool f;
  while (n--){
    l = r = 0;
    f = true;
    REP(i, 10){
      int a = in();
      if (a > l) l = a;
      else if (a > r) r = a;
      else f = false;
      if (l < r) swap(l, r);
    }
    (f)?cout << "YES" << endl:cout << "NO" << endl;
  }

  return (0);
}

C++: #include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <ctype.h>

using namespace std;

int main () {
    int b[10];
    int l=0,r=0;

    int x;
    cin>>x;
    
    while(cin>>b[0]>>b[1]>>b[2]>>b[3]>>b[4]>>b[5]>>b[6]>>b[7]>>b[8]>>b[9]){
        int flag=0;
        for(int i=0; i<10; i++){
            if(l<b[i]&&r<b[i]){
                if(l<r){
                    r=b[i];
                }else{
                    l=b[i];
                }
            }else if(l>b[i]&&r<b[i]){
                r=b[i];
            }else if(l<b[i]&&r>b[i]){
                l=b[i];
            }else{
                flag++;;
                break;
            }
        }
        
        if(flag){
            cout<<"NO"<<endl;
        }else{
            cout<<"YES"<<endl;
        }

    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int n;
  while(cin>>n){
    bool ok=true;
    int a,b=0,c=0;
    rep(i,10){
      cin>>a;
      if(a>b)b=a;
      else if(a>c)c=a;
      else ok=false;
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}

C++: #include<stdio.h>
int main(){
    int a;
    scanf("%d",&a);
    for(;a--;){
        int b[10];
        for(int i=0;i<10;i++)scanf("%d",b+i);
        bool ans=false;
        for(int i=0;i<1024;i++){
            int maxa=0;
            int maxb=0;
            bool val=true;
            for(int j=0;j<10;j++){
                if(i&1<<j){
                    if(maxa<b[j])maxa=b[j];
                    else val=false;
                }else{
                    if(maxb<b[j])maxb=b[j];
                    else val=false;
                }
            }
            if(val)ans=true;
        }
        printf(ans?"YES\n":"NO\n");
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int BALL_NUM = 10;

int ball[BALL_NUM];

bool IsLeft(int num, int left, int right) {
    if (left > num) { return false; }
    if (left > right || right > num) { return true; }
    else { return false; }
}

bool Simulate() {
    int left = 0, right = 0;
    bool flag = true;
    for (int j = 0; j < BALL_NUM; j++) {
        if (ball[j] < min(left, right)) {
            flag = false;
            break;
        }
        if (IsLeft(ball[j], left, right)) { left = ball[j]; }
        else { right = ball[j]; }
    }
    return flag;
}

int main() {
    long n;
    scanf("%ld", &n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < BALL_NUM; j++) {
            scanf("%d", &ball[j]);
        }
        if (Simulate()) { printf("%s\n", "YES"); }
        else { printf("%s\n", "NO"); }
    }
 
    return 0;
}