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 <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[20],vis[20];
int b[20],c[20];
int n;
bool flag = false;
bool dfs(int i,int j,int k)
{
    if(i > n)
    {
        flag = true;
        return true;
    }
    if(flag = true)
        return true;
    if(a[i] > c[j - 1]){
        c[j] = a[i];
        dfs(i + 1,j + 1,k);
    }
    if(a[i] > b[k - 1]){
        b[k] = a[i];
        dfs(i + 1,j,k + 1);
    }
    return false;
}
int main()
{
    scanf("%d",&n);
    while(n --)
    {
        for(int i = 0; i < 10; i++)
            scanf("%d",&a[i]);
        flag = false;
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        if(dfs(0,1,0))
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

C++: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define FORR(i,a,b) for (int i=a; i>=b; i--)

typedef long long ll;

int dp[1010][2]={};

int main(void){
	const int n=10;
	int a[n];
	int m;
	cin >> m;
	while (m--){
		REP(i,n) cin >> a[i];
		int x=0,y=0;
		bool f=1;
		REP(i,n){
			if (a[i]<x && a[i]<y){
				f=0;
				break;
			}
			else if (a[i]<y)
				x=a[i];
			else if (a[i]<x)
				y=a[i];
			else{
				if (x<y)
					y=a[i];
				else
					x=a[i];
			}
		}
		if (f)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;

	}

	return 0;
}

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

int a[10],l,r;

bool dfs(int n)
{
	if(n>=10)return true;
	int x;
	if(a[n]>l)
	{
		x=l;
		l=a[n];
		if(dfs(n+1))return true;
		l=x;
	}
	if(a[n]>r)
	{
		x=r;
		r=a[n];
		if(dfs(n+1))return true;
		r=x;
	}
	return false;
}

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		l=0;r=0;
		for(int i=0;i<10;i++)scanf("%d",a+i);
		if(dfs(0))printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

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

int main(){
	unsigned c, tmp, d[2] = {0};
	bool res;

	scanf("%d", &c);

	while(c--){
		res = true;
		d[0] = d[1] = 0;

		for(int i = 0; i < 10; ++i){
			std::cin >> tmp;
		
			if( d[0] < tmp ){
				if(d[1] < tmp){
					*std::max_element(d, d + 1) = tmp;
				}else{
					d[0] = tmp;
				}
			}else if( d[1] < tmp ){
				d[1] = tmp;
			}else{
				res = false;
				break;
			}
		}

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

	return 0;
}

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int N;

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

      bool flag = false;
      for (int mask = 0; mask < (1<<10); mask++) {
         vector<int> b, c;
         for (int j = 0; j < 10; j++) {
            if ( (mask >> j) & 1 ) {
               b.push_back(a[j]);
            } else {
               c.push_back(a[j]);
            }
         }
         bool f = true;
         for (int k = 1; k < b.size(); k++) {
            if (b[k-1] > b[k]) f = false;
         }
         for (int k = 1; k < c.size(); k++) {
            if (c[k-1] > c[k]) f = false;
         }
         if (f) {
            flag = true;
         } 
      }

      if (flag) {
         puts("YES");
      } else {
         puts("NO");
      }
   }

   return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<cmath>
#include<ctype.h>
#include<vector>
#include<cstdlib>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<stack>
#include<map>

#define ll long long
#define LL long long
#define ULL unsigned long long 
#define ull unsigned long long 
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)

using namespace std;
int N;


int ball[11];


bool solve(int i,int tmp_1,int tmp_2) {
	if (tmp_1 < ball[i] && tmp_2 < ball[i]) 
		return max(solve(i + 1, ball[i], tmp_2), solve(i + 1, tmp_1, ball[i]));
	
	if (tmp_1 < ball[i] && tmp_2 >= ball[i]) 
		return solve(i + 1, ball[i], tmp_2);
	
	if (tmp_1 >= ball[i] && tmp_2 < ball[i]) 
		return solve(i + 1, tmp_1, ball[i]);
	
	if (i == 10) 
		return true;
	
	if (tmp_1 >= ball[i] && tmp_2 >= ball[i]) 
		return false;
	

}

int main()
{
	int tmp[2] = {};
	cin >> N;
	REP(i, N) {
		REP(j, 10) {
			cin >> ball[j];
		}
		if (solve(0, 0, 0)) {
			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\n");
	else printf("NO\n");
}
			
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>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

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

#define PI 3.14159265358479

typedef long long ll;

int n, k, b = 0, c = 0;
//int l = 0, m = 0;
bool f = 1;
stack<int> sb, sc;

int main(){
	cin >> n;
	REP(i, n){
		REP(j, 10){
			cin >> k;
			if (b == 0){
				sb.push(k);
				b++;
				//l = sb.top();
			}
			else if (c == 0){
				sc.push(k);
				if (sb.top() < k){
					sc.push(sb.top());
					sb.push(k);
				}
				c++;
				//m = sc.top();
			}
			else{
				if (sb.top() < k){
					sb.push(k);
				}
				else if (sc.top() < k){
					sc.push(k);
				}
				else{
					f = 0;
				}
				//l = sb.top();
				//m = sc.top();
			}
			//cout << n << m << "\n";
		}
		sb.empty();
		sc.empty();
		if (f){
			cout << "YES\n";
		}
		else{
			cout << "NO\n";
		}
	}
}