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>
using namespace std;
int a[15];
string b,c; 
int main(){
	int n;
	cin>>n;
	while(n--){
		for(int i=0;i<10;i++){
			cin>>a[i];	
		}
		for(int i=0;i<=1024;i++){
			if(i==1024){
				cout<<"NO"<<endl;
				break;
			}
			c.clear();b.clear();
			for(int j=0;j<10;j++){
				if((i>>j)&1){//进c 
					c+=('0'+a[j]);
				}
				else{//进b 
					b+=('0'+a[j]);
				}
			}
			int ok=1;
			for(int j=0;j<b.size()-1;j++){
				if(b[j]>b[j+1]){
					ok=0;
					break;
				}
			}
			for(int j=0;j<c.size()-1;j++){
				if(c[j]>c[j+1]){
					ok=0;
					break;
				}
			}
			if(ok){
				cout<<"YES"<<endl;break;
			}
		}
	}	
	return 0;
}

C++: /*
* Filename:    aoj0033.cpp
* Desciption:  DFS
* Created:     2016-03-02
* Author:      JIngwei Xu [mail:xu_jingwei@outlook.com]
*
*/
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#define INT_MAX 2<<30
using namespace std;
//typedef long long ll;
int a[10],n;
int used[10];
bool ans=false;
bool check(){
	int ss=0;
	for (int i = 0; i < 10; i += 1)
	{
		if(used[i]==0){ss=a[i];break;}
	}
	if(ss==0)return true;
	for (int i = 0; i < 10; i += 1)
	{
		if(used[i]==0){
			if(a[i]<ss)return false;
			else ss=a[i];
		}
	}
	return true;
}
void dfs(int k,int rec){
	if(k==10){
		if(check())ans=true;
		return;
	}
	if(ans)return;
	if(a[k]>rec){
		used[k]=1;
		dfs(k+1,a[k]);
		if(ans)return;
		used[k]=0;
		dfs(k+1,rec);
		if(ans)return;
	}
	else{
		used[k]=0;
		dfs(k+1,rec);
	}
}
int main()
{
	scanf("%d",&n);
	for (int i = 0; i < n; i += 1)
	{
		for (int j = 0; j < 10; j += 1)
		{
			scanf("%d",&a[j]);
		}
		ans=false;
		for (int i = 0; i < 10; i += 1)
		{
			memset(used,0,sizeof(used));
			used[i]=1;
			dfs(i+1,a[i]);
			if(ans)break;
		}
		
		
		if(ans)printf("YES");
		else printf("NO");
		
	}
	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<string>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
int flag,a[11],vis[11];
void bfs(){
	queue<int>q;queue<int>p;
	q.push(a[0]);
	p.push(a[1]);
	int i=2;
	while(i<10){
		int t1=q.front(),t2=p.front();
		if(!q.empty())q.pop();if(!p.empty())p.pop();
		if(a[i]<t1&&a[i]<t2){
			flag=0;
			break;
		}
		 if(a[i]>=t1){
			q.push(a[i]);
			i++;
		}
		 if(a[i]>=t2){
			p.push(a[i]);
			i++;
		}
	}
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--){
		flag=1;
		for(int i=0;i<10;i++)
		scanf("%d",&a[i]);
		bfs();
		if(flag)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++: /*
*
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#define CLR(ARR,NUM) memset(ARR,NUM,sizeof(ARR))
#define GETNUM(NUM) scanf("%d",&NUM)
#define faster_io() ios_base::sync_with_stdio(false)
using namespace std;
const int MAXN = 20;
int a[MAXN];
bool vaild;
void dfs(int x,int l,int r)
{
	if(x==10){
		vaild=true;
		return;
	}
	if(a[x]>l){
		dfs(x+1,a[x],r);
	}
	if(a[x]>r){
		dfs(x+1,l,a[x]);
	}
}

int main()
{
	int n;
	cin >> n;
	while(n--){
		for(int i=0;i<10;i++){
			GETNUM(a[i]);
		}
		vaild=false;
		dfs(0,0,0);
		if(vaild){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
 
using namespace std;
 
int a[10];
bool flag;
 
void dfs(int n, int l, int r)
{
    if (n == 10) {
        flag = true;
        return ;
    }
 
    if (a[n] > l)
        dfs(n + 1, a[n], r);
    if (a[n] > r)
        dfs(n + 1, l, a[n]);
 
    return ;
}
 
int main()
{
    int n;
 
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++)
            cin >> a[j];
 
        flag = false;
        dfs(0, 0, 0);
        if (flag)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
 
    return 0;
}

C++: #include<algorithm>
#include<iostream>
#include<cstring>
#include<climits>
#include<cstdio>
using namespace std;
int T,a[15],isac;
void dfs(int num,int left,int right)
{
    if(num==11){isac=1;return ;}
    if(a[num]>left)dfs(num+1,a[num],right);
    if(a[num]>right)dfs(num+1,left,a[num]);
}
int main()
{
    scanf("%d",&T);
    while(T--)
    {
        isac=0;
        for(int i=1;i<=10;i++)scanf("%d",&a[i]);
        dfs(1,0,0);
        if(isac)printf("YES\n");
        else printf("NO\n");
    }
}

C++: #include<iostream>
int box[10];
int ltop = -1, rtop = -1;
bool ball(int i, int left, int right){
	if (i == 10)return true;
	if (left<box[i])return ball(i + 1, box[i], right);
	if (right<box[i])return ball(i + 1, left, box[i]);
	if (left>box[i] && right>box[i])return false;
}
int main(){
	int n;
	std::cin >> n;
	for (int what = 0; what<n; ++what){
		for (int i = 0; i<10; ++i){
			std::cin >> box[i];
		}
		if (ball(0, ltop, rtop))std::cout << "YES\n";
		else std::cout << "NO\n";
		ltop = -1;
		rtop = -1;
	}
}

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

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    vector<int> v(10);
    for (int j = 0; j < 10; j++) {
      cin >> v.at(j);
    }
    sort(v.begin(), v.begin() + 2);
    int a = v.at(0), b = v.at(1);
    bool flag = true;
    for (int k = 2; k <= 10; k++) {
      if (v.at(k) > a) {
        if (v.at(k) < b) {
          a = v.at(k);
        } else {
          b = v.at(k);
        }
      } else {
        flag = false;
      }
    }
    if (flag)
    cout << "YES" << endl;
    else
    cout << "NO" << endl;
  }
}

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