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 <vector>
using namespace std;

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

    for(int i = 0; i < N; i++) {
        bool ans = true;
        int B_top = 0, C_top = 0;
        vector<int> ball(10);
        for(int i = 0; i < 10; i++) {
            cin >> ball[i];
        }
        for(int j = 0; j < 10; j++) {
            if(B_top < ball[j]) {
                B_top = ball[j];
            }
            else if(C_top < ball[j]) {
                C_top = ball[j];
            }
            else {
                ans = false;
                break;
            }
        }
        if(ans) {
            cout << "YES" << endl;
        }
        else {
            cout << "NO" << endl; 
        }
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        bool ans(true);
        int in[10],a,b;
        for(int j=0;j<10;j++){
            cin >> in[j];
        }
        a = in[0];   b = 0;
        for(int j=1;j<10;j++){
            if(a<in[j]||b<in[j]){
                if(a<in[j]&&b<in[j]){
                    if(abs(a-in[j])>=abs(b-in[j])){
                        b = in[j];
                    }else{
                        a = in[j];
                    }
                }else if(a<in[j]){
                    a = in[j];
                }else{
                    b = in[j];
                }
            }else{
                ans = false;
            }
        }
        if(ans)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}

C++: #include<cstdio>

int main(){
	int n, b, c, t;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			b = c = 0;
			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;
					break;
				}
			}
		}

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

C++: #include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



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

	for (int i = 0; i < n; i++)
	{
		int left = 0, right = 0;
		int ball[10];

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

		for (int j = 0; j < 10; j++)
		{
			if (left < ball[j] && right < ball[j])
			{
				if (right < left)
				{
					left = ball[j];
				}
				else
				{
					right = ball[j];
				}
			}
			else if (left < ball[j])
				left = ball[j];
			else if (right < ball[j])
				right = ball[j];
			else
			{
				cout << "NO" << endl;
				break;
			}
		}

		if (right == ball[9] || left == ball[9]) cout << "YES" << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int n;
	cin >> n;
	rep(x, 0, n) {
		vi d(10);
		rep(i, 0, 10) {
			cin >> d[i];
		}
		int t1 = 0, t2 = 0;
		bool ans = true;
		rep(i, 0, 10) {
			if (t1 < d[i]) t1 = d[i];
			else if (t2 < d[i]) t2 = d[i];
			else ans = false;
		}
		cout << (ans ? "YES" : "NO") << endl;
	}
}

C++: //
//  0033.cpp
//  
//
//  Created by Yoshida Satoshi on 2017/11/16.
//
//

#include <iostream>
using namespace std;

void tsumu(int l,int r,int* in,int j,bool *ans){
    if(j==9){
        *ans=true;
        return;
    }
    if(in[j]>l) tsumu(in[j],r,in,j+1,ans);
    if(in[j]>r) tsumu(l,in[j],in,j+1,ans);
    
    return;
}

int main(){
    int N;
    int in[10];
    int l;
    int r;
    bool ans;
    
    cin>>N;
    for(int i=0;i<N;i++){
        ans=false;
        l=r=0;
        for(int j=0;j<10;j++){
            cin>>in[j];
        }
        tsumu(l,r,in,0,&ans);
        if(i<N-1){
            if(ans) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else{
            if(ans) cout<<"YES"<<flush;
            else cout<<"NO"<<flush;
        }
        
    }
    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];

int 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:
	return 0;
}

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 <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>


int N;
int a[100];
int left[100], right[100], flag;
int main()
{
    scanf("%d", &N);

   while(N--){

        for(int j = 0; j < 10; j++) scanf("%d", &a[j]);

        for(int j = 0; j < 1<<10; j++)
        {
            int l = 0, r = 0;
            flag = 1;
            for(int k = 1, x = 0; k < 1<<10; k<<=1, x++)
            {
                if(j & k)  left[l++] = a[x];
                else   right[r++] = a[x];

                if((l >= 2 && left[l-1] <= left[l-2]) ||(r >= 2 && right[r-1] <= right[r-2]))
                {
                    flag = 0;
                    break;
                }
            }

            if(flag) break;

        }
        if(flag) printf("YES\n");
        else printf("NO\n");
    }

    return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
void dfs(int b[10],int c[10],int m,int k,int t);//a中，b中，c中游标
int a[10];
int flag;
int main()
{
	int N;
	cin >> N;
	while (N--)
	{
		for (int i = 0; i < 10; i++)
			cin >> a[i];
		int b[10];
		int c[10];
		b[0] = 0;
		c[0] = 0;
		flag = 0;
		dfs(b, c, 0, 0, 0);
		if (flag== 1)
			cout << "YES" << endl;
		else 
			cout << "NO" << endl;
	}
	return 0;
}
void dfs(int b[10], int c[10], int m, int k, int t)
{
	int ma = m;
	int kb = k;
	int tc = t;
	int i;
	int x[10], y[10];             //用x,y去中间值，好进行回溯
	if (ma == 10)
		flag=1;
	for (i = 0; i <=kb; i++)
	{
		x[i] = b[i];	
	}
	for (i = 0; i <= tc; i++)
	{
        y[i] = c[i];
	}
	/*if (x[kb] > a[ma] && y[tc] > a[ma])  //两个都大  不要直接return 应该返回 找其他的枝丫
		return 0;*/
	if (x[kb] > a[ma] && y[tc] < a[ma])
	{
		y[tc] = a[ma];
		ma++; tc++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
	}
	if (x[kb] < a[ma] && y[tc] > a[ma])
	{
		x[kb] = a[ma];
		ma++; kb++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
	}
	if (x[kb] < a[ma] && y[tc] < a[ma])
	{
		x[kb] = a[ma];
		ma++; kb++;
		if (ma <=10)
			dfs(b, c, ma, kb, tc);
		ma--; kb--;
		y[tc] = a[ma];
		ma++; tc++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
	}
}