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 <stack>
#include <vector>
#include <algorithm>
using namespace std;
static const int MAX_N = 10;
int a[MAX_N] = {0};

bool dfs(int a[],vector<int> r,vector<int> l,int i){
	if(i==MAX_N)return true;
	if(r.size()==0 || r[r.size()-1]<a[i]){
		r.push_back(a[i]);
		return dfs(a,r,l,i+1);
	}
	if(l.size()==0 || l[l.size()-1]<a[i]){
		l.push_back(a[i]);
		return dfs(a,r,l,i+1);
	}
	return false;
}


int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){//input
			cin>>a[j];
		}
		vector<int> r;
		vector<int> l;
		if dfs(a,r,l,0){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
}

C++: #include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;

int a[15];
int b[15],c[15];
int flag;
bool dfs(int x)
{
    if(x==10)
    return true;
    	int e,i;
	if(b[0]>c[0])
	{
		e=b[0];
		b[0]=c[0];
		c[0]=e;
	}
	if(a[x]>c[0])
	c[0]=a[x];
	else if(a[x]>b[0])
	b[0]=a[x]; 
	else 
	{
		return false;
	 } 
	dfs(x+1);
	
}
int main()
{
	int n,i,j;
	scanf("%d",&n);
	memset(b,0,sizeof(b));
	memset(c,0,sizeof(c));
	while(n--)
	{
		bool flag=false;
		for(i=0;i<10;i++)
		{
			scanf("%d",&a[i]);
		}
		flag=dfs(0);
		if(!flag) printf("NO\n");
		else printf("YES\n");
	}
}

C++: #include <cassert>
#include <cctype>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <deque>
#include <functional>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#include <fstream>
#include <iostream>
#include <sstream>

#include <iomanip>

using namespace std;

typedef pair<int, int> pint;
typedef vector<int> vint;
typedef long long ll;

#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)

#define NEXTP(c) next_permutation(ALL(c))
#define SUM(c) accumulate(ALL(c),0)
#define MP( a, b ) make_pair( ( a ), ( b ) )

#define DUMP(x)  cerr << #x << " = " << (x) << endl;

#define INF 1000000000 // 10^9
const double EPS = 1e-10;
vector<int> ball;

bool dfs(int i,int left,int right){
    if (i==10) return true;
    
    if (ball[i]>left&&ball[i]>right) {
        return dfs(i+1, ball[i], right)||dfs(i+1, left, ball[i]);
    }else if(ball[i]>left&&ball[i]<right){
        return dfs(i+1, ball[i], right);
    }else if(ball[i]<left&&ball[i]>right){
        return dfs(i+1, left, ball[i]);
    }else{
        return false;
    }
    
}

int main(){
    int N;
    cin>>N;
    REP(i, N){
        ball.clear();
        ball.resize(10);
    
        REP(j, 10)cin>>ball[j];
        
        cout<<(dfs(0,0,0)?"YES":"NO")<<endl;
    }
    return 0;
}

C++: //
// Create by 神舟 on 2015-02-20
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cctype>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <set>
#include <vector>
using namespace std;

#define CLR(x) memset(x,0,sizeof x)
#define ll long long
#define inf 0x3f3f3f3f
const int maxn=1e1+5;
const int MOD=5e5+5;
int num[maxn],n;
bool dfs( int deep, int A, int B)
{
    if(deep==11) return true;
    if(num[deep]>A&&dfs(deep+1,num[deep],B)) return true;
    if(num[deep]>B&&dfs(deep+1,A,num[deep])) return true;
    return false;

}
int main()
{
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(0);

	scanf("%d",&n);
	while(n--){
        CLR(num);
        for(int i=1;i<11;scanf("%d",num+i++));
        if(dfs(1,-inf,-inf)) printf("YES\n");
        else printf("NO\n");
	}
	return 0;
}

C++: #include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>
#include<stack>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	int n,d[10],f;
	stack<int> a,b,*p,*q;
	scanf("%d",&n);
	rep(i,n){
		rep(j,10)scanf("%d",d+9-j);
		while(!a.empty())a.pop();
		while(!b.empty())b.pop();
		a.push(11);
		b.push(11);
		f=0;
		rep(j,10){
			p=a.top()>b.top()?&a:&b;
			q=a.top()<=b.top()?&a:&b;
			if(q->top()>d[j])q->push(d[j]);
			else if(p->top()>d[j])p->push(d[j]);
			else {
				f=1;break;
			}
		}
		puts(f?"NO":"YES");
	}
	return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <stack>
using namespace std;

stack<int> B, C;
int A[10];

bool dfs(int index)
{
  bool ret = false;
  char s[11];

  if (index >= 10) {
    return true;
  }

  for (int i = 0; i < 11; i++) {
    if (i < index) s[i] = '>';
    else s[i] = 0;
  }

  if (B.empty() || B.top() < A[index]) {
    B.push(A[index]);
    // printf("%spush %d into B\n", s, A[index]);
    ret = dfs(index + 1);
    // printf("%s%s. pop %d from B\n", s, ret ? "succeeded" : "failed", A[index]);
    B.pop();
  }
  if (!ret && (C.empty() || C.top() < A[index])) {
    C.push(A[index]);
    // printf("%spush %d into C\n", s, A[index]);
    ret = dfs(index + 1);
    // printf("%s%s. pop %d from C\n", s, ret ? "succeeded" : "failed", A[index]);
    C.pop();
  }

  return ret;
}

bool solve()
{
  while (!B.empty()) B.pop();
  while (!C.empty()) C.pop();

  B.push(A[0]);
  bool ret = dfs(1);
  B.pop();

  return ret;
}

int main()
{
  int N;
  scanf("%d", &N);

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      scanf("%d", A + j);
    }

    if (solve()) {
      printf("Yes\n");
    }
    else {
      printf("No\n");
    }
  }

  return 0;
}

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

int Balls[10];


bool not_dfs(int balls[]){
  int b = 0, c = 0;
  for (int i = 0; i < 10; i++) {
    if (b < balls[i]) continue;
    if (c < balls[i]) continue;
    return false;
  }
  return true;
}

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

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

using namespace std;

int main(void){
	int n;

	cin >> n;
	for(int i=0;i<n;i++){
		int ball;
		stack<int> b,c;
		bool put=true;

		for(int j=0;j<10;j++){
			cin >> ball;
			if(put){
				if(b.empty()||b.top()<ball)
					b.push(ball);
				else if(c.empty()||c.top()<ball)
					c.push(ball);
				else
					put=false;
			}
		}
		cout << (put?"YES":"NO") << endl;
	}
}

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

int ball[10];

int  bunbetu(int i, int left, int right) {
	if (i == 10) {
		cout << "YES" << "\n";
		return 0;
	}
	if (ball[i] < left) {
		if (ball[i] < right) {
			cout << "NO" << "\n";
			return 0;
		}
		bunbetu(i + 1, left, ball[i]);
	}
	else bunbetu(i + 1, ball[i], right);
}

int main() {
	int set;
	cin >> set;
	for (int i = 0; i < set; i++) {
		for (int j = 0; j < 10; j++){
			cin >> ball[j];
		}
		bunbetu(0, 0, 0);
	}
	return 0;
}