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++: // AojTemplete.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include "stdafx.h"
#include<iostream>
#include<vector>
using namespace  std;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		bool flag = false;
		int prev;
		int in[10];
		int used[10];
		for (int j = 0; j < 10; j++)
		{
			cin >> in[j];
		}
		prev = in[0];
		vector<int> B;
		vector<int> C;
		for (int j = 0; j < 10; j++)
		{
			if (prev > in[j])
			{
				C.push_back(in[j]);
				used[j] = false;
				continue;
			}
			else
			{
				prev = in[j];
				B.push_back(in[j]);
				used[j] = true;
			}
		}
		prev = C[0];
		for (int j = 0; j < C.size(); j++)
		{
			if (prev > C[j])
			{
				flag = true;
				break;
			}
			else
			{
				prev = C[j];
			}
		}
		if (flag) cout << "NO" << endl;
		else cout << "YES" << endl;
	}
	return 0;
}

C++: #include<iostream>
#include <stack> 
using namespace std;
int ar[10];
stack<int> a,b;
bool dfs(int i)
{
	bool aflag = false,bflag = false;
	if(i!=9)
	{
		if(a.empty()||a.top()<ar[i])
		{
			a.push(ar[i]);
			aflag = dfs(i+1);
		}
		if(b.empty()||b.top()<ar[i])
		{
			b.push(ar[i]);
			bflag = dfs(i+1);
		}
		return aflag|bflag;
	}
	if(i==9)
	{
		if(a.empty()||a.top()<ar[i])
		{
			a.push(ar[i]);
			aflag = true;
		}
		if(b.empty()||b.top()<ar[i])
		{
			b.push(ar[i]);
			bflag = true;
		}
		return aflag|bflag;
	}
}
int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		for(int i = 0;i<10;i++)
			cin >> ar[i]; 
		cout<<(dfs(0)?"YES":"NO")<<endl;
	}
 }

C++: #include<cstdio>

int main(){
	int n, b, c, t;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		b = c = 0;
		for(int j = 0; j < 10; j++){
			scanf("%d", &t);
			if(b < t){
				b = t;
			}else{
				if(c < t){
					c = t;
					if(b < c){
						t = b;
						b = c;
						c = t;
					}
				}else{
					t = 0;
					j += 10;
				}
			}
		}

		if(t){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <vector>



int t;
std::vector<int> balls(10);


int dfs(int d,int a,int b)
{
  if(d==10)
    {
      return 1;
    }

  //

  if(balls[d] > a   )
    {
      if(dfs(d+1,balls[d],b) == 1 )
        return 1;
    }

  if(balls[d] > b)
    {
      if( dfs(d+1,a,balls[d]) == 1)
        return 1;
    }

  return 0;
}

int main(int argc,char* argv[])
{
  //freopen("in.txt","r",stdin);
  std::cin>>t;
  while(t--)
    {
      for(int i = 0 ; i < 10 ; i++)
        std::cin >> balls[i];
      if(dfs(0,0,0) == 1 )
        std::cout<<"YES"<<std::endl;
      else
        std::cout<<"NO"<<std::endl;
    }
  return 0;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int t=0; t<n; t++){
        int b=0, c=0;
        int a[10];
        int i;
        if(!(cin>>a[0])) break;
        for(i=1; i<10; i++) cin>>a[i];
        for(i=0; i<10; i++){
            if(b<c){
                if(c<a[i]) c=a[i];
                else if(b<a[i]) b=a[i];
                else break;
            }else{
                if(b<a[i]) b=a[i];
                else if(c<a[i]) c=a[i];
                else break;
            }
        }
        cout<<(i==10?"YES\n":"NO\n");
    }
    return 0;
}

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

int main(void){
	queue<int> que;
	int b,c,n;
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			cin >> b;
			que.push(b);
		}
		b = c = 0;
		bool flag = false;
		while(!que.empty()){
			if(que.front() > b){
				b = que.front();
				que.pop();
			}else if(que.front() > c){
				c = que.front();
				que.pop();
			}else{
				flag = true;
				break;
			}
		}
		if(flag){
			cout << "NO" << endl;
		}else{
			cout << "YES" << endl;
		}
	}
}

C++: #include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    
    int n;
    cin >> n;
    
    for(int i=0;i<n;++i){
        
        bool flg=false;
        int maxB=0,maxC=0;
        
        for(int j=0;j<10;++j){
            int tmp;
            cin >> tmp;
            if(maxB<tmp)
                maxB=tmp;
            else if(maxC<tmp)
                maxC=tmp;
            else{
                flg=true;
            }
        }
        
        if(flg)
            cout << "NO" <<endl;
        else
            cout << "YES" <<endl;
        
    }
    
    
    return 0;
}

C++: #include<iostream>
#include<fstream>
#include<stack>
#include<vector>
#include<cstring>
using namespace std;
int a[11];
int b[11];
int c[11];
int flag;
void dfs(int x,int y,int z)
{
	if(x==9)
		flag=1;
	if(a[x]<b[y]&&a[x]<c[z])
		return;
	if(a[x]>b[y])
	{
		b[y+1]=a[x];
		dfs(x+1,y+1,z);
	}
	if(a[x]>c[z])
	{
		c[z+1]=a[x];
		dfs(x+1,y,z+1);
	}
}
int main()
{
	//freopen("3.txt","r",stdin);
	int n;
	cin >> n;
	while(n--)
	{
	flag=0;
	memset(b,0,sizeof(b));
	memset(c,0,sizeof(c));
	for(int i=0;i<10;i++)
		cin >> a[i];
	dfs(0,0,0);
	if(flag)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	}	
	return 0;
}

C++: #include <stdio.h>
int RideBack[10];
bool check(int val) {int B=-1,C=-1,q;for (q=9;q>=0;q--,val>>=1) if (val&1) {if (B<RideBack[q]) B=RideBack[q]; else break;} else {if (C<RideBack[q]) C=RideBack[q]; else break;} return (q<0);}
int main() {int N,i;scanf("%d",&N);while (N--) {for (i=9;i>=0;scanf("%d",&RideBack[i--]));for (i=0;i<1024;i++) if (check(i)) break;if (i==1024) puts("NO"); else puts("YES");}return 0;}

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


int n;
int A[10];

std::queue<int> input;

void solve() {
    bool                            flag = true;
    std::queue< std::pair<int, int> > que; // empty : -1

    que.push( std::make_pair(input.front(), -1) );
    // que.push( std::make_pair(-1, input.front()) );
    input.pop();
    while (!input.empty() && flag) {
        bool b = false;
        // bfs
        std::pair<int, int> p = que.front();
        que.pop();
        int n = input.front();

        if (p.first < n) {
            que.push( std::make_pair(n, p.second) );
            b = true;
            // std::cout << n << '\t' << p.second << std::endl;
        }

        if (p.second < n) {
            que.push( std::make_pair(p.first,  n) );
            b = true;
            // std::cout << p.first << '\n' << n << std::endl;
        }

        if (b) input.pop();

        if (que.empty()) flag = false;
    }

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


int main() {
    std::cin >> n;
    for (int i=0; i<n; i++) {
        int a;
        for (int j=0; j<10; j++) {
            std::cin >> a;
            input.push(a);
        }
        solve();
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  int a[10];
  int b[6];
  int c[6];
  int k=0;
  int k2=0;
  int out=0;
  cin>>n;
  b[0]=0;
  c[0]=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>a[j];
      if(b[k]<a[j] ){
	b[k+1]=a[j];
	k++;
      }
      else if(c[k2]<a[j]){
	c[k2+1]=a[j];
	k2++;
      }
      else{
	out=1;
      }
    }
    if(out==0) cout << "YES" << endl;    
    else if(out==1) cout << "NO" <<endl;
  }
}