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[10];
bool dfs(int d, int l, int r){
    if(d == 10) return true;
    if(a[d] > l && dfs(d + 1, a[d], r))
      return true;
    if(a[d] > r && dfs(d + 1, l, a[d]))
       return true;
    return false;
}
int main(){
    int n;
    cin >> n;
    for(int k = 0; k < n; k++){
        for(int i = 0; i < 10; i++)
          cin >> a[i];
        if(dfs(0, 0, 0))
          puts("YES");
        else
          puts("NO");
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std ;
int a[50] ,flag , l , r  ;
void dfs(int x , int l , int r)
{
    if(x==11) return ;
    if(a[x]>l) dfs(x+1,a[x],r);
    else if(a[x]>r) dfs(x+1,l,a[x]);
    else
    {
        flag = 1 ;
        return;
    }
}
int main()
{
    int t ;
    cin>>t;
    while(t--)
    {
        flag = 0 ;
        for(int i = 1 ; i<=10;i++)
        {
            cin>>a[i];
        }
        dfs(1,0,0);
        if(flag) printf("NO\n");
        else printf("YES\n");
    }
    return 0 ;
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
	int a,b;
	int n;
	int g;
	bool check;
	vector<int> ball;

	while(cin >> n){
		a = b = 0;
		check = true;
		rep(i,10){
			cin >> g;
			ball.insert( ball.begin(), g);
		}
		rep(i,10){
			if(a < ball.back()){
				a = ball.back();
				ball.pop_back();
			}else if(b < ball.back()){
				b = ball.back();
				ball.pop_back();
			}else{
				check = false;
			}
		}
		if(check) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(void)
{
    int bo[11],n,B[11],C[11],b1=0,c1=0,A=0,k=0,l=1;
    cin>>n;
    for(int i=0;i<n;i++){
            C[0]=11;k=0;l=0;B[0]=0;b1=0;c1=0;C[1]=13;
        for(int j=0;j<10;j++){
            cin>>bo[j];
        }
        for(int j=1;;j++){
                cout<<bo[j]<<" ";
            if(j==1)B[0]=bo[0];
        if(C[0]==11&&j==2){
            C[0]=bo[j];
            k++;
            cout<<"6\n";
        }else if(C[1]==13&&j>3&&C[0]<bo[j]){
            C[1]=bo[j];
            k++;
            c1=1;
            cout<<"7\n";
        }else if(B[l]<bo[j]){
            b1=1;
            B[l+1]=bo[l];
            l++;
            cout<<"1\n";
        }else if(C[0]==11){
            C[0]=bo[j];
            k++;
            cout<<"2\n";
        }else if(C[k-1]<bo[j]){
            c1=1;
            C[k+1]=bo[j];
            cout<<"3\n";
        }else if(B[l]<bo[j+1]){
            C[k+1]=bo[j];
            k++;
            cout<<"5\n";
        }else{
            B[l+1]=bo[j];
            l++;
            cout<<"4\n";
        }
        if(j==9||(b1==1&&c1==1))break;
    }
    if(b1==1&&c1==1)cout<<"YES\n";
    else cout<<"NO\n";
    for(int j=0;j<10;j++){
        B[j]=0;C[j]=0;
    }

}
}

C++: #include <iostream>
#include <stack>

using namespace std;

int main()
{
    int n;
    cin >> n;

    for( int iii=0; iii<n; ++iii ) {
        stack<int> p[2];
        bool succ = true;

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

            if ( p[0].size() == 0 ) {
                p[0].push( ball );

            } else {
                int diff = 999;
                int t;
                for( int j=0; j<2; ++j ) {
                    int r = 0;
                    if ( !p[j].size() == 0 )
                        r = ball - p[j].top();
                    if ( r < 0 )
                        continue;

                    if ( r < diff ) {
                        t = j;
                        diff = r;
                    }
                }

                if ( diff == 999 ) {
                    succ = false;
                } else {
                    p[t].push( ball );
                }

            }
        }

        cout << ( succ ? "YES" : "NO" ) << endl;
    }
}

C++: // 
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define roop(a,t) for(int a=0;a<t;a++) 
int a[10], n;
bool bit(int n,vector<int>left,vector<int>right) {
	if (n == 10) {
		bool left_f = true;
		bool left_r = true;
		roop(i, left.size() - 1) { if (left[i + 1] <= left[i]) { return false; } }
		roop(i, right.size() - 1) { if (right[i + 1] <= right[i]) { return false; } }
		return true;
	}
	if (left[left.size() - 1] > a[n] && right[right.size() - 1] > a[n]) { return false; }
	vector<int>new_l = left;
	vector<int>new_r = right;
	
	new_l.push_back(a[n]);
	new_r.push_back(a[n]);
	return (bit(n + 1, new_l, right) || bit(n + 1, left, new_r));
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	vector<int>emptynow;
	roop(i, n) {
		roop(j, 10) {
			cin >> a[j];
		}
		if (bit(0, emptynow, emptynow)) { cout << "YES" << endl;}
		else { cout << "NO" << endl; }
	}
	return 0;
}

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

typedef long long ll;

using namespace std;

vector<int> balls(10);

bool flag;

void dfs(int i, int left, int right) {
    if (i == 10) {
        flag = true;
        return;
    }
    int num = balls[i];
    if (left < num) {
        dfs(i+1, num, right);
    }
    if (right < num) {
        dfs(i+1, left, num);
    }
}

void solve() {
    flag = false;
    for (int i = 0; i < 10; i++) {
        cin >> balls[i];
    }
    dfs(0, 0, 0);
    string ans = flag ? "YES": "NO";
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N = 0;
    cin >> N;

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

C++: #include <iostream>

using namespace std;

int main() {

	int a, b=0, i, N, x[10], end=0;

	cin >> N;
	for(; N!=0; N--) {
		for(i=0; i<10; i++)
			cin >> x[i];
		for(i=0; i<10; i++) {
			if(i==0) {
				a=x[i];
				i++;
			}
			if(a>x[i]&&b>x[i]) {
				end++;
				break;
			}
			if(a<x[i])
				a=x[i];
			else if(b<x[i])
				b=x[i];
		}

		if (end!=0)
			cout << "NO" << endl;
		else
			cout << "YES" << endl;
		end=0;
	}

	return 0;

}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;

int main(void){
  int n,N;
  vector<int> v(10);
  cin >> N;
  REP(n,N){
    int i;
    bool flg = true;
    REP(i,v.size()) cin >> v[i];
    int max = 0,min = 0;
    REP(i,v.size()){
      if(max<v[i]) max = v[i];
      else if(min<v[i]) min = v[i];
      else{
        flg = false;
        break;
      }
    }
    if(flg) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}