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>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
int ta[10];
bool dfs(int h,int a,int b){
	if(h==10)return true;
	int now=ta[h];
	bool ret=0;
	if(now>a)ret=dfs(h+1,now,b);
	if(now>b)ret=dfs(h+1,a,now);
	return ret;
}

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

C++: #include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

typedef long long ll;

constexpr int INF = 1e8;
constexpr int MOD = 1e9+7;

int a[10];
stack<int> st[2];

bool dfs(int x) {
    if (x == 10) return true;
    int i;
    bool ret = false;
    REP (i,2) if (st[i].empty() || st[i].top() < a[x]) {
        st[i].push(a[x]);
        ret |= dfs(x+1);
        st[i].pop();
    }
    return ret;
}

int main(void) {
    int i, n;
    cin >> n;
    while (n--) {
        REP (i,10) cin >> a[i];
        if (dfs(0))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}

C++: #include <stdio.h>

int main()
{
	int N, ball[10], B[10], C[10], b, c, k;

	scanf("%d", &N);

	for (int i = 0; i < N; i++){
		scanf("%d %d %d %d %d %d %d %d %d %d", &ball[0], &ball[1], &ball[2], &ball[3], &ball[4], &ball[5], &ball[6], &ball[7], &ball[8], &ball[9]);

		b = 0;
		c = 0;
		k = 0;
		for (int j = 0; j < 10; j++){
			if(b < ball[j] && (ball[j] - b) <= (ball[j] - c)) b = ball[j];
			else if(c < ball[j]) c = ball[j];
			else {k = 1; break;}
		}

		if(k == 0) printf("YES\n");
		else printf("NO\n");
	}
	
	return 0;
}

C++: #include <cstdio>

const int N_BALL = 10;

int balls[N_BALL];

bool solve(int l[], int l_top, int r[], int r_top) {
  int bi = (l_top + 1) + (r_top + 1);
  if (bi == N_BALL) return true;

  l[l_top+1] = balls[bi];
  if (l_top >= 0 && l[l_top] > l[l_top+1]) return false;
  if (solve(l, l_top+1, r, r_top)) return true;
  l[l_top+1] = 0;

  r[r_top+1] = balls[bi];
  if (r_top >= 0 && r[r_top] > r[r_top+1]) return false;
  if (solve(l, l_top, r, r_top+1)) return true;;
  r[r_top+1] = 0;

  return false;
}

int main() {
  int N;
  scanf("%d", &N);

  for (int i = 0; i < N; i++) {
    for (int bi = 0; bi < N_BALL; bi++) scanf("%d", &balls[bi]);

    int left[N_BALL] = {}, right[N_BALL] = {};
    if (solve(left, -1, right, -1)) printf("YES\n");
    else printf("NO\n");
  }

  return 0;
}

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

int main(){
	int n;
	bool check;
	stack<int> a;
	stack<int> b;
	int ain,bin;
	cin>>n;
	for(int i=0;i<n;i++){
	check=true;
	a.push(0);b.push(0);
	cin>>ain>>bin;
	a.push(ain);b.push(bin);
	for(int j=0;j<5;j++){
		cin>>ain>>bin;
		if(!(a.top()<ain||b.top()<bin))check=false;
		a.push(ain);b.push(bin);
	}	
	if(check==false){cout<<"NO"<<endl;}else cout<<"YES"<<endl;
	}
}

C++: #include<cstdio>
int N, a[15];
void solve()
{
    int x = a[0], y = 0;
    for(int i = 1; i < 10; i++){
        if(a[i] > x && a[i] > y){
            if(a[i] - x >= a[i] - y)
                y = a[i];
            else
                x = a[i];
        }
        else if(a[i] > x)
            x = a[i];
        else if(a[i] > y)
            y = a[i];
        else{
            printf("NO\n");
            return;
        }
    }
    printf("YES\n");
}
int main()
{
    scanf("%d", &N);
    while(N--){
        for(int i = 0; i < 10; i++)
            scanf("%d", &a[i]);
        solve();
    }
    return 0;
}

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

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

	for (int i = 0; i < n; i++) {
		vector< vector<int> > v{ {0} };
		for (int j = 0; j < 10; j++) {
			cin >> x;
			for (int k = 0; k < v.size(); k++) {
				if (v[k].back() < x) {
					v[k].push_back(x);
					break;
				}

				if (k == v.size() - 1) {
					v.push_back({ x });
					break;
				}
			}

			if (v.size() == 3) {
				x = -1;
				break;
			}
		}
		if (x == -1) {
			cout << "NO";
		}
		else {
			cout << "YES";
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;

const int BALL_NUM = 10;

long n;

bool IsLeft(int num, int left, int right) {
    if (left > num) { return false; }
    if (left > right || right > num) { return true; }
    else { return false; }
}

int main() {
    scanf("%ld", &n);
    for (int i = 0; i < n; i++) {
        int b, left = 0, right = 0;
        bool flag = true;
        for (int j = 0; j < BALL_NUM; j++) {
            scanf("%d", &b);
            if (b < min(left, right)) {
                flag = false;
                break;
            }
            if (IsLeft(b, left, right)) { left = b; }
            else { right = b; }
        }
        if (flag) { printf("%s\n", "YES"); }
        else { printf("%s\n", "NO"); }
    }

    return 0;
}

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

int balls[10];

bool dfs(int idx, int b, int c){
	if(idx > 9) return true;
	
	bool ok = false;
	if(b < balls[idx]){
		ok = dfs(idx+1, balls[idx], c);
	}
	if(c < balls[idx]){
		ok = dfs(idx+1, b, balls[idx]);
	}
	return ok;
}

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

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


int main(){
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		int ball[10];
		for(int j=0;j<10;j++)scanf("%d",&ball[j]);
		
		stack<int> S,Q;
		int a[2]={0};
		S.push(ball[0]);
		Q.push(a[1]);
		
		int k=1;
		bool OK = false;
		while(1){
//			printf("%d,%d\n",a[0],a[1]);
			a[0] = S.top();
			a[1] = Q.top();
			if(a[0] < ball[k]){
				S.push(ball[k]);
				k++;
				if(k >= 11){
					OK = true;
					break;
				}
			}else if(a[1] < ball[k]){
				Q.push(ball[k]);
				k++;
				if(k >= 11){
					OK = true;
					break;
				}
			}else{
				S.pop();
				Q.pop();
				k--;
			}
			if(S.size() == 0) break;
		}		
		if(OK == true) printf("YES\n");
		else printf("NO\n");
		for(;;){
			if(S.size() == 0)break;
			S.pop();
		}
		for(;;){
			if(Q.size() == 0)break;
			Q.pop();
		}
		
		
	}
	return 0;
}

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

using namespace std;

int flag, a[10];

void f(int x0, int x1, int i)
{
	if (flag)
		return;
	if (i == 10)
	{
		flag = 1;
		return;
	}
	if (a[i] < x0 && a[i] < x1)
		return;
	if (a[i] > x0)
		f(a[i], x1, i + 1);
	if (a[i] > x1)
		f(x0, a[i], i + 1);
}

int main()
{
	int t, i;
	scanf("%d", &t);
	while (t--)
	{
		for (i = flag = 0; i < 10; i++)
			scanf("%d", &a[i]);
		f(0, 0, 0);
		if (flag)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}