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 <stdio.h>

int ball[10];

bool can(int n,int left,int right){
	bool flag;
	
	if(n==10) return true;
	if(ball[n]>right && can(n+1,left ,ball[n])) return true;
	if(ball[n]>left  && can(n+1,ball[n],right)) return true;
	
	return false;
}


int main(){
	
	int N;
	
	scanf("%d",&N);
	
	for(int i=0;i<N;i++){
		for(int j=0;j<10;j++){
			scanf("%d",&ball[j]);
		}
		
		printf(can(0,0,0)?"YES":"NO");
		
		
	}
}

C++: #include<cstdio>
#include<stack>
using namespace std;
int a[10],flag;
stack<int>s1,s2;
void dfs(int i){
	if(i==10){flag=1;return ;}
	if(a[i]>s1.top()){
		s1.push(a[i]);
		dfs(i+1);
		s1.pop();
	}
	if(a[i]>s2.top()){
		s2.push(a[i]);
		dfs(i+1);
		s2.pop();
	}
	return ;
}
int main(void){
	int T;scanf("%d",&T);
	while(T--){
		while(!s1.empty())s1.pop();
		while(!s2.empty())s2.pop();
		flag=0;
		for(int i=0;i<10;i++)
			scanf("%d",a+i);
		s1.push(0),s2.push(0);
		dfs(0);
		printf(flag?"YES\n":"NO\n");
	}
}

C++: #include <iostream>
using namespace std;
int a[10];
bool dfs(int i,int b,int c){
	if(i<10){
		if(a[i] > b) {
			if(dfs(i+1,a[i],c)){
				return true;
			}
		}
		else if(a[i] > c) {
			if(dfs(i+1,b,a[i])) {
				return true;
			}
		}
		return false;
	}
	return true;
}
int main(){
	int i,n;
	while(cin >> n && n){
		for(i=0;i<n;i++){
			for(int j = 0;j<10;j++){
				cin >> a[j];
			}
			if(dfs(0,0,0)) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int a[10];

void solve() {
    int min1 = INT_MIN, min2 = INT_MIN;
    for(int i = 0;i < 10; i++) {
        if(a[i] > min1 && a[i] > min2) {
            if(min1 > min2) {
                min1 = a[i];
            } else {
                min2 = a[i];
            }
        } else if(a[i] > min1) {
            min1 = a[i];
        } else if(a[i] > min2) {
            min2 = a[i];
        } else {
            printf("NO\n");
            return ;
        }
    }
    printf("YES\n");
    return ;
}

int main() {
    int num;
    scanf("%d", &num);
    while(num--) {
        for(int i = 0;i < 10; i++) {
            scanf("%d", &a[i]);
        }
        solve();
    }
}

C++: #include<stdio.h>
#include<string.h>

int main(){
	int ball[10];
	int cell[2][10]={0};
	int n,i,k,cell_1=1,cell_2=1,flag[1000]={0};
	
	scanf("%d",&n);
	
	for(k=0;k<n;k++){
		for(i=0;i<10;i++)scanf("%d",&ball[i]);
		
		cell[0][0]=0;
		cell[1][0]=0;

		for(i=0;i<10;i++){
			if(cell[0][cell_1-1] < ball[i]){
				cell[0][cell_1]=ball[i];
				cell_1++;
			}
			else if(cell[1][cell_2-1] < ball[i]){
				cell[1][cell_2]=ball[i];
				cell_2++;
			}
			else flag[k]=1;
		}	
	}
	
	cell_1=1;
	cell_2=1;
	
	for(i=0;i<n;i++){
		if(flag[i]==0)printf("YES\n");
		else printf("NO\n");
	}
	
	return 0;
}

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

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

	for (int i = 0; i < n; i++){
		queue<int> ball;
		int num;
		for (int j = 0; j < 10; j++){
			cin >> num;
			ball.push(num);
		}

		int b = 0, c = 0;
		for (int j = 0; j < 10; j++){
			int p_ball = ball.front();
			if (b < p_ball){
				b = p_ball;
				ball.pop();
			}
			else if (c < p_ball){
				c = p_ball;
				ball.pop();
			}
			else {
				cout << "NO" << endl;
				break;
			}
		}

		if (ball.empty()){
			cout << "YES" << endl;
		}
	}

	return (0);
}

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

bool solver(queue<int> q, int a, int b){
    bool result = false;
    if(q.empty()) {
        return true;
    }
    int tmp = q.front();
    if(tmp > a){
        a = tmp;
        q.pop();
        result = solver(q, a, b);
        q.push(tmp);
    }
    if(result) return true;
    tmp = q.front();
    if(tmp > b){
        b = tmp;
        q.pop();
        result = solver(q, a, b);
        q.push(tmp);
    }
    if(result) return true;
    return false;
}

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

    for(int i=0; i<n; i++){
        queue<int> q;
        for(int j=0; j<10; j++){
            int tmp;
            cin >> tmp;
            q.push(tmp);
        }
        cout << (solver(q,0,0)?"YES":"NO") << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int ball[10];

bool dfs(int,int,int);

int main(){
	int n;
	cin>>n;
	for (int i = 0; i < n; i++) {
		for (int& j : ball) cin>>j;
		if(dfs(0,0,0))puts("YES");
		else puts("NO");
	}
	return 0;
}

bool dfs(int b,int c,int m){
	if(m == 9)return (b<ball[m] || c<ball[m]) ? true : false;
	bool res = false;
	if(b<ball[m])res = max(res,dfs(ball[m],c,m+1));
	if(c<ball[m])res = max(res,dfs(b,ball[m],m+1));
	return res;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int a[10];

bool dfs(int i, int left, int right){
	cout << left << " " << right << " " << i << endl;
	if(i == 10) return true;
	bool answer = false;
	if(left < a[i]){
		answer = dfs(i+1, a[i], right);
	}
	if(right < a[i]){
		answer = dfs(i+1, left, a[i]);
	}

	return answer;
}


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

C++: // scnucjh
// AOJ 0033
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n;
vector<int> B,C;
int A[10];
bool flag; //是否有解

void dfs(int x) {
	if(x==10) { //球丢完了，递归要返回
		for(int i=1;i<B.size();i++) {
			if(B[i]<B[i-1]) return; //这个分支不行,有矛盾
		}
		for(int i=1;i<C.size();i++) {
			if(C[i]<C[i-1]) return; //这个分支不行,有矛盾
		}
		flag = true; 			 //这个分支走到最后是有解的
		return;
	}
	B.push_back(A[x]); 			//把第x个球丢给B
	dfs(x+1);  					//进入这个分支
	B.pop_back(); 				//撤销操作，弹出B的最后一个球
	
	C.push_back(A[x]); 			//把第x个球丢给C
	dfs(x+1);    				//进入这个分支
	C.pop_back(); 				//撤销操作，弹出C的最后一个球
}

int main() {
	int T;
    scanf("%d",&T);
	while(T--) {
		for(int i=0;i<10;i++) scanf("%d",&A[i]);
		flag = false;
		dfs(0);
		puts(flag ? "YES":"NO");
	}
    return 0;
}

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

int ball[10];

bool solve(int i, int a, int b){
	if (i == 10) return true;
	bool ans = false;
	if (a < ball[i]) ans = solve(i + 1, ball[i], b);
	if (b < ball[i])ans = solve(i + 1, a, ball[i]);
	return ans;
}

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

	for (int i = 0; i < n; i++){
		for (int j = 0; j < 10; j++){
			cin >> ball[j];
		}
		if (solve(0, 0, 0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;
}
//beatmaniaIIDX 23th copula

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

int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		bool z = true;
		int a[10];
		for(int j=0;j<10;j++) cin >> a[j];
		int b = 0;
		int c = 0;
		for(int j=0;j<10;j++){
			if(b>a[j] and c>a[j]) z = false;
			if(not z) break;
			if(b>c){
				if(b>a[j]) c = a[j];
				else b = a[j];
			}
			else{
				if(c>a[j]) b = a[j];
				else c = a[j];
			}
		}
		if(z) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}