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++: #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
using namespace std;

#define TEST 0
#if TEST
FILE *in = freopen("./q", "r", stdin);
FILE *out = freopen("./ans", "w", stdout);
#endif

int main(){
	int n; cin >> n;
	while (n--){
		int balls[10];
		for (int i = 0; i < 10; i++){
			cin >> balls[i];
		}

		int left = 0, right = 0;
		bool ok = true;
		for (int i = 0; i < 10; i++){
			int dleft = balls[i] - left;
			int dright = balls[i] - right;

			if (dleft <= 0 && dright <= 0){
				ok = false;
				break;
			}

			if (dleft <= 0){
				right = balls[i];
			}
			else if (dright <= 0){
				left = balls[i];
			}
			else if (dleft < dright){
				left = balls[i];
			}
			else{
				right = balls[i];
			}
		}

		cout << (ok ? "YES": "NO") << endl;

	}
	

#if TEST
	fclose(in);
	fclose(out);
#endif
}

C++: #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

int main(){
    int n,b,B=0,C=0;
    
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        B=0;C=0;
        for(int j=0;j<10;j++){
            scanf("%d",&b);
            if(min(B,C)<b){
                if((B>C && B<b) || C>b)B=b;
                else C=b;
            }else{
                B=11;C=11;
            }
        }
        if(B==10 || C==10)
            puts("YES");
        else
            puts("NO");
    }
    return 0;
}

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

using namespace std;

bool Solution()
{
    int n;
    
    int left = 0;
    int right = 0;
    
    int a[10];
    
    cin>>n;
    
    where(n--)
    {
        for (int i = 0; i < 10; i++)
        {
            cin>>a[i];
        }
        
        for (int i = 0; i < 10; i++)
        {
            if (a[i] > left) // at the beginning, compare with first ball and the ball before first ball (empty)
            {
                left = a[i];
            }
            else if (a[i] > right)
            {
                right = a[i];
            }
            else                 //when can not enter to the both bottles to the end, then return false
            {
                return false;
            }
        }
        
        return true;
    }
}

int main()
{
   if (Solution())
   {
       cout<<"YES"<<endl;
   }
   else
   {
        cout<<"NO"<<endl;
   }
    
    return 0;
}

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

int main(){
  int n;
  
  cin >> n;
  for(int j = 0 ; j < n ; j++){ 

    int ball[10]={0},left[5]={0},right[5]={0};
    int lmax=0,rmax=0,lcnt=0,rcnt=0,lc=0,rc=0;
    
    for( int i = 0 ; i < 10 ; i++ ){
      cin >> ball[i];
      
      if(i % 2 == 0) left[lc++] = ball[i];
      else right[rc++] = ball[i];
      
      if( lmax < left[lc-1] ){
	lmax = left[lc-1];
	lcnt++;
      }   
      
      if( rmax < right[rc-1] ){
	rmax = right[rc-1];
	rcnt++;
      }
     
    }
    if( lcnt == 5 && rcnt == 5 ) cout << "YES" << endl;
    else cout << "NO" << endl;
  } 
  return 0;
}

C++: #include<iostream>
#include<queue>
using namespace std;
int main (){
	int n;
	cin>>n;
	queue <int > p,q;
	int a[10];
	while(n--){
		for (int i=0;i<10;i++){
			cin>>a[i];
			if(!i) p.push(a[i]);
			if(a[i]<p.back()) q.push(a[i]);
			else p.push(a[i]);
		}
		int t=q.front(),k=0;
		q.pop();
		while(!q.empty()){
			if(t>q.front()){
				k=1;
				break;
			}else {
				q.pop();
			}
		}
		if(k) cout<<"NO"<<endl;
		else cout<<"YES"<<endl; 
	}
}

C++: #include <cstdio>

using namespace std;
#define INF 1000000000

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

  for (int i = 0; i < N; ++i) {
    int B = 0, C = 0;
    bool ans = true;
    for (int j = 0; j < 10; ++j) {
      int A;
      scanf("%d", &A);
      int diffB = INF, diffC = INF;
      if (A > B) diffB = A - B;
      if (A > C) diffC = A - C;
      if (diffB == INF && diffC == INF) ans = false;
      if (diffB < diffC) B = A;
      else C = A;
    }
    if (ans) puts("YES");
    else puts("NO");
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,a;
  int f = 0;
  int b = 0 ,c = 0;
  cin >> n;
  while(n--){
    for(int i = 0;i < 10;i++){
      cin >> a;
      if(b < a)b = a;
      else if(c < a)c = a;
      else {
	f = 1;	
      }  
    }
    if(f == 1)cout << "NO" << endl;
    else cout << "YES" << endl;
  }
  return 0;
}

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

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); i++)
#define loops(i,f,n) for(int i = (f); i < (n); i++)
#define INF 100000000
typedef pair<int, int> pii;

vector<int> A(10);
bool ans = false;
void dfs(int a, int b, int cnt)
{
	if (cnt == 9)
	{
		if (a < A[cnt])ans = true;
		if (b < A[cnt])ans = true;
		return;
	}
	if (A[cnt] > a)dfs(A[cnt], b, cnt + 1);
	if (A[cnt] > b)dfs(a, A[cnt], cnt + 1);
	if (A[cnt] < a && A[cnt] < b)return;
}

int main()
{
	int n;
	cin >> n;
	loop(k, n)
	{
		loop(i, 10)
		{
			cin >> A[i];
		}
		ans = false;
		dfs(0, 0, 0);
		cout << (ans ? "YES" : "NO") << endl;
	}
	return 0;
}

C++: //
//  main.cpp
//

#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
#include <limits>
#include <math.h>
#include <queue>
#include <tuple>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <memory>

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0033

using namespace std;

// #define TEST

#ifdef TEST
static const string g_SAMPLE = R"(2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 11)";
static FILE* g_IN_FP;
static const char* g_IN_FN = "in.txt";
#define scanf(...) fscanf(g_IN_FP, __VA_ARGS__)
#endif // TEST

int main() {
#ifdef TEST
    g_IN_FP = fopen(g_IN_FN, "w");
    fwrite(g_SAMPLE.c_str(), 1, g_SAMPLE.size(), g_IN_FP);
    fclose(g_IN_FP);
    g_IN_FP = fopen(g_IN_FN, "r");
#endif // TEST
    int N;
    scanf("%d", &N);
    for (int n = 0; n < N; n++) {
        vector<int> balls;
        for (int i = 0; i < 10; i++) {
            int ball;
            scanf("%d", &ball);
            balls.push_back(ball);
        }
        bool foundGoodBits = false;
        for (int bits = 0; bits < (1 << 10); bits++) {
            if (bits > (~bits & ((1 << 10) - 1))) {
                continue;
            }
            function<bool(int)> isGoodBits = [&balls](int bits) -> bool {
                int zeroTop = 0;
                int oneTop = 0;
                for (int bit = 0; bit < 10; bit++) {
                    int* topPtr = (bits & (1 << bit)) != 0 ? &oneTop : &zeroTop;
                    if (balls[bit] <= *topPtr) {
                        return false;
                    } else {
                        *topPtr = balls[bit];
                    }
                }
                return true;
            };
            if (isGoodBits(bits)) {
                foundGoodBits = true;
                break;
            }
        }
        if (foundGoodBits) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
    return 0;
}