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<cstdio>

using namespace std;


//引数はそれぞれ、入力配列のカウント変数、a[]のカウント変数,b[]のカウント変数,答え配列,筒を意味するaとb配列,成功判定flg変数
bool tansaku(int count,int n1,int n2,int ans[],int a[],int b[],bool flg)
{
	//カウントが１０になったときは成功したとき
	if (count == 10)
	{
		return true;
	}
	//既にflgがtrueならさっさと返す
	if (flg == false)
	{
		//最初はn1は１である
		if (a[n1] < ans[count])		//１つ前の要素と比べている
		{
			//a[n1]にans[count]を格納
			//最初に足しておくと動作が正しくなる
			n1++;					
			//答えを格納
			a[n1] = ans[count];
			//入力された配列に使うカウント変数
			count++;
			//再帰関数
			bool hozon = tansaku(count,n1,n2,ans,a,b,flg);
			//trueだった場合falseで上書きしないように調整
			if (hozon == true)
			{
				flg = true;
			}
		}
		//ひとつ前の要素と比べている
		if (b[n2] < ans[count])
		{
			//先に足す
			n2++;
			//b[n2](最初はn2 = 1)に小さい順に入れていく
			b[n2] = ans[count];
			//関数の前でインクリメント
			count++;
			//再帰関数
			bool hozon = tansaku(count,n1,n2,ans,a,b,flg);
			//trueだった場合上書きしないようにする
			if (hozon == true)
			{
				flg = true;
			}
		}
	}

	return flg;
}


int main(void)
{
	//何回回すか
	int n = 0;
	//10個のボール
	int a[10] = {0};
	//関数で送るためのいらない変数
	int damy[20] = {0};
	bool ans_flg[100] = {false};

	scanf("%d",&n);
	//n回文の入力
	for (int i = 0;i < n;i++)
	{
		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]);
		if (tansaku(0,0,0,a,damy,damy,false) == true)
		{
			ans_flg[i] = true;
		}
	}

	for (int i = 0;i < n;i++)
	{
		if (ans_flg[i] == true)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}

	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>
#include <utility>
#include <list>
#include <cmath>
#include <unordered_map>

using namespace std;

typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;

const int INF = 1 << 29;
const LL MOD = 100000;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(), (c).end()

struct edge{ int to, cost; edge(int t, int c) :to(t), cost(c){} };

int main()
{
	//while (cin >> n)
	stringstream ss;
	//ss << "result" << i + 1 << ".txt";
	//FILE* fp_out = freopen(ss.str().c_str(), "w", stdout);

	int n;
	while (cin >> n)
	{
		rep(k, n)
		{
			vector<int> balls(10);
			rep(i, 10) cin >> balls[i];
			function<bool(int, int, int)> dfs = [&](int left, int right, int idx)
			{
				if (idx == 10) return true;
				int x = balls[idx];
				return (left < x && dfs(x, right, idx + 1)) ||
					(right < x && dfs(left, x, idx + 1));
			};

			cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
		}
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int ball,bal,n,a,flg;
  cin>>n;
  for(int i=0;i<n;i++){
    flg=0;
    ball=0;
    bal=0;
    for(int k=0;k<10;k++){
      cin>>a;
      if(ball<a){
	ball=a;
      }else if(bal<a){
	bal=a;
      }else{
	flg=1;
      }
    }
    if(flg==0){
      cout<<"YES"<<endl;
    }if(flg==1){
      cout<<"NO"<<endl;
    }
  }
  return 0;
}

C++: // Aoj 0033: Ball
#include<bits/stdc++.h>
#define mset(x,y) memset(x,y,sizeof(x))
using namespace std;

const int N=110,M=20010;
int h[N],to[M],nexp[M],p=1;
inline void init_list(){mset(h,0),mset(nexp,0),p=1;}
inline void ins(int a,int b){
    nexp[p]=h[a],h[a]=p,to[p]=b,p++;
}
int arr[N];
int col[N];
bool imp;
void dfs(int x,int ncol){
    col[x]=ncol;
    for(int u=h[x];u;u=nexp[u]){
        if(col[to[u]] == col[x]) imp=1;
        if(imp) return;
        if(!col[to[u]]) dfs(to[u],ncol^1);
    }
}

int main(){
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--){
        for(int i=0;i<10;i++) cin>>arr[i];
        init_list();
        for(int i=0;i<10;i++)
        for(int j=i+1;j<10;j++)
            if(arr[i]>arr[j]) ins(i,j),ins(j,i);
        mset(col,0), imp=0;
        for(int i=0;i<10;i++)
            if(!col[i]) dfs(i,2);
        if(imp) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

bool
f(vector<int>&ln, int idx, int x, int y) {
  if (idx == 10) return true;
  int z = ln[idx];
  return (x < z && f(ln, idx + 1, z, y)) || (y < z && f(ln, idx + 1, x, z));
}

int main() {

  int n; cin >> n;
  for (;n--;) {
    vector<int> ln(10);
    rep (i, 10) cin >> ln[i];
    bool bl = f(ln, 0, 0, 0);
    cout << (bl ? "YES" : "NO" ) <<endl;
  }

  return 0;
}

C++: //#define LOCAL 

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>

#define SIZE 10

using namespace std;

int map[SIZE];

bool dfs(int a, int b, int pos){
	//printf("a: %d b: %d pos: %d\n", a, b, pos);

	if(pos == SIZE)
		return true;

	if(map[pos] > a)
		return dfs(map[pos], b, pos + 1);

	if(map[pos] > b)
		return dfs(a, map[pos], pos + 1);

	return false;
}

int main(void){
#ifdef LOCAL
	freopen("data.in", "r", stdin);
#endif 
	int n;
	
	scanf("%d", &n);
	while(n--){
		for(int i = 0; i < SIZE; i++){
			scanf("%d", &map[i]);
	//		printf("%d ", map[i]);
		}
	//	printf("\n");

		if(dfs(0, 0, 0))
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}

C++: #include <cstdio>

int a[10];


int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    bool ans = true;
    for (int i = 0; i < 10; ++i) {
      scanf("%d", &a[i]);
    }
    int l, r;
    l = r = 0;
    for (int i = 0; i < 10; ++i) {
      if (a[i] > l) {
        l = a[i];
      } else if (a[i] > r) {
        r = a[i];
      } else {
        ans = false;
        break;
      }
    }
    printf("%s\n", ans ? "YES" : "NO");
  }
  return 0;
}

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

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		int b[10];
		int left = 0, right = 0;
		bool avail = true;
		for (int j = 0; j < 10; j++)
			cin >> b[j];
		for (int j = 0; j < 10; j++) {
			if (b[j] > left) left = b[j];
			else if (b[j] > right) right = b[j];
			else avail = false;
		}
		cout << (avail ? "YES" : "NO") << endl;
	}
	return 0;
}