Go: package main

import "fmt"

func isOrdered(a []int) bool {
	if len(a) <= 1 {
		return true
	}
	for i := 0; i+1 < len(a); i++ {
		if a[i] > a[i+1] {
			return false
		}
	}
	return true
}

func main() {
	// ボールの数がせいぜい10個しかないので、全てのボールの落とし方を全探索することが可能
	// Bit全探索を行う。右から見てj番目のビットが立っているときには左側の筒、立っていない時は右側の筒にいれる物とする。
	// 全てのボールを落とし終わった後に、それぞれの筒で昇順に並んでいるか調べることにする。
	var t int
	fmt.Scan(&t)
	ans := make([]bool, t)
	for i := 0; i < t; i++ {
		balls := make([]int, 10)
		for i := range balls {
			fmt.Scan(&balls[i])
		}
		ans[i] = false
		for bits := 0; bits < (1 << uint(10)); bits++ {
			pipeB := make([]int, 0)
			pipeC := make([]int, 0)
			for j := 0; j < 10; j++ {
				if (bits & (1 << uint(j))) != 0 {
					pipeB = append(pipeB, balls[j])
				} else {
					pipeC = append(pipeC, balls[j])
				}
			}
			if isOrdered(pipeB) && isOrdered(pipeC) {
				// fmt.Printf("test case %d - OK pattern - pipeB %v, pipec %v\n", i, pipeB, pipeC)
				ans[i] = true
				break
			}
		}
	}
	for i := range ans {
		if ans[i] {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

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

using namespace std;

bool Solution()
{
    int n;
    
    int left = 0;
    int right = 0;
    
    int a[10];
    
    cin>>n;
    
    where(n--)
    {
        for (int i = 0; i < 10; i++)
        {
            cin>>a[i];
        }
        
        for (int i = 0; i < 10; i++)
        {
            if (a[i] > left) // at the beginning, compare with first ball and the ball before first ball (empty)
            {
                left = a[i];
            }
            else if (a[i] > right)
            {
                right = a[i];
            }
            else                 //when can not enter to the both bottles to the end, then return false
            {
                return false;
            }
        }
        
        return true;
    }
}

int main()
{
   if (Solution())
   {
       cout<<"YES"<<endl;
   }
   else
   {
        cout<<"NO"<<endl;
   }
    
    return 0;
}