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 <queue>
#include <utility>
using namespace std;

int main()
{
	int n, ball;
	queue<pair<int, int> > qu;

	cin >> n;

	for (int i=0; i<n; i++){
		bool flag = false;
		int rem;

		cin >> ball;
		qu.push(make_pair(ball, 0));

		for (int j=0; j<9; j++){
			cin >> ball;

			while (!qu.empty() && ball != qu.front().first && ball != qu.front().second)
			{
				if(qu.front().first < ball){
					qu.push(make_pair(ball, qu.front().second));
					//cout << ball << ',' << qu.front().second << ' ';	//debug
				}
				else if(qu.front().second < ball){
					qu.push(make_pair(qu.front().first, ball));
					//cout << qu.front().first << ',' << ball;	//debug
				}

				//cout << endl; //debug
				
				qu.pop();
				//if(qu.empty())	break;
			}

			if(qu.empty()){
				rem = j+1;
				break;
			}
			if(j==8 && !qu.empty()){
				rem = 9;
				flag = true;
			}
		}

		for(; rem < 9; rem++)	cin >> ball;

		if(flag)	cout << "YES" << endl;
		else		cout << "NO" << endl;
		
		while (!qu.empty()) qu.pop();
	}

	return 0;
}

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

signed main(void)
{
  stack<int> b, c;
  int n;
  int B, C = 0;

  cin >> n;

  for (int j = 0; j < n; j++){
    bool frag = true;
    int a[10];
    for (int k = 0; k < 10; k++) cin >> a[k];
   
    for (int i = 0; i < 10; i++){
      if (i == 0) {
        B = a[i];
        b.push(a[i]);
      }
      else if (B > a[i] && C < a[i]) {
        C = a[i];
        c.push(a[i]);
      }
      else if (B < a[i]) {
        B = a[i];
        b.push(a[i]);
      }
      else {
        frag = false;
        break;
      }
    }
    if (frag) puts("YES");
    else puts("NO");
  }

  return 0;
}

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

int main() {
	int n, balls[10]; cin >> n;
    while(n--){
        for(int i = 0; i < 10; i++){
            cin >> balls[i];
        }
        
        bool sortable = false;
        stack<tuple<int, int, int> > states;
        
        states.push(make_tuple(0,0,0));
        while(!states.empty()){
        	tuple<int, int, int> now = states.top();
        	states.pop();
        	
        	int idx = get<0>(now);
        	if(idx < 9){
        		if(get<1>(now) < balls[idx]){
        			if(idx + 1 == 9){
        				sortable = true; break;
        			}
        			states.push(make_tuple(idx+1,balls[idx],get<2>(now)));
        		}
        		if(get<2>(now) < balls[idx]){
        			if(idx + 1 == 9){
        				sortable = true; break;
        			}
        			states.push(make_tuple(idx+1,get<1>(now),balls[idx]));
        		}
        	}        	
        }
         
        if(sortable) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

C++: #include <iostream>
using namespace std;
int main(void){
  int n;
  cin>>n;
  while(n--){
    int ans=1;
    for(int i=0,a,p=0,q=0;i<10;++i){
      cin>>a;
      if(ans){
	      if(p>=a&&q>=a) ans=0;
	      else{
	      	if(p>q) (p<a)?p=a:q=a;
	      	else (q<a)?q=a:p=a;
	      }
      }
    }
    cout<<(ans?"YES":"NO")<<endl;
  }
  return 0;
}

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

using namespace std;

#define N 10

int main(){
  int tc; //test case
  cin >> tc;

  while(tc-->0){
    //maximun 1024 pattern. try all

    int n[10];
    for(int i=0; i<N; i++){ scanf("%d", &n[i]); }

    int b, c; //tube
    bool ans = false;
    for(int i=0; i<(1<<N); i++){
      int bit=i; b=c=0;
      for(int j=0; j<N; j++){
	if(bit%2==0){ // to B
	  if(b < n[j]) b=n[j];
	  else break;
	} else { // to C
	  if(c < n[j]) c=n[j];
	  else break;
	}
	if(j==N-1){
	  ans=true;
	  goto OUT;
	}
	bit /= 2;
      }
    }

  OUT:
    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;

  }
}

C++: #include<iostream>


using namespace std;

int data[11],N;
int a[11],b[11];
int na,nb;

bool dfs(int a[],int b[],int k)
{
	if(k==11)
	  return true;
	if(data[k]>a[na])
	{
		na++;
		a[na] = data[k];
		
		if(dfs(a,b,k+1))
		 return true;
		a[na] = 0;
		na--;
	}
	if(data[k]>b[nb])
	{
		nb++;
		b[nb] = data[k];
	    if(dfs(a,b,k+1))
	     return true;
		b[nb]=0;
		nb--;
	}
	
	return false;
	
}
int main()
{
	cin>>N;
	int time=1;
	while(time++<=N)
	{
		for(int i=1;i<=10;i++)
		{
		cin>>data[i];
		a[i]=0;
		b[i]=0;
		}
		na = nb = 0;
		
		if(dfs(a,b,1)==true)
		cout<<"YES"<<endl;
		else
		 cout<<"NO"<<endl;
	}
}

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

using namespace std;

bool flag = true;

void IsSplitable(queue<int> num, queue<int> left, queue<int> right) {
	if (num.size() > 0) {
		if (left.size() > 0) {
			if (num.front() > left.back()) {
				left.push(num.front());
				num.pop();
				IsSplitable(num, left, right);
			}
			else {
				if (right.size() > 0) {
					if (num.front() > right.back()) {
						right.push(num.front());
						num.pop();
						IsSplitable(num, left, right);
					}
					else {
						flag = false;
					}
				}
				else {
					right.push(num.front());
					num.pop();
					IsSplitable(num, left, right);
				}
			}
		}
		else {
			left.push(num.front());
			num.pop();
			IsSplitable(num, left, right);
		}
	}
}

int main() {
	int Indexnum;
	
	cin >> Indexnum;
	//getchar();
	for (size_t in = 0; in != Indexnum; ++in) {
		
		queue<int> number;
		queue<int> left;
		queue<int> right;
		for (size_t i = 0; i < 10; ++i) {
			int temp;
			cin >> temp;
			number.push(temp);
		}

		IsSplitable(number, left, right);

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

	return 0;
}