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>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
using namespace std;
int a[11];
int a1[11];
int pn=0;
int Flag;
void dfs(int i)
{
    if(Flag==1)
        return;

    if(a[i]>a[a1[pn]])
    {
        a1[++pn]=i;
        for(int m=i+1;m<=10;m++)
        {
            dfs(m);
        }
    }
    else
        return;
    int flag=0;
    for(int m=i+1;m<=10;m++)
    {
        if(a[m]>a[i])
            flag=1;
    }
    int flag2;
    if(flag==0||i==10)
    {
        int a2[11];
        int pm=0;
        for(int n=1;n<=10;n++)
        {
            flag2=0;
            for(int m=1;m<=pn;m++)
            {
                if(n==a1[m])
                   flag2=1;
            }
            if(!flag2)
            {
               a2[++pm]=n;
            }
        }
        int flag3=0;
        for(int m=1;m<pm;m++)
        {
            if(a[a2[m]]>a[a2[m+1]])
                flag3=1;
        }
        if(flag3==0)
        {
            Flag=1;
            return;
        }
        else
        {
            pn--;
            return;
        }
    }

}
int main()
{
    int n;
    //freopen("C:\\Users\\ibm\\Desktop\\456.txt","r",stdin);
    scanf("%d",&n);
    getchar();
    a[0]=-1;
    a1[0]=0;
    for(int i=1;i<=n;i++)
    {
        Flag=0;
        for(int j=1;j<=10;j++)
        {
            scanf("%d ",&a[j]);
        }
        dfs(1);
        if(Flag==0)
        {
            printf("NO\n");
        }
        else
            printf("YES\n");
    }
    return 0;
}

C++: #include "stdio.h"
#include "stdlib.h"
#include "iostream"
#include "math.h"
#include <string.h>


using namespace std;
#define fori0(G) for(int i=0;i<G;i++)
#define fori1(G) for(int i=1;i<=G;i++)
#define forj0(G) for(int j=0;j<G;j++)
#define forj1(G) for(int j=1;j<=G;j++)
#define fork0(G) for(int k=0;k<G;k++)
#define fork1(G) for(int k=1;k<=G;k++)



int main() {
	int n, ba[13],p=11,q=11,r=0;
	cin >> n;
	fork0(n) {
		p = 11;q = 11;r = 0;
		ba[11] = -1;

		fori0(10) { cin >> ba[i]; }
		fori0(1023) {
			p = 11;q = 11;
			forj0(10) {
				//printf("%d,%d", p, q);
				if (i&(int)pow(2, j)) { if (ba[p] > ba[j]) { break; } else { p = j; } }
				else { if (ba[q] > ba[j]) { break; } else { q = j; } }
				if (j == 9) { r = 1; }

			}
		}
		if (r) { printf("YES\n"); }
		else { printf("NO\n"); }
	}
	//system("pause");
	return 0;
}

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

int main() {
	int n;
	int a;
	vector<int>d;
	vector<int>va;
	vector<int>vb;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> a;
			d.push_back(a);
		}
		va.push_back(d[0]);		

		for (int j = 1; j < 10; j++) {
			int b = va.size();
			int c = vb.size();

			if (d[j] > va[b-1]) {
				va.push_back(d[j]);
			}
			else if (d[j] > vb[c-1]) {
				vb.push_back(d[j]);
			}
			else {
				cout << "NO" << endl; 
				goto FINLOOP;
			}
		}
		cout << "YES" << endl;
			FINLOOP:
		;
	}
	return 0;
}

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

using namespace std;

int ball[10];

bool dfs(int B, int C, int cnt){
    if(cnt == 10){
        return true;
    }
    if(B < ball[cnt]){
        return dfs(ball[cnt], C, cnt + 1);
    }
    if(C < ball[cnt]){
        return dfs(B, ball[cnt], cnt + 1);
    }
    if(B > ball[cnt] && C > ball[cnt]){
        return false;
    }
}

int main()
{
    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 10; j++)
            cin >> ball[i];

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

C++: #include <cstdio>
using namespace std;
int main(void)
{
  int a,b,ball[10],n,i,flag;
  scanf("%d",&n);
  while(n-->0)
  {
    a=-1;b=-1;
    for(i=0;i<9;i++)
      scanf("%d",&ball[i]);
    for(i=0;i<9;i++)
    {
      flag=0;
      if(ball[i]>a)
        flag=1;

      if(ball[i]>b)
      {
        if(flag==1)
        {
          if(ball[i]-a<ball[i]-b)
            a=ball[i];
          else
            b=ball[i];
        }else{
          b=ball[i];
        }
        flag=2;
      }
      if(flag==0)
      {
        printf("NO\n");
        break;
      }
      if(flag==1)
        a=ball[i];
    }
    if(flag!=0)
      printf("YES\n");
  }
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "iostream"
#include "cstdio"
using namespace std;

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

int hantei(int left,int right,int *ball,int i){
	if (i == 10)return 1;
	int OK = 0;
	if (left < ball[i])OK=hantei(ball[i], right, ball, i + 1);
	if (right < ball[i])OK=hantei(left, ball[i], ball, i + 1);
	return OK;
}

int main(){

	int n,ball[10],left=0,right=0,FLAG=2;
	cin >> n;
	while (n--){
		int i = 0;
		for (auto&& x : ball)cin >> x;
		if (hantei(left, right, ball, i))cout << "YES" << endl;
		else cout << "NO" << endl;

	}

#if TEST
	fclose(in);
	fclose(out);
#endif
	return 0;

}

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

int balls[20];
int R, L;

bool dfs(int n) {
  if (n == 10) {
    return true;
  }
  if (R < balls[n]) {
    R = balls[n];
    if (dfs(n+1)) {
      return true;
    }
  }
  if (L < balls[n]) {
    L = balls[n];
    if (dfs(n+1)) {
      return true;
    }
  }
  return false;
}

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

    if (dfs(1)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }

  return 0;
}

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

int n,len,ball[20],used[20];

int f()
{
	int t = -1;
	for (int i=1;i<=10;++i)
		if (!used[i])
		{
			if (ball[i] < t) return 0;
			t = ball[i];
		}
	t = -1;
	for (int i=1;i<=10;++i)
		if (used[i])
		{
			if (ball[i] < t) return 0;
			t = ball[i];	
		}
	return 1;
}

int dfs(int x,int l)
{
	if (l == len) return f();
	for (int i=x+1;i<=10;++i)
		if (!used[i])
		{
			used[i] = 1;
			if (dfs(i,l+1)) return 1;
			used[i] = 0;
		}
	return 0;
}

int main()
{
//	freopen("in.txt","r",stdin);
	cin>>n; 
	while (n--)
	{
		int flag = 0;
		for (int i=1;i<=10;++i) cin>>ball[i];
		for (int i=0;i<=5;++i)
		{
			memset(used,0,sizeof(used));
			len = i;
			if (dfs(0,0)) 
			{
				flag = 1;
				break;
			}
		}
		if (flag) cout<<"YES";
		else cout<<"NO";
		cout<<'\n';
	}
	return 0;
}

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

int main() {
	int n, x;
	cin >> n;
	for (int lop = 0, a = 0, b = 0; lop < n; lop++) {
		bool f = true;
		for (int i = 0; i < 10; i++) {
			cin >> x;
			if (f) {
				if (a < x&&b < x) {
					if (a < b) {
						b = x;
						continue;
					}
					a = x;
					continue;
				}
				if (a < x) {
					a = x;
					continue;
				}
				if (b < x) {
					b = x;
					continue;
				}
				f = false;
			}
		}
		cout << (f ? "YES" : "NO") << endl;
	}
	return 0;
}