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++: /*
P135
AOJ 0033 Ball
http://judge.u-aizu.ac.jp/onlinejudge/index.jsp

*/

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <functional>
#include <string.h>
using namespace std;

int W, H;
char board[110][110];
int a[10];
bool read()
{
    for(int i=0; i<10; ++i)
        scanf("%d", a+i);
}

bool isVisited[110][110];
int step;

void dfs(int x, int y, char c){
    if(x<0 || x>=H || y<0 || y>=W) return;
    if(board[x][y]!=c) return;
    if(isVisited[x][y]) return;
    isVisited[x][y] = true;
    dfs(x+1, y, c);
    dfs(x-1, y, c);
    dfs(x, y+1, c);
    dfs(x, y-1, c);
}

void solve()
{
    int x1=0, x2=0;
    bool ans = true;
    for(int i=0; i<10; ++i)
    {
        if(x1 < x2) swap(x1, x2);
        if(x1 < a[i]) x1 = a[i];
        else if(x2 < a[i]) x2 = a[i];
        else {ans = false; break;}
    }
    if(ans) printf("YES\n");
    else printf("NO");
}


int main()
{
    int T;
    scanf("%d", &T);
    while(T--){
        read();
        solve();
    }
}

C++: #include<iostream>

using namespace std;

int main(void){
	int a[11],fir,n;
	int i;
	cin>>n;
	while(n--){
		int sec = 0;
		for(i=0;i<10;i++){
			cin>>a[i];
		}
		fir=a[0];
		for(i=1;i<10;i++){
			if(fir<a[i])fir=a[i];
			else if(sec<a[i])sec=a[i];
			else break;
		}
		if(i==10)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;

}

C++: #include <iostream>

using namespace std;

//Aoj 0033

int ball[15], l[15],r[15];

bool res= false;

void dfs(int i,int j,int k){//i 为当年需要落下的球,j 表示左边最上面球的上一位置，k 表示最右边球的上一位置
    if(i>=10){
        res=true;
        return;
    }
//    if(res){
//        return;
//    }
    if(ball[i]>l[j-1]){
        l[j]=ball[i];
        dfs(i+1,j+1,k);
    }
    if(ball[i]>r[k-1]){
        r[k]=ball[i];
        dfs(i+1,j,k+1);
    }

}

int main(){
    int n;
    cin>>n;
    while(n--){
        res= false;
        for(int i=0;i<10;i++){
            cin>>ball[i];
        }
        dfs(0,1,1);
        if(res){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }

    }
    return 0;
}

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;
}