Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	for i := 0; i < n; i++ {
		a := -1
		b := -1
		ans := true
		// それぞれの筒の一番上にあるたまの数字に着目すればよい
		for j := 0; j < 10; j++ {
			x := nextInt()
			if x > a {
				a = x
			} else if x > b {
				b = x
			} else {
				ans = false
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <string.h>
#include <set>
#include <queue>
#include <cmath>
#include <algorithm>

using namespace std;

bool check(vector<int> v)
{
	if (v.size() == 0 || v.size() == 1)
		return true;
	else
	{
		for (int i = 0;i < v.size() - 1;i ++)
		{
			if (v[i] > v[i + 1])
				return false;
		}
		return true;
	}
}

int input[20];

int main()
{
	int i , j , mask , n;
	while (scanf("%d" , &n) != EOF)
	{
		for (i = 0;i < n;i ++)
		{
			bool ok = false;

			for (j = 0;j < 10;j ++)
				scanf("%d" , &input[j]);

			for (mask = 0;mask < (1 << 10);mask ++)
			{
				vector<int> v1 , v2;
				for (j = 0;j < 10;j ++)
				{
					if (mask & (1 << j))
						v1.push_back(input[j]);
					else
						v2.push_back(input[j]);
				}
				if (check(v1) && check(v2))
				{
					ok = true;
					break;
				}
			}

			if (ok)
				printf("YES\n");
			else
				printf("NO\n");
		}
	}
	return 0;
}

C++: #include <stdio.h>
int a[10];
int dfs(int l,int r,int i){
  if(i==10)return 1;
  if(a[i]>l&&dfs(a[i],r,i+1))return 1;
  if(a[i]>r&&dfs(l,a[i],i+1))return 1;
  return 0;
}
int main(){
  int n;
  scanf("%d",&n);
  for(;n;n--){
    scanf("%d %d %d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);
    dfs(0,0,0)?printf("YES\n"):printf("NO\n");
  }
  return 0;
}

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;
}