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 main(){
    
    int n;
    cin >> n;

    int b[n][10];
    

    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            cin >> b[i][j];
        }
    }

    bool check[n];
    for(int i=0;i<n;i++){
        check[i]=true;
    }

    for(int i=0;i<n;i++){
        vector<int> x,y;
        x.push_back(0);
        y.push_back(0);
        x.push_back(b[i][0]);
        
        
        for(int j=1;j<10;j++){
            int pa = x[x.size()-1];
            int pb = y[y.size()-1];

            int p = b[i][j];

            if(p<pa&&p<pb){
                check[i] = false;
            }else if(p<pa&&p>pb){
                y.push_back(p);
            }else if(p>pa&&p<pb){
                x.push_back(p);
            }else{
                if(pa<pb){
                    y.push_back(p);
                }else{
                    x.push_back(p);
                }
            }
        }
    }


    for(int i=0;i<n;i++){
        if(check[i]){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    
    return 0;
}

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

int a[10];

int main() {
    int n, x, y, f;
    cin >> n;
    while (n--) {
        for (int i = 0; i < 10; i++) cin >> a[i];
        x = y = f = 0;
        for (int i = 0; i < 10; i++) {
            if (a[i] > x)
                x = a[i];
            else if (a[i] > y)
                y = a[i];
            else {
                f = 1;
                break;
            }
        }
        if (f)
            cout << "NO\n";
        else
            cout << "YES\n";
    }
}

C++: 
#include<cstdio>
using namespace std;
const static int MAX_N = 12;
static int num[12], left[12], right[12];
static bool ret = false;
void dfs(int cur, int n, int num[], int left[],int l, int right[],int r) {
	if (cur == n) {
		for (int i = 0; i < l-1; i++) {
			if (left[i] > left[i + 1])
				return;
		}
		for (int j = 0; j < r - 1; j++) {
			if (right[j] > right[j + 1])
				return;
		}
		ret = true;
	} else {
		left[l] = num[cur];
		dfs(cur + 1, n, num, left, l + 1, right, r);
		right[r] = num[cur];
		dfs(cur + 1, n, num,left, l, right, r + 1);
	}
}

int main() {
	int n;
	for (scanf("%d ", &n); n; n--) {
		for (int i = 0; i < 10; i++) {
			scanf("%d", &num[i]);
		}
		dfs(0, 10, num, left, 0, right, 0);
		if (ret)printf("YES\n");
		else printf("NO\n");
		ret = false;
	}
}

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\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 <bits/stdc++.h>

using namespace std;

int main(){
    int n; cin >> n;
    while(n--){
        vector<int> v(10);
        rep(i,10) cin >> v[i];
        int a=0, b=0;
        bool is = true;
        for(int i=0; i< 10; i++){
            if(v[i] < a && v[i] < b){is = false; break;}
            if(a < b) (b<v[i]?b:a) = v[i];
            else (a<v[i]?a:b) = v[i];
        }
        cout << (is?"YES":"NO") << endl;
    }
}

C++: #include <cstdio>
#include <stack>
using namespace std;

int main(void)
{
    int n;
    scanf("%d", &n);
    
    for (int i = 0; i < n; i++){
        stack < int > b, c;
        int j;
        
        b.push(0);
        c.push(0);
        
        int ball[10];
        for (int i = 0; i < 10; i++){
            scanf("%d", &ball[i]);
        }
        
        for (j = 0; j < 10; j++){
            if (b.top() < ball[j]){
                if (c.top() < ball[j]){
                    if (c.top() < b.top()){
                        b.push(ball[j]);
                    }
                    else {
                        c.push(ball[j]);
                    }
                }
                else {
                    b.push(ball[j]);
                }
            }
            else if (c.top() < ball[j]){
                c.push(ball[j]);
            }
            else {
                break;
            }
        }
        
//        printf("%d\n", j);
        
        if (j == 10){
            printf("YES\n");
        }
        else {
            printf("NO\n");
        }
    }
    
    return (0);
}

C++: #include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
int a[10];
bool ans;
void dfs(int i,int r,int l){
	if(i==10)ans=1;
	if(a[i]<r&&a[i]<l)return;
	if(ans)return;
	if(r<a[i])dfs(i+1,a[i],l);
	if(l<a[i])dfs(i+1,r,a[i]);

}
int main(){
	int t;
	cin>>t;
	while(t--){
		ans=0;
		for(int i=0;i<10;i++)cin>>a[i];
		dfs(0,0,0);
		if(ans)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int a[10];
int n;

bool dfs(int i,int left,int right){
	if(i==10) return true;
	if(a[i]>left){
		return dfs(i+1,a[i],right);
	}
	if(a[i]>right){
		return dfs(i+1,left,a[i]);
	}
	return false;
}

void solve(){
	rep(i,10) cin >> a[i];
	if(dfs(0,0,0)) cout << "YES" << endl;
	else cout << "NO" << endl;
	return;
}

int main(){
	cin >> n;
	rep(i,n){
		solve();
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
#define N 10
int flag;
int shunxu[N+5];
void dfs(int x1,int y1,int x2,int y2,int ans) {
	if (x2 < x1 || y2 < y1)
		return;
	if (ans == 10) {
		flag = 1;
		return;
	}
	dfs(x2, y1, shunxu[ans], y2, ans + 1);
	dfs(x1, y2, x2, shunxu[ans], ans + 1);
}
int main()
{
	int n;
	cin >> n;
	while (n--) {
		for (int i = 0; i < N; i++) {
			cin >> shunxu[i];
		}
		flag = 0;
		dfs(0, 0, 0, 0, 0);
		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

int b[10];

bool dfs(int idx, int left, int right)
{
	if (idx == 10) return true;

	if (b[idx] > left && dfs(idx + 1, b[idx], right)) return true;
	if (b[idx] > right && dfs(idx + 1, left, b[idx])) return true;

	return false;
}

int main()
{
	int n; cin >> n;
	while (n--) {
		for (int i = 0; i < 10; ++i) cin >> b[i];

		cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
	}
}

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

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

bool ans;
int a[10];

void dfs(int idx, int l, int r) {
   if (idx == 10) {
      ans = true;
      return;
   }

   int val = a[idx];
   if (l < val) dfs(idx+1, val, r);
   if (r < val) dfs(idx+1, l, val);
}

int main() {
   int N;
   cin >> N;
   while (N--) {
      for (int i = 0; i < 10; i++) cin >> a[i];
      ans = false;
      dfs(0, -1, -1);
      puts(ans ? "YES" : "NO");
   }

   return 0;
}