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++: /*
AOJ 0033 Ball

?¢???????????§??????????????????¢???????§???§?\?????????????A??£?????\???????????????????????????????????????DE?????¶??????B?£???????C?£??????????
??°??????1-10??????????????????????????????A??£?????\???????????????????§???§??¶??????????????\?????\???B?£???????C?£???????????????????????????????????¢????

?????\????¬¬???????????\??°????????°N?????\?????\N??????N???????????°??????????????°?????????10?????´??°?????£??¨???????????\?????????

???????????????????????°????????\?????\?????¨?????????YES?????\????????¨?????????NO
 */
#include <assert.h>
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

#include <algorithm>
#include <complex>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define SZ(a) (int)(a).size()
#define FOR(i,a,b) for (int i=(a); i<=(b); ++i)
#define REP(i,n) for (int i=0; i<(n); ++i)
#define ALL(c) c.begin(), c.end()
#define CLR(c,n) memset(c, n, sizeof(c))
#define TR(it, c) for(typeof(c.begin()) it = c.begin();it != c.end(); ++it)
#define CONTAIN(it, c) (c.find(it) != c.end())
typedef vector<int> VI;
typedef pair<int, int> PII;
template <class T> void checkmin(T &a, T b) { if (b<a) a=b; }
template <class T> void checkmax(T &a, T b) { if (b>a) a=b; }

const int N = 10;
int x[N];

bool go(int idx, int l1, int l2) {
  if (idx == N) return true;
  return (x[idx] > l1 && go(idx+1, x[idx], l2)) ||
      (x[idx] > l2 && go(idx+1, l1, x[idx]));
}

int main(int argc, char *argv[]) {
  int n;
  for (scanf("%d", &n); n; --n) {
    REP(i, 10) scanf("%d", &x[i]);
    puts(go(0, 0, 0)? "YES" : "NO");
  }
}

C++: /*
 * AOJ 0033: Ball
 * ?¢????????????????1-10???10???????????????????????????????????\2????????????????????????????????\??????????????????????¢????????????????????????¨???
 * ?±???????DFS
 * ?????????????????????????????\??§???????????¶???????´????????????\??°?????\????????¶??§????????????
 */

#include <cstdio>
#include <iostream>

using namespace std;

int a[10], b[2][10];
int len[2];
bool ans;


void dfs(int step) {
  if (ans) return;
  if (step == 10) {
    ans = true;
    return;
  }
  for (int i = 0; i < 2; ++i) {
    if (len[i] <= 0 || a[step] > b[i][len[i] - 1]) {
      while(len[i]>=10);
      b[i][len[i]++] = a[step];
      dfs(step + 1);
      --len[i];
    }
  }
}

void solve() {
  ans = false;
  for (int i = 0; i < 10; ++i) {
    cin >> a[i];
  }
  len[0] = len[1] = 0;
  dfs(0);
}

int main() {
  int T;
  cin >> T;
  while (T--) {
    solve();
    cout << (ans ? "YES" : "NO") << endl;
  }
  return 1;
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
int num[20];
bool dfs(int x, int left, int right)
{
    if(num[x] > left)
    {
        if(x == 9)
            return true;
        if(dfs(x + 1, num[x], right))
            return true;
        return false;
    }
    else if(num[x] > right)
    {
        if(x == 9)
            return true;
        if(dfs(x + 1, left, num[x]))
            return true;
        return false;
    }
    return false;
}
int main()
{
    int T, i;
    scanf("%d", &T);
    while(T--)
    {
        for(i = 0; i < 10; i++)
            scanf("%d", &num[i]);
        if(dfs(0, -1<<30, -1<<30))
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

C++: #include<bits/stdc++.h>

using namespace std;
int a[15];
int dfs(int x, int y, int step)
{
    if( step == 11)
       return 1;
    if(x < a[step]) dfs(a[step], y, step+1);
    else if(y < a[step]) dfs(x, a[step], step+1);
  else
    return 0;
}
int main ()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        int i;
        for(i = 1;i <= 10;i++)
            scanf("%d", &a[i]);
        if(dfs(0, 0, 1))
            printf("YES\n");
        else
            printf("NO\n");
    }
}

C++: #include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
#define INF 40
using namespace std;

int ball[12];
int flag ;
stack<int> A, B;


void dfs(int s)
{
	if (s >= 10)
	{
		flag = 1;
		return;
	}
	else if (ball[s] < A.top() && ball[s] < B.top())
	{
		return;
	}
	else {
		if (ball[s] > A.top())
		{
			A.pop();
			A.push(ball[s]);
			dfs(ball[s + 1]);
		}
		if (ball[s] > B.top())
		{
			B.pop();
			B.push(ball[s]);
			dfs(ball[s + 1]);
		}
	}
}


int main()
{
	int n;
	while (~scanf("%d",&n))
	{
		while (n--)
		{
			flag = 0;
			A.push(0);
			B.push(0);
			memset(ball, 0, sizeof(ball));
			for (int i = 0;i < 10;i++)
			{
				scanf("%d", &ball[i]);
			}
			dfs(0);
			if (flag) printf("YES\n");
			else printf("NO\n");
		}
	}
	return 0;
}

C++: #include<cmath>
#include<stack>
#include<cstring>
#include<iostream>
#include<algorithm>
#define SC(x) scanf("%d",&x);
#define pr(x)  cout << x << endl;
#define mem(arr,v) memset(arr,v,sizeof arr);
#define bug(x) cout << "#x = " << x <<endl;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
typedef long long ll;
using namespace std;
int a[20];
stack<int> s1,s2;

bool dfs(int pos){
	if(pos == 10 + 1) return true;
	
	int v = a[pos];
	if(s1.empty() || v >= s1.top()){
		s1.push(v);
		if(dfs(pos + 1)) return true;
		s1.pop();
	}
	if(s2.empty() || v >= s2.top()){
		s2.push(v);
		if(dfs(pos + 1)) return true;
		s2.pop();
	}
	return false;
}

int main(){
//	freopen("in.txt","r",stdin);
	int t;
	cin >> t;
	for(int i = 1 ; i <= t ;++i){
		for(int j = 1; j <= 10 ; j++)
			cin >> a[j];
		while(! s1.empty()) s1.pop();
		while(! s2.empty()) s2.pop();
		
		bool ans = dfs(1);
		if(ans)	puts("YES");
		else	puts("NO");
	}
	
}

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 main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int x,l=0,r=0;
		bool yes=true;
		for(int i=0;i<10;i++)
		{
			scanf("%d",&x);
			if(x<l&&x<r){yes=false;break;}
			if(x<l)r=x;
			else if(x<r)l=x;
			else
			{
				if(x-r<x-l)r=x;
				else l=x;
			}
		}
		if(yes)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}