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<stdio.h>
int main(void)
{
	int n,i,sum,t,aaa,bbb,nnn;
	char ch,a[10000];
	scanf("%d",&n);
	getchar();
	while(n--)
	{
		t=0;i=0;
		sum=0;aaa=0;bbb=0;
		while((ch=getchar())!='\n')
			a[i++]=ch;
		nnn=i;
		for(i=0;i<nnn;i++)
		{
			if(a[i]>='1'&&a[i]<='9')
			{
				if(a[i+1]=='0')
					sum=10,i++;
				else
					sum=a[i]-'0';
				if(aaa==0)
					aaa=sum;
				else
				{
					if(aaa<sum&&bbb<sum)
						t=1;
					if(aaa>sum)
						bbb=sum;
					else
					{
						if(bbb>sum)
							aaa=sum;
						else
						{
							if(aaa>bbb)
								aaa=sum;
							else
								bbb=sum;
						}
					 } 
				}
			}
			
		}
		if(t==1)
			printf("YES\n");
		else
			printf("NO\n");
	}
}

C++: #include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

#define REP(i,n) for ( int i = 0; i < (int)n; i++ )
#define FOR(i,c) for ( __typeof((c).begin())i=(c).begin(); i != (c).end(); i++ )
#define ALL(c) (c).begin(), (c).end()

typedef vector <int> VI;
int a, b;

bool solve( VI L, int d ) {
  if ( d >= (int)L.size() ) {
    return true;
  }
  int ba = a;
  int bb = b;
  if ( L[d] > a ) {
    a = L[d];
    if ( solve( L, d + 1 ) ) return true;
    a = ba;
  }
  if ( L[d] > b ) {
    b = L[d];
    if ( solve( L, d + 1 ) ) return true;
    b = bb;
  }
  return false;
}

int main() {
  int n;
  while ( cin >> n ) {
    for ( int i = 0; i < n; ++ i ) {
      VI L( 10 );
      for ( int j = 0; j < 10; ++ j ) {
	cin >> L[j];
      }
      a = 0;
      b = 0;
      cout << ( solve( L, 0 ) ? "YES" : "NO" ) << endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main(){
  int N;
  cin >> N;
  int boll[10];
  stack<int> B,C;
  for(int i=0;i<N;i++){
    B.push(0); C.push(0);
    for(int j=0;j<10;j++) cin >> boll[j];
    for(int j=0;j<10;j++){
        if(boll[j]>B.top()) B.push(boll[j]);
        else if(boll[j]>C.top()) C.push(boll[j]);
        else{
          cout << "NO" << endl;
          break;
        }
        if(j==9) cout << "YES" << endl;
    }
  }
  return 0;
}

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

int a[10];

bool dfs(int id, int l_last, int r_last){
	if (id == 10)
		return true;
	if (a[id] > l_last && dfs(id + 1, a[id], r_last))
		return true;
	if (a[id] > r_last && dfs(id + 1, l_last, a[id]))
		return true;
	return false;
}

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

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i){
		for (int j = 0; j < 10; ++j)
			cin >> a[j];
		solve();
	}
	return 0;
}