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 <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <stack>
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)++)

void solve33() {
    stack<int> st1;
    stack<int> st2;
    REP(i,10) {
        int j;
        cin >> j;
        if (st1.size() == 0 || st1.top() < j) st1.push(j);
        else if (st2.size() == 0 || st2.top() < j) st2.push(j);
        else break;
        if (i == 9) {cout << "YES" << endl; return;}
    }
    cout << "NO" << endl;
}

int main() {
    int n;
    cin >> n;
    REP(i,n) {
        solve33();
    }
    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

int main() {
	int n; cin >> n;
	int l = 0, r = 0;
	bool ok = true;
	while (n--) {
		rep(i, 10) {
			int b; cin >> b;
			if(l < b) l = b;
			else if (r < b) {
				r = b;
				if (l < r) swap(l, r);
			}
			else {
				ok = false;
			}
		}
		cout << (ok ? "YES" : "NO" ) << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <functional>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

int t,n=10,a[10002],b[10002],c[10002];
bool flag;

void dfs(int dep,int db,int dc)
{
	if(!flag)return;
	if(dep==n)
	{
		flag=0;
		for(int i=1;i<db;++i)
			if(b[i]<b[i-1])
				flag=1;
		for(int i=1;i<dc;++i)
			if(c[i]<c[i-1])
				flag=1;
		return;
	}
	b[db]=a[dep];
	dfs(dep+1,db+1,dc);
	c[dc]=a[dep];
	dfs(dep+1,db,dc+1);
}
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		flag=1;
		for(int i=0;i<n;++i)
			scanf("%d",&a[i]);
		dfs(0,0,0);
		if(flag)
			printf("NO\n");
		else
			printf("YES\n");
	}
	return 0;
}

C++: #include<stdio.h>
#include<queue>
#include<string.h>
using namespace std;
int main()
{
    int t;scanf("%d",&t);
    while(t--)
    {
        int i,j,k,l;
        int f=1;
        j=-0x3f3f3f;
        k=-0x3f3f3f;
        for(i=2;i<10;i++){
            scanf("%d",&l);
            if(f)
            {
                if(j<l){
                    j=l;
                }
                else
                if(k<l){
                    k=l;
                }
                else{
                    f=0;
                }

            }


        }
        if(f){
            printf("YES\n");

        }
        else
            printf("NO\n");

    }





    return 0;
}

C++: #include <iostream>

using namespace std;

int ball[10],f;

int hukasa(int cup1,int cup2,int no){
	//cout << "NOW no:" << no << endl;
	if(no>=10)return 1;
	else if((ball[no]<cup1)&&(ball[no]<cup2))return 0;
	
	if(cup1<ball[no])return hukasa(ball[no],cup2,no+1);
	if(cup2<ball[no])return hukasa(cup1,ball[no],no+1);
}
int main(){
	int n;
	cin>>n;
	while(n!=0){
		f = 0;
		for(int i=0;i<10;i++){
			cin>>ball[i];
			}
		f = hukasa(0,0,0);
		//cout << "f is " << f << endl;
		if(f==1)cout << "YES" << endl;
		else cout<<"NO"<<endl;
		n-=1;
}
}

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

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

	for (int i = 0; i < n; i++) {
		vector<vector<int>> v{ {0} };
		for (int j = 0; j < 10; j++) {
			cin >> x;
			for (int k = 0; k < v.size(); k++) {
				if (v[k].back() < x) {
					v[k].push_back(x);
					break;
				}

				if (k == v.size() - 1) {
					v.push_back({ x });
					break;
				}
			}

			if (v.size() == 3) {
				x = -1;
				break;
			}
		}
		if (x == -1) {
			cout << "NO";
		}
		else {
			cout << "YES";
		}
		cout << endl;
	}
	return 0;
}

C++: #include<iostream>
#define MAX_BALL 10
using namespace std;

int ball[MAX_BALL];
int n;
int r = 0, l = 0;
bool flag = 0;

void dfs(int x)
{
	if (x == MAX_BALL)
	{
		flag = true;
		return;
	}
	if (ball[x] >= r)
	{
		r = ball[x];
		dfs(x + 1);
	}
	if (ball[x] >= l)
	{
		l = ball[x];
		dfs(x + 1);
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		flag = false;
		r = 0;
		l = 0;
		for (int j = 0; j < MAX_BALL; j++)
			cin >> ball[j];
		dfs(0);
		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

C++: #include <cstdio>

#define N 10

int D, Ball[N];
int R, L;

bool solve(int i) {
	if(i == N) return true;
	if(R < Ball[i]) {
		R = Ball[i];
		if( solve(i+1) ) return true;
	}
	if(L < Ball[i]) {
		L = Ball[i];
		if( solve(i+1) ) return true;
	}
	return false;
}

int main() {
	scanf("%d", D);
	for(int i = 0; i < D; i++) {
		R = L = 0;
		for(int j = 0; j < N; j++) scanf("%d", &Ball[j]);
		R = Ball[0];
		if( solve(1) )	printf("YES\n");
		else			printf("NO\n");
	}
	return 0;
}

C++: #include <cstdio>
#include <vector>

using namespace std;

int N;
const int LEN = 10;
int arr[LEN+1];
vector<int> bucket[2];

bool dfs(int n, int idx)
{
    if (n == LEN)
        return true;
    vector<int>& buc = bucket[idx];
    if (!buc.empty() && arr[n] < buc.back()) return false;
    buc.push_back(arr[n]);
    bool res[2];
    res[0] = dfs(n+1, 0);
    if (res[0]) goto finish;
    res[1] = dfs(n+1, 1);
finish:
    buc.erase(buc.end()-1);
    return res[0] || res[1];
}

int main()
{
    scanf("%d", &N);
    for (int j = 0; j < N; j++) {
        for (int i = 0; i < LEN; i++) {
            scanf("%d", &arr[i]);
        }
        if (dfs(0, 0) || dfs(0, 1)) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int ball;
	int n;
	while(cin >> n){
		bool flag = true;
		for(int i=0; i<n; i++){
			int B=0, C=0;
			for(int j=0; j<10; j++){
				cin >> ball;
				if(flag){
					if(B < ball) B=ball;
					else if(C < ball) C=ball;
					else flag=false;
				}
			}
			
			if(flag) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
	return 0;
}