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<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int n;
    cin >> n;
    rep(i, n){
        vector<int> b, c;
        b.push_back(-1);
        c.push_back(-1);
        bool flag = true;
        rep(j, 10){
            int a;
            cin >> a;
            if(flag){
                if(b[b.size()-1] < c[c.size()-1]){
                    if(c[c.size()-1] < a){
                        c.push_back(a);
                    }else if(b[b.size()-1] < a){
                        b.push_back(a);
                    }else{
                        flag = false;
                    }
                }else{
                    if(b[b.size()-1] < a){
                        b.push_back(a);
                    }else if(c[c.size()-1] < a){
                        c.push_back(a);
                    }else{
                        flag = false;
                    }
                }
            }
        }
        if(flag){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

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

int num[10];

bool f;
void dfs(int x, int l, int r) {
	if (x == 10) {
		f = true;
	}
	if (num[x] > l) {
		dfs(x + 1, num[x], r);
	}
	if (num[x] > r) {
		dfs(x + 1, l, num[x]);
	}
}

int main() {
	int T;
	cin >> T;
	cin.ignore();
	while (T--) {
		string line;
		getline(cin, line);
		stringstream ss(line);
		for (int i = 0; i < 10; i++) {
			ss >> num[i];
		}
		f = false;
		dfs(0, 0, 0);
		if (f) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1009;
int a[maxn];
int b[maxn];
int c[maxn];
int ln,lm,flag;
int t;
bool erjinzhi()
{
    for(int i=0;i<1024;i++)
    {
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        ln=0;
        lm=0;
        flag=1;
        for(int j=i,cnt=0;cnt<10;cnt++,j>>=1)
        {
            if(j&1)
            b[ln++]=a[cnt];
            else
            c[lm++]=a[cnt];
        }
        for(int k=1;k<ln;k++)
        {
            if(b[k-1]>b[k])
            {
                flag=0;
                break;
            }
        }
        if(flag)
        for(int k=1;k<lm;k++)
        {
            if(c[k-1]>c[k])
            {
                flag=0;
                break;
            }
        }
        if(flag)return true;
    }
    return false;
}
int main()
{
    scanf("%d",&t);
    while(t--)
    {

     for(int i=0;i<10;i++)
     scanf("%d",&a[i]);
     bool fl=erjinzhi();
     if(fl)
     printf("YES\n");
     else
     printf("NO\n");
    }
    return 0;
}

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;
	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){
					s1.push(a);
					continue;
			}
			yes=false;

		}
		if (yes)
			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");
	else printf("NO");
}*/

bool back(int right, int left, int n){
	if(n == 10) return true;
	bool result = false;
	if(right<a[n]) result = result || back(a[n],left,n+1);
	if(left<a[n]) result = result || back(right,a[n],n+1);
	return result;
}

void solve(){
	if(back(0,0,0)) printf("YES");
	else printf("NO");
}
			
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 <iostream>
using namespace std;

int Balls[10];

bool fork(int balls[], int i, int b, int c) {
    if (i == 10) return true;
    if (b > balls[i] && c > balls[i]) return false;
    if (b < balls[i]) fork(balls, i + 1, balls[i], c);
    if (c < balls[i]) fork(balls, i + 1, b, balls[i]);
}


int main() {
    int n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> Balls[j];
        if(fork(Balls, 0, 0, 0)) {cout << "YES" << endl;}
        else(){cout << "NO" << endl;}
        }

    }
        return 0;
}

C++: 
#include <iostream>

using namespace std;

int main() {
	const bool debug = false;
	int N;
	cin >> N;

	int* balls = new int[N * 10];
	for (int i = 0; i < N * 10; i++) {
		cin >> balls[i];
	}

	for (int j = 0; j < N; j++) {
		bool isYes = true;
		int hole[2] = { 0,0 };
		for (int i = 0; i < 10; i++) {
			if (hole[0] < balls[i+j*10]) {
				hole[0] = balls[i + j * 10];
				if (debug)
					cout << "" << balls[i + j * 10] << "\n";
			} else if (hole[1] < balls[i + j * 10]) {
				hole[1] = balls[i + j * 10];
				if (debug)
					cout << "  " << balls[i + j * 10] << "\n";

			} else {
				if (debug)
					cout << "falure\n";
				isYes = false;
				break;
				
			}
		}
		cout << (isYes ? "YES" : "NO") << "\n";
	}
}