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<vector>
using namespace std;

const int max_v = 10;
vector<int> l;
vector<int> r;

void solve(int N) {
	int k = 0, a = 0, flag = 0;
	while (k < N) {
		for (int i = 0; i < 10; i++) {
			cin >> a;
			if (l.empty() && r.empty())
				l.push_back(a);
			else if (a > l.back())
				l.push_back(a);
			else {
				if (r.empty())
					r.push_back(a);
				else if (a > r.back())
					r.push_back(a);
				else {
					cout << "NO" << endl;
					l.clear();
					r.clear();
					flag = 1;
					break;
				}
			}
		}
		if (flag == 1)
			k++;
		else {
			cout << "YES" << endl;
			l.clear();
			r.clear();
			k++;
		}
	}
}
int main() {
	int n;
	cin>>n;
	solve(n);
	return 0;
}

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

int main(){

  int n,z;
  queue < int > a;

  cin >> n;

  for(int i=0;i<n;i++){
    int x = 0,y = 0;

    for(int j=0;j<10;j++){
      cin >> z;
      a.push(z);
    }

    for(int j=0;j<10;j++){

      if(a.front() > x && a.front() > y){
	if(x < y){
	  y = a.front();
	  a.pop();
	}
	else{
	  x = a.front();
	  a.pop();
	}
      }

      else if(a.front() > x){
	x = a.front();
	a.pop();
      }

      else if(a.front() > y){
	y = a.front();
	a.pop();
      }
    }

    if(a.empty() == true) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

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


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(){
    for(int i=0;i<10;i++){
        cin>>a[i];
    }
    if(dfs(0,0,0)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return;
}

int main(){
    cin>>n;
    for(int i=0;i<2;i++){
        solve();
    }
    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)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	vector<bool>l;
	int o[10], n;
	cin >> n;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < 10; j++)
			cin >> o[i];
		int sum = o[i], num = 0;
		for (int k = 0; k < 10;k++) {
			if (o[k] < sum){
				num++;
				sum = o[k];
			}
		}
		l.push_back(!(num >= 2));
	}
	for (bool b : l) {
		if (!b)cout << "YES";
		else cout << "NO";
		cout << endl;
	}
	char c;
	cin >> c;
}

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

using namespace std;

int main() {
	vector<int> left;
	vector<int> right;
	vector<int> all;

	bool flag = true;

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else  if (all.size() == (i+1)*(j+1)) {

						}
						else {
							flag = false;
						}			  						
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}

		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
		flag = true;
	}

	return 0;
}

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

int inp[10];
int n;

bool dfs(int b, int c, int depth) {
  if (depth >= 10) return true;
  if (inp[depth] < b && inp[depth] < c) return false;
  if (inp[depth] > b) dfs(inp[depth], c, depth+1);
  if (inp[depth] > c) dfs(inp[depth], c, depth+1);
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    canbe = false;
    for (int j = 0; j < 10; j++) cin >> inp[j];
    cout << (dfs(0,0,0) ? "YES": "NO") << endl;
  }

  return 0;
}

C++: #include <stdio.h>
#include <iostream>

using namespace std;

bool hantei(int k[], int l, int m, int n) {
	if (l == 0) {
		return true;
	} else {
		if (k[10-l] > m) {
			return hantei(k,l-1,k[10-l],n);
		} else if(k[10-l] > n) {
			return hantei(k,l-1,m,k[10-l]);
		} else {
			return false;
		}
	}
}


int main() {
	int n;
	int kazu[10];
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> kazu[j];
		}
		if (hantei(kazu,10,0,0)) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
int x[15],l[15],r[15];
int kase;
void dfs(int i,int j,int k)//i 是当前下落的球，j是左?的桶的第几个球，k 是右?放入
{
	if(i>10)//如果可以全部下落，肯定?足
	{
		kase=1;
		return;
	}
	if(kase)
	{
		return;
	}
	if(x[i]>l[j-1])//??落在左?
	{
		l[j]=x[i];dfs(i+1,j+1,k);
	}
	if(x[i]>r[k-1])//??落在右?
	{
		r[k]=x[i];dfs(i+1,j,k+1);
	}
}
int main()
{
	int t; 
	//freopen("shuju.txt","r",stdin);
	scanf("%d",&t);
	while(t--)
	{
		for(int i=1;i<=10;++i)
		{
			scanf("%d",&x[i]);
		}
		kase=0;
		dfs(1,1,1);
		if(kase)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
	int time;
	cin>>time;
	int ball[10];
	vector<int> line1;
	vector<int> line2;
	for(int i2=0;i2<time;++i2){
		for(int i=0;i<10;++i){
			cin>>ball[i];
		}
		line1.push_back(ball[9]);
		for(int i=8;i>=0;--i){
			if(line1.back()>ball[i])line1.push_back(ball[i]);
			else if(line2.empty()||line2.back()>ball[i])line2.push_back(ball[i]);
			else {
				cout<<"NO"<<endl;
				goto NO;
			}
		}
		cout<<"YES"<<endl;
NO:;
		line1.clear();
		line2.clear();
	}
	return 0;
}