Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	for i := 0; i < n; i++ {
		a := -1
		b := -1
		ans := true
		// それぞれの筒の一番上にあるたまの数字に着目すればよい
		for j := 0; j < 10; j++ {
			x := nextInt()
			if x > a {
				a = x
			} else if x > b {
				b = x
			} else {
				ans = false
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

#define MAX 10	// ÊÌ

int main()
{
	int A, B, C;
	int n;
	int i, j;
	int flag;

	cin>>n;
	for (i = 0; i < n; i++) {
		B = C = 0;
		flag = 1;
		for (j = 0; j < MAX; j++) {
			cin>>A;

			if (B < A) {
				B = A;
			} else if (C < A) {
				C = A;
			} else {
				flag = 0;
				break;
			}
		}
		if (flag) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}

	return 0;
}

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

int main(){
    int n;
    cin>>n;
    while(n--){
        vector<int>vec;
        for(int i=0;i<10;i++){
            int t;
            cin>>t;
            vec.push_back(t);
        }
        for(int i=0;i<1<<10;i++){
            vector<int>a,b;
            for(int j=0;j<10;j++){
                if((i>>j)&1){
                    a.push_back(vec[j]);
                }
                else{
                    b.push_back(vec[j]);
                }
            }
            int suc=1;
            if(a.size()>1)
                for(int j=0;j<a.size()-1;j++){
                    if(a[j+1]<a[j])
                        suc=0;
                }
            if(b.size()>1)
                for(int j=0;j<b.size()-1;j++){
                    if(b[j+1]<b[j])
                        suc=0;
                }
            if(suc==1){
                cout<<"YES"<<endl;
                goto next;
            }
            a.clear();
            b.clear();
        }
        cout<<"NO"<<endl;
    next:;
    }
    return 0;
}

C++: #include <cstdio>

const int BALL_NUMBER = 10;
bool state[1];

void back_track(int* list, int n_ptr,int left_top, int right_top) {
	// print
	//printf("ptr=%d, left=%d, right=%d\n", n_ptr, left_top, right_top);
	// find solution
	if (n_ptr == BALL_NUMBER) {
		state[0] = true;
		return;
	}
	// is ever found solution
	if (state[0]) {
		return;
	}
	// do left pattern
	if (list[n_ptr] > left_top)
		back_track(list, n_ptr + 1, list[n_ptr], right_top);
	// do right pattern
	if (list[n_ptr] > right_top)
		back_track(list, n_ptr + 1, left_top, list[n_ptr]);
	return;
}

int main(int argc, char *argv[]) {
	int dataN;
	fscanf(stdin, "%d", &dataN);
	
	for (int i = 0; i < dataN; i++) {
		int ball[10];
		state[0] = false;
		for (int j = 0; j < BALL_NUMBER; j++) {
			fscanf(stdin, "%d", &ball[j]);
		}
		// search
		back_track(ball, 0, -1, -1);
		// print result
		if (state[0])
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}

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

int Balls[10];

bool dfs(int i, int R, int L)
{
	if(i == 10) return true;

	if(dfs(i+1, Balls[i], L) && Balls[i] > R) return true;

	if(dfs(i+1, R, Balls[i]) && Balls[i] > L) return true;

	return false;
}

int main()
{
	int n;

	cin >> n;
	for(int i=0; i<n; i++){
		for(int j=0; j<10; j++)
			cin >> Balls[j];

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

	return 0;
}

C++: #include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define RG register int
#define rep(i,a,b)	for(RG i=a;i<=b;++i)
#define per(i,a,b)	for(RG i=a;i>=b;--i)
#define ll long long
#define inf (1<<29)
using namespace std;
int T,n=10,flg;
int num[15],rec[15],a[15],b[15];
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}

void judge()
{
	int la=0,lb=0;
	rep(i,1,n)	if(rec[i]==1)	a[++la]=num[i];
				else			b[++lb]=num[i];
	rep(i,2,la)	if(a[i-1]>a[i])	return;
	rep(i,2,lb)	if(b[i-1]>b[i])	return;
	flg=1;return;
}

void dfs(int step)
{
	if(flg)	return;
	if(step>n){judge();return;}
	rec[step]=1;dfs(step+1);
	rec[step]=0;dfs(step+1);
}

int main()
{
	T=read();
	while(T--)
	{
		rep(i,1,n)	num[i]=read();
		flg=0;
		dfs(1);
		puts(!flg?"NO":"YES");
	}
	return 0;
}

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

bool hoge(int a[], int i, int left, int right)
{
    if (i==10)
        return true;
    if (left < a[i])
        if (hoge(a, i+1, a[i], right))
            return true;
    if (right < a[i])
        if (hoge(a, i+1, left, a[i]))
            return true;
    return false;
}

int main(void) {
    int n, a[10];
    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 10; ++j)
            cin >> a[j];
        cout << ((hoge(a, 0, 0, 0))? "YES" : "NO") << endl;
    }
    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	while (n--) {
		int a[10];
		for (int i = 0; i < 10; i++) {
			cin >> a[i];
		}
		bool res = false;
		for (int i = 0; i < (1 << 10); i++) {
			bool flag = true;
			int am = 0, bm = 0;
			for (int j = 0; j < 10; j++) {
				if (i & (1 << j)) {
					if (a[j] > am) {
						am = a[j];
					}
					else {
						flag = false;
						break;
					}
				}
				else {
					if (a[j] > bm) {
						bm = a[j];
					}
					else {
						flag = false;
						break;
					}
				}
			}
			if (flag) {
				res = true;
			}
		}
		cout << (res ? "YES" : "NO") << endl;
	}
	return 0;
}

C++: #include<cstdio>
#define ture 1
#define false 0
using namespace std;

int s[10],l[10],r[10];

bool slove(int i,int j,int k){

for(int i=1;i<10;i++)
{
    if(s[i]<l[j]&&s[i]<r[k]){
        return false;
    }
    if(s[i]>l[j]&&s[i]<r[k]){
        l[j+1]=s[i];
        j++;
    }
    if(s[i]<l[j]&&s[i]>r[k]){
        r[k+1]=s[i];
        k++;
    }
    else{
    if(s[i]-1==l[j]){
        l[j+1]=s[i];
        j++;
    }
    else if(s[i]-1==r[k+1]){
        r[k+1]=s[i];
        k++;
    }
    else if((s[i]-l[j])<(s[i]-r[k])){
        l[j+1]=s[i];
        j++;
    }
    else {
        r[k+1]=s[i];
        k++;
    }
    }
}
return true;
}







    /*
        if(k==10)
        return ture;
        if(l[i]>s[k]&&r[j]>s[k])
        return false;
        l[i+1]=s[k];
        r[j+1]=s[k];
        if(slove(i,j+1,k+1)&&r[j]<s[k])
            {
                l[i+1]=0;
                return ture;
            }
            else if(slove(i+1,j,k+1)&&l[i]<s[k])
            {
                r[j+1]=0;
                return ture;
            }
            else
                return false;*/


int main()
{
    int N;
    scanf("%d",&N);
    while(N--)
    {
        for(int i=0;i<10;i++)
            {
                scanf("%d",&s[i]);
                l[i]=0;
                r[i]=0;
            }
            l[0]=s[0];
        if(slove(0,0,1))
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

C++: #include <cstdio>
using namespace std;
int n;
int a[11];
int main() {
    scanf("%d", &n);
    for (int t = 0; t < n; ++t) {
        int l = 0, r = 0;
        for (int i = 0; i < 10; ++i) scanf("%d", &a[i]);
        bool flag=false;
        for (int i = 0; i < 10; ++i) {
            if (r > l) {
                if (a[i] > r) r = a[i];
                else if (a[i] > l) l = a[i];
                else flag=true;
            } else {
                if (a[i] > l) l = a[i];
                else if (a[i] > r) r = a[i];
                else flag=true;
            }
        }
        if (flag) printf("NO");
        else printf("YES");

    }
    return 0;
}