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 <vector>
#include <climits>
using namespace std;
int b = INT_MIN, c = INT_MIN;
bool push(vector<int> ball) {
    vector<int>::iterator ite;
    for(ite = ball.begin(); ite != ball.end(); ite++) {
        if(*ite > b) b = *ite;
        else if (*ite > c) c = *ite;
        else return(false);
    }
    return(true);
}

int main(void) {
    int num; cin >> num;
    for(int r = 0; r < num; r++) {
        vector<int> vec;
        for(int c = 0; c < 10; c++) {
            int input; cin >> input;
            vec.push_back(input);
        }
        if(push(vec)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return(0);
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <cstring>
#include <string>
#include <sstream>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

vector<int> in(10);
string res;

void dfs(int, int, int);

int main(void){
    int n; cin >> n;
    while(n --){
        res = "NO";
        rep(i, 10) cin >> in[i];

        dfs(0, 0, 0);
        cout << res << endl;
    }

    return 0;
}

void dfs(int left, int right, int cur){
    if(cur == in.size()) res = "YES";
    if(res == "YES") return;

    if(left < in[cur]) dfs(in[cur], right, cur + 1);
    if(right < in[cur]) dfs(left, in[cur], cur + 1);
}

C++: #include <iostream>

using namespace std;

int main() {

	int s=0, i, N, x[10], c=0, d=0, end1=0, end2=0;
	int a[10], b[10];

	cin >> N;
	while(N!=0) {
		for(i=0; i<10; i++)
			cin >> x[i];
		i=0;
		while(i<10) {
			if(s==0) {
				if(c==0) {
					a[c]=x[i];
					c++;
					end2=0;
				}
				if(a[c-1]>x[i]) {
					s++;
					end1=1;
				}
				else {
					a[c]=x[i];
					c++;
					end2=0;
				}
			}
			if(s==1) {
				if(d==0) {
					b[d]=x[i];
					d++;
					end1=0;
				}
				if(b[d-1]>x[i]) {
					s--;
					end2=1;
				}
				else {
					b[d]=x[i];
					d++;
					end2=0;
				}
			}
			if(end1==1&&end2==1) {
				cout << "NO" << endl;
				break;
			}
			i++;
		}
		if(end1==0||end2==0)
			cout << "YES" << endl;
		N--;
	}

	return 0;

}

C++: #include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,a;
  int b = 11,c = 11;
  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 {
	cout << "NO" << endl;
	return;
      }  
    }
    cout << "YES" << endl;
  }
  return;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

/*
int main(){
	int n;

	cin >> n;

	while(n--){
		int input = 0;
		int left = 0, right = 0;
		bool achieve = true;
		REP(i, 10){
			cin >> input;
			if(left > input && right > input){
				//両方入らなかったら
				achieve = false;
				break;
			}
			else{
				//どっちかにしか入らない場合
				
				if(left > input || right > input){
					//入る方探して入れる
					if(input > left){
						left = input;
					}
					else{
						right = input;
					}
				}
				//どっちにも入る場合
				else{
					//先に入ってる数字が大きい方に入れる
					if(left > right){
						left = input;
					}
					else{
						right = input;
					}
				}
			}
		}
		cout << (achieve ? "YES" : "NO") << endl;
	}
	return 0;
}
*/
int main(){
    int n;
 
    cin >> n;
    while(n--){
        int a;
        bool p = true;
        int b = 0, c = 0;
        for(int i = 0; i < 10; i++){
            cin >> a;
            if(p){
                if(a > b){
                    b = a;
                }else if(a > c){
                    c = a;
                }else{
                    p = false;
                }
            }
        }
         
        if(p){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
 
    return 0;
}

C++: #include<iostream>

int N;
int a[10];

int main()
{
	std::cin >> N;
	
	while( N-- )
	{
		for( int i = 0; i < 10; i++ )
			std::cin >> a[i];

		int lm = 0, rm = 0;

		bool f = true;

		for( int i = 0; i < 10; i++ )
		{
			if( a[i] > lm )
				lm = a[i];
			else if( a[i] > rm )
				rm = a[i];
			else 
				f = false;
		}

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

	return 0;
}

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

int B, C, num[12], b, c;

bool dfs(int b, int c, int i){
    if(i == 10) return true;
    if(b<num[i] && dfs(num[i], c, i+1)){
        return true;
    }
    if(c<num[i] && dfs(b, num[i], i+1)){
        return true;
    }
    return false;
}

int main(void){
  int N;
  cin >> N;
  for(int j=0; j<N; j++){
  B = 0;
  C = 0;
  for(int i=0; i<10; i++){
    cin >> num[i];
  }
  dfs(0, 0, 0);
  if(dfs(0, 0, 0))  cout << "YES" << endl;
  else cout << "NO" << endl;
  }
  return 0;
}

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

using namespace std;

int main(void)
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int k=0; k<n; k++) {
        int a[10];
        for(int i=0; i<10; i++) cin >> a[i];
        int b=-1, c=-1;
        bool f = 0;
        for(int i=0; i<10; i++) {
            if(b<a[i]) {
                b = a[i];
            } else if(c<a[i]) {
                c = a[i];
            } else {
                f = 1;
                break;
            }
        }
        printf("%s\n", f ? "NO" : "YES");
    }

    return 0;
}

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

using namespace std;


const int MAX_M = 15;
int N, H[10];

double dp[2][(1 << MAX_M) + 1];

void solve() {
	int big=0, small=0;
	for (int i = 0; i < 10; i++) {
		if (big < small) swap(big, small);
		if (H[i] < small) {
			printf("NO\n");
			goto JUMP;
		}

		if (H[i] > big) big = H[i];
		else if (H[i] > small) small = H[i];

	}
	printf("YES\n");
JUMP:;
}

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

	
	return 0;
}

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

int A[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int B[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

bool isSorted(void)
{
	int i = 1;
	while(A[i]!=0 && i<=9)
	{
		if(A[i] < A[i-1]) return false;
		i++;
	}

	i = 1;
	while(B[i]!=0 && i<=9)
	{
		if(B[i] < B[i-1]) return false;
		i++;
	}

	return true;
}

int main(void)
{
	int n;
	cin >> n;
	bool enable = false;
	for(int i=0; i<n; i++)
	{
		int X[10];
		for(int j=0; j<10; j++)
			cin >> X[j];

		for(int j=0; j<1024; j++)
		{
			int a = 0, b = 0;
			int e = 1;
			for(int k=0; k<10; k++)
			{
				if( (j & e) == e)
				{
					A[a] = X[k];
					a++;
				}
				else
				{
					B[b] = X[k];
					b++;
				}
				e *= 2;
			}
			if(isSorted())
			{
				enable = true;
			}

			//initialize
			for(int j=0; j<10; j++)
			{
				A[j] = 0; B[j] = 0;
			}
		}
		if(enable) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}