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 <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

int a[10005];
int dp[10005];
int n;

///flag == 0求最长不上升子序列的长度
///flag == 1求最长不上升子序列的最少数目
///（即最长上升子序列的长度）
void slove(bool flag)
{
    int ans = 0;
    for(int i = 0; i < n; ++i)
    {
        dp[i] = 1;
        for(int j = 0; j < i; ++j)
        {
            if(!flag && a[j] < a[i])
                dp[i] = max(dp[i], dp[j] + 1);
            if(flag && a[j] >= a[i])
                dp[i] = max(dp[i], dp[j] + 1);
        }
        ans = max(ans, dp[i]);
    }
    if(ans <= 2)
        cout << "YES" << '\n';
    else
        cout << "NO" << '\n';
}

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        n = 10;
        for(int i = 0; i < 10; ++i)
            cin >> a[i];
        slove(1);
    }
    return 0;
}

C++: #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <ostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define INF 1000000000
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define rev(i,a,b) for (int i=(a)-1;i>=b;i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef queue<int> qi;
typedef queue< pair<int, int> > qpii;
typedef vector<int> vi;
typedef vector<int, int> vii;
typedef vector<string> vs;
typedef vector< pair<int, int> > vpii;
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

int n[10];
int h, w;

bool dfs(int b, int c, int cnt) {
  if(cnt == 10) return true;
  if(n[cnt] > n[b]) {
    if(dfs(cnt, c, cnt+1)) return true;
  }
  if(c == -1 || n[cnt] > n[c]) {
    if(dfs(b, cnt, cnt+1)) return true;
  }
  return false;
}

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

  int num;
  cin >> num;
  rep(i,0,num) {
    rep(j,0,10) cin >> n[j];

    if(dfs(0, -1, 1)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }

	return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> d(10);
	int b, c;

	for (int i = 0; i<N; i++){
		for (int k = 0; k < 10; k++)
			cin >> d.at(k);

		b = d.at(0);
		c = 0;
		for (int k = 1; k < 10; k++){
			if (b < c){
				if (b > d.at(k)){
					cout << "NO" << endl;
					break;
				}
				else{
					if (c < d.at(k))
						c = d.at(k);
					else
						b = d.at(k);
				}
			}

			else{
				if (c > d.at(k)){
					cout << "NO" << endl;
					break;
				}
				else{
					if (b < d.at(k))
						b = d.at(k);
					else
						c = d.at(k);
				}
			}
			if (k == 9)
				cout << "YES" << endl;
		}
	}
}

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

int l=0, r=0;
bool flag=true;

void solve(int N) {
	int a = 0;
	while (N > 0) {
		for (int i = 0; i < 10; i++) {
			cin >> a;
			if (a > l)
				l = a;
			else if (a > r)
				r = a;
			else 
				flag = false;
		}
		if (flag == true)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
		flag = true;
		l = 0;
		r = 0;
		N--;
	}
}
int main() {
	int n = 0;
	cin >> n;
	solve(n);
	return 0;
}

C++: #include <iostream>

using namespace std;

int main( void )
{
	int n, input[10], stA[10], stB[10];
	cin >> n;
	while(n--) {
		for(int i=0; i < 10; ++i) {
			stA[i] = stB[i] = 0;
			cin >> input[i];
		}
		int idxI, idxA, idxB;
		idxI = 2; idxA = idxB = 0;
		stA[0] = input[0]; stB[0] = input[1];
		bool hit = true;
		while(10 > idxI && hit) {
			int tmp = input[idxI];
			if(stB[idxB] < stA[idxA]) { // A
				if(stA[idxA] < tmp) stA[++idxA] = tmp;
				else if(stB[idxB] < tmp) stB[++idxB] = tmp;
				else hit = false;
			}
			else {	// B
				if(stB[idxB] < tmp) stB[++idxB] = tmp;
				else if(stA[idxA] < tmp) stB[++idxA] = tmp;
				else hit = false;
			}
			++idxI;
		}
		if(idxI == 10 && hit)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int const N=10;
int src[N];
int a[N+1], b[N+1];//a存放左边的球，b存放右边
int aindex;//记录左边有多少球
int bindex;//右边有多少球
int ans;//标记是否能找到

void dfs(int i){//dir 标记球放在哪一边
	if (i == N){ ans = 1; return; }
	//球i放在左边
	if (src[i]>=a[aindex]){
		a[++aindex] = src[i];
		dfs(i+1);
		aindex--;
	}
	//球放在左边
	if (src[i] >= b[bindex]){
		b[bindex] = src[i];
		dfs(i + 1);
		bindex--;
	}
	return;
}
int main(){
	int n;
	cin >> n;
	while (n--){
		ans = 0;
		aindex = 0; bindex = 0;
		a[aindex] = -9999; b[bindex] = -9999;
		for (int i = 0; i < N; i++){
			cin >> src[i];
		}
		dfs(0);
		if (ans)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

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

using namespace std;

const int BALL_NUM = 10;

long n;

bool IsLeft(int num, int left, int right) {
    if (left > num) { return false; }
    if (left > right || right > num) { return true; }
    else { return false; }
}

int main() {
    int b, left = 0, right = 0;
    bool flag = true;
    scanf("%ld", &n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < BALL_NUM; j++) {
            scanf("%d", &b);
            if (b < min(left, right)) {
                flag = false;
                break;
            }
            if (IsLeft(b, left, right)) { left = b; }
            else { right = b; }
        }
        if (flag) { printf("%s\n", "YES"); }
        else { printf("%s\n", "NO"); }
    }

    return 0;
}

C++: #include <stdio.h>
#include <stdbool.h>
??
#define NUM_BALL 10
??
int main(void)
{
????int???????????? n;
????int???????????? num;
????int???????????? left, right;
????bool?? flag = true;
????int???? i, j;
??
????scanf("%d", &n);
????for (i = 0; i < n; i++) {
????????????????left = right = -1;
????????????????for (j = 0; j < NUM_BALL; j++) {
????????????????????????scanf("%d", &num);
????????????????????????if?????????? (num > left) { left?? = num; }
????????????????????????else if (num > right)?????? { right = num; }
????????????????????????else?????? { flag?? = false; break; }
????????????????}
????????????????puts((flag) ? "YES" : "NO");
????????}
??
????????return 0;
}

C++: #include<iostream>
using namespace std;
int d[10]={};
bool f;
void dfs(int l,int r int s){
  if(s==10) f=true;
  //cout << d << endl;
  if(l<d[s]){
    dfs(d[s],r,s+1);
  }
  if(r<d[s]){
    dfs(l,d[s],s+1);
  }
}
int main(){
  int n;cin >> n;
  while(n--){
    int r=0,l=0,d;
    f=false;
    for(int i=0;i<10;i++){
      cin >> d;
      //cout << l << ":" << r << endl;
    }
    dfs(0,0,0);
    if(f) cout << "NO" << endl;
    else cout << "YES" << endl;
  }  
}

C++: #include<iostream>
#include<vector>
//#include<ctime>
using namespace std;
int main(){
	int n;
	cin >> n;
	//clock_t t1, t2;
	//t1 = clock();
	for(int i = 1; i <= n; i++){
		int num[10];
		for(int j = 0; j < 10; j++) cin >> num[j];
		bool flag = false;
		for(int j = 0; j < (1 << 10); j++){
			vector<int> va, vb;
			for(int k = 0; k < 10; k++){
				if(j & (1 << k)) va.push_back(num[k]);
				else vb.push_back(num[k]);
			}
			bool flag_ = true;
			for(int k = 1; k < va.size(); k++){
				if(va[k] < va[k - 1]) flag_ = false;
			}
			for(int k = 1; k < vb.size(); k++){
				if(vb[k] < vb[k - 1]) flag_ = false;
			}
			if(flag_) flag = true;
		}
		if(flag) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	//t2 = clock();
	//cout << t2 - t1 << endl;
	return 0;
}