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++: /*If I get TLE , it is good.If I get AC,it's NICE !*/
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int MAXN=1e7+10;
const ll mod=1e9+7;
using namespace std;
typedef long long ll;
int a[11];

bool judge()
{
    for(int i=2;i<=5;i++)
    {
        if(a[i]<a[i-1]) return false;
    }
    for(int i=7;i<=10;i++)
    {
        if(a[i]<a[i-1]) return false;
    }
    return true;
}

int main(void)
{
    int t;
    cin >> t;
    while(t--)
    {
        int flag=0;
        for(int i=1;i<=10;i++)
            scanf("%d",&a[i]);
        do
        {
            if(judge())
            {
                flag=1;
                break;
            }
        }while(next_permutation(a+1,a+1+10));
        if(flag)    printf("YES\n");
        else    printf("NO\n");
    }
}

C++: #include <iostream>

using namespace std;

bool recursive(int left, int right, int* list, int index)
{
	int next = list[index];

	if(index == 9)
	{
		if(next <= left && next <= right)
			return false;
		return true;
	}

	if(left < next)
		if(recursive(next, right, list, index+1))
			return true;
	if(right < next)
		if(recursive(left, next, list, index+1))
			return true;

	return false;
}

int main()
{
	int n;
	cin >> n;

	while( n-- > 0 )
	{
		int list[10];
		for(auto& n : list)
			cin >> n;

		if( recursive(0, 0, list, 0) )
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}

	return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int a[10];
bool ok = false;

// これから入れるボールのindex，左の筒の一番上のボール，右の筒の一番上のボール
void dfs(int idx, int l, int r) {
  if (idx == 10) {
    ok = true;
    return;
  }
  int val = a[idx];
  if (l < val) dfs(idx + 1, val, r);  // 左の筒に入れる場合
  if (r < val) dfs(idx + 1, l, val);  // 右の筒に入れる場合
}

int main() {
  int n;
  cin >> n;
  REP(i, n) {
    REP(i, 10) cin >> a[i];
    ok = false;
    dfs(0, -1, -1);
    cout << (ok ? "YES" : "NO") << endl;
  }
  return 0;
}

C++: #include <cstdio>

using namespace std;

int a[10];

bool dfs(int i, int l, int r)
{
	if (i == 10) return true;

	if (l < a[i] && dfs(i + 1, a[i], r)) return true;
	if (r < a[i] && dfs(i + 1, l, a[i])) return true;

	return false;
}

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

	while (n--) {
        for (int i = 0; i < 10; ++i) scanf("%d", &a[i]);
        printf("%s\n", (dfs(0, 0, 0) ? "YES" : "NO"));
	}
}

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

int main(){
	int a[10],n,i;
	bool can;
	while(cin >> n && n){
		for(i=0;i<n;i++){
                        can = false;
			for(int j = 0;j<10;j++){
				cin >> a[j];
			}
			for(int j = 1;j<=7;j+=2){
				if(a[j] < a[j+2] && a[j-1] < a[j+1]) can = true;
				else {
					can = false;
					break;
				}
			}
			if(can == true) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,r,n) for(int i=r;i<(int)n;i++)
using namespace std;
int in() {int x; cin >> x; return x;}

int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		bool ans = true;
		int r = -1, l = -2;

		for (int i = 0; i < 10; i++)
		{
			int x;
			cin >> x;
			if (r < l)swap(r, l);

			if (l > x)
			{
				ans = false;
			}

			if(r < x)r=x;
			else l=x;


			if (r < l)swap(r, l);
		}


		if (ans)cout << "YES" << endl;
		else cout << "NO" << endl;
	}


	return 0;

}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <stack>

#define REP(i,n) for(int (i) = 0;(i) < (n) ; ++(i))
#define REPA(a,i,n) for(int (i) = (a) ; (i) < (n) ; ++(i))
#if defined(_MSC_VER)||__cplusplus > 199711L
#define AUTO(r,v) auto r = (v)
#else
#define AUTO(r,v) typeof(v) r = (v)
#endif
#define ALL(c) (c).begin() , (c).end()
#define EACH(it,c) for(AUTO(it,(c).begin());it != (c).end();++it)
#define LL long long 
#define INF  99999999;
#define QUICK_CIN ios::sync_with_stdio(false); cin.tie(0);
using namespace std;

int balls[10];

bool is_b[10];

bool check(){
	int b(-1), c(-1);

	REP(i, 10){
		if (is_b[i]){
			if (b > balls[i])
				return false;
			b = balls[i];
		}
		else{
			if (c > balls[i])
				return false;
			c = balls[i];
		}
	}
	return true;
}

bool DFS(int i){
	if (i == 10)
		return check();

	bool ret(false);

	ret |= DFS(i + 1);

	is_b[i] = true;

	ret |= DFS(i + 1);

	is_b[i] = false;

	return ret;
}

int main(){
	QUICK_CIN;

	int n;
	cin >> n;

	REP(i, n){
		REP(j, 10){
			cin >> balls[j];
		}
		cout << (DFS(0) ? "YES" : "NO") << endl;
		fill(is_b, is_b + 10, false);
	}

	return 0;
}

C++: a

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

int main() {
  int N;
  cin >> N;
  for (int a = 0; a < N; ++a) {
    vector<int> A(10);
    for (int i = 0; i < 10; ++i)
      cin >> A[i];

    bool flag = false;
    for (int bit = 0; bit < 1 << 10; ++bit) {
      vector<int> B1(10), B2(10);
      int B1_size = 0, B2_size = 0;
      for (int i = 0; i < 10; ++i)
        if (bit & 1 << i)
          B1[B1_size] = A[i], ++B1_size;
        else
          B2[B2_size] = A[i], ++B2_size;

      vector<int> B1_s = B1, B2_s = B2;
      sort(B1_s.begin(), B1_s.begin() + B1_size),
          sort(B2_s.begin(), B2_s.begin() + B2_size);

      if (B1 == B1_s && B2 == B2_s)
        flag = true;
    }

    if (flag)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int d[11];
bool ans=false;
bool rec(int i,int a,int b){
  //cout<<"ball["<<i<<"]"<<d[i]<<" a:"<<a<<" b:"<<b<<endl;
  if(10==i)ans=true;
  if(a<d[i]){
    a=d[i];
    rec(i+1,a,b);
  }
  else if(b<d[i]){
    b=d[i];
    rec(i+1,a,b);
  }
  else return false;
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    ans=false;
    for(int j=0;j<10;j++){
      cin>>d[j];
    }
    //    cout<<(rec(0,0,0)?"YES":"No")<<endl;
    rec(0,0,0);

    cout<<(ans?"YES":"NO")<<endl;
  }
  return 0;
}