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 <vector>  

using namespace std;



void solve(vector<int> left, vector<int> right, vector<int> all, int n) {
	bool flag = true;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else
							flag = false;
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}	 	
		if (flag)
			printf("YES\n");
		else
			printf("NO\n");
		flag = true;
	}
}

int main() {		
	vector<int> left;
	vector<int> right;
	vector<int> all;


	int n;
	scanf("%d", &n);
	if (n <= 0) return -1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}	  

	solve(left, right, all, n);

	return 0;
}

C++: #include <iostream>
using namespace std;
int b, c, cnt, x[11];
void dfs(int i){
   if(x[i] > b){
       b = x[i];
       dfs(i+1);
       cnt++;
   }
   if(x[i] > c){
       c = x[i];
       dfs(i+1);
       cnt++;
   }
}

int main(void){
   int N;
   cin >> N;
   while(N != 0){
       b = 0;
       c = 0;
       cnt = 0;
       for(int i = 0; i < 10; i++){
           cin >> x[i];    
       }
       dfs(0);
       if(cnt == 11)   cout << "YES" << endl;
       else    cout << "NO" << endl;
       N--;
   }
   return 0;
}

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

stack<int> S1,S2;
int A[10];
bool flag;

int ball(int a){
	while (1){
		flag = false;
		cout << A[a] << endl;
		if (S1.top() < A[a]){
			S1.push(A[a]);
			a++; flag = true;
		}
		else if (S2.top() < A[a]){
			S2.push(A[a]);
			a++; flag = true;
		}
		if (flag == false) {
			return 0;
		}
		if (a == 10) {
			return 1;
		}
	}
}



int main(){
	int N;
	cin >> N;
	for (int i = 0; i < N; i++){
		for (int l = 0; l < 10; l++) cin >> A[l];
		S1.push(0);
		S2.push(0);
		int a = 0;
		if (ball(a)) cout << "YES" << endl;
		else cout << "NO" << endl;
		a = 0;
		while (!S1.empty()) S1.pop();
		while (!S2.empty()) S2.pop();
	}
	return 0;
}

C++: #include<iostream>
#include<stack>

using namespace std;

bool solve(stack<int> st1, stack<int> st2, int ball[10],int index){
	if(index == 10){
		return true;
	}
	if(st1.top() < ball[index]){
		st1.push(ball[index]);
		if(solve(st1,st2,ball,index+1)){
			return true;
		}else{
			st1.pop();
		}
	}
	if(st2.top() < ball[index]){
		st2.push(ball[index]);
		if(solve(st1,st2,ball,index+1)){
			return true;
		}else{
			st2.pop();
		}
	}
	return false;
}

int main(){
	stack<int> st1,st2;
	int ball[10];
	int n;
	cin >> n;
	for(int loop=0;loop<n;loop++){
		for(int i=0;i<10;i++){
			cin >> ball[i];
		}
		st1.push(0);
		st2.push(0);
		
		if(solve(st1,st2,ball,0)){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
}

C++: // https://onlinejudge.u-aizu.ac.jp/problems/0033
// 玉
// 1-10的序列，分成两组，让每一组都升序
// 虽然想让你用dfs，但是这个似乎直接贪心就可以了

#include <iostream>
#include <stack>

using namespace std;
int a[10];

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        for (int i = 0; i < 10; ++i)
            cin >> a[i];
        stack<int> q1;
        stack<int> q2;
        for (int i = 0; i < 10; ++i)
        {
            int t1, t2;
            if (q1.empty())
                t1 = 0;
            else
                t1 = q1.top();
            if (q2.empty())
                t2 = 0;
            else
                t2 = q2.top();
            if (t1 > a[i] && t2 > a[i])
            {
                cout << "NO" << endl;
                break;
            }
            else if (t1 < a[i] && t2 > a[i])
            {
                q1.push(a[i]);
            }
            else if (t1 > a[i] && t2 < a[i])
            {
                q2.push(a[i]);
            }
            else if (t1 < t2)
            {
                q2.push(a[i]);
            }
            else
            {
                q1.push(a[i]);
            }
            if (i == 9)
            {
                cout << "YES" << endl;
            }
        }
        
    }
    return 0;
}

C++: /*0ms,1008KB*/

#include<cstdio>
#include<cstring>

int a[15], l[15], r[15], t, i, j, lc, rc, cnt;
bool vis[15], flag;

bool solve()
{
	for (i = 0; i < 1024; ++i)
	{
		memset(l, 0, sizeof(l));
		memset(r, 0, sizeof(r));
		lc = rc = 0;
		for (cnt = 0, j = i; cnt < 10; ++cnt, j >>= 1)
		{
			if (j & 1) l[lc++] = a[cnt];
			else r[rc++] = a[cnt];
		}
		flag = true;
		for (j = 1; j < lc; ++j)
			if (l[j] < l[j - 1])
			{
				flag = false;
				break;
			}
		if (flag)
			for (j = 1; j < rc; ++j)
				if (r[j - 1] > r[j])
				{
					flag = false;
					break;
				}
		if (flag) return true;
	}
	return false;
}

int main()
{
	scanf("%d", &t);
	while (t--)
	{
		memset(vis, 0, sizeof(vis));
		for (i = 0; i < 10; ++i)
			scanf("%d", &a[i]);
		puts(solve() ? "YES" : "NO");
	}
	return 0;
}

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

int main() {
	int n;
	int d[10];
	int va[10];
	int vb[10];
	int trush;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> d[i];
		}

		int ca = 0, cb = 0;
		va[0] = d[0];
		ca++;
		if (d[1] > va[0]) {
			va[1] = d[1];
			ca++;
		}

		else {
			vb[0] = d[1];
			cb++;
		}

	for (int j = 2; j < 10; j++) {

			if (d[j] > va[ca-1]) {
				va[ca] = d[j];
				ca++;
			}

			else if (d[j] > vb[cb-1]) {
				vb[cb] = d[j];
				cb++;
			}

			else {
				trush = d[j];
			}

		}

	if (ca + cb == 10) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

		for (int i = 0; i < 10; i++) {
			va[i] = 0;
		}
		for (int i = 0; i < 10; i++) {
			vb[i] = 0;
		}
	}
	return 0;
}

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

#define TEST 0
#if TEST
FILE *in = freopen("./q", "r", stdin);
FILE *out = freopen("./ans", "w", stdout);
#endif

int main(){
	int n; cin >> n;
	while (n--){
		int balls[10];
		for (int i = 0; i < 10; i++){
			cin >> balls[i];
		}

		int left = 0, right = 0;
		bool ok = true;
		for (int i = 0; i < 10; i++){
			int dleft = balls[i] - left;
			int dright = balls[i] - right;

			if (dleft <= 0 && dright <= 0){
				ok = false;
				break;
			}

			if (dleft <= 0){
				right = balls[i];
			}
			else if (dright <= 0){
				left = balls[i];
			}
			else if (dleft < dright){
				left = balls[i];
			}
			else{
				right = balls[i];
			}
		}

		cout << (ok ? "YES": "NO") << endl;

	}
	

#if TEST
	fclose(in);
	fclose(out);
#endif
}

C++: #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

int main(){
    int n,b,B=0,C=0;
    
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        B=0;C=0;
        for(int j=0;j<10;j++){
            scanf("%d",&b);
            if(min(B,C)<b){
                if((B>C && B<b) || C>b)B=b;
                else C=b;
            }else{
                B=11;C=11;
            }
        }
        if(B==10 || C==10)
            puts("YES");
        else
            puts("NO");
    }
    return 0;
}