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 <cstdio>
#include <iostream>
using namespace std;
int ans = 0;
void judge(int a[], int aa, int b,int  c) {
	if (aa == 10)ans = 1;
	if (a[aa] > b) {
		if (a[aa] > c)
		{
			judge(a, aa + 1, a[aa], c);
			judge(a, aa + 1, b, a[aa]);
		}
		judge(a, aa + 1, a[aa], c);
	}
	else if (a[aa] > c)judge(a, aa + 1, b, a[aa]);
}
int main() {
	int n;
	int a[10] = { 0 };
	cin >> n;
	for (int i = 0; i < n; i++) {
		ans = 0;
		for (int j = 0; j < 10; j++) {
			cin >> a[j];
		}
		judge(a, 0, 0, 0);
		if (ans == 1)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	}

C++: #include <iostream>

using namespace std;

int ball[11],f;

int hukasa(int cup1,int cup2,int no){
	//cout << "NOW no:" << no << endl;
	if(no>=10)return 1;
	else if((ball[no]<cup1)&&(ball[no]<cup2))return 0;
	
	if(cup1<ball[no])return hukasa(ball[no],cup2,no+1);
	if(cup2<ball[no])return hukasa(cup1,ball[no],no+1);
}
int main(){
	int n;
	cin>>n;
	while(n!=0){
		f = 0;
		for(int i=1;i<11;i++){
			cin>>ball[i];
			}
		f = hukasa(0,0,1);
		//cout << "f is " << f << endl;
		if(f==1)cout << "YES" << endl;
		else cout<<"NO"<<endl;
		n-=1;
}
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n; cin >> n;
	while (n--) {
		int a(0), b(0), x;
		bool f(true);
		rep(i, 0, 10) {
			cin >> x;
			if (a < x)a = x;
			else if (b < x)b = x;
			else f = false;
		}
		cout << (f ? "YES" : "NO") << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int a[11];
bool dfs(int i,int l,int r){
	if(i==10)return true;
	if(dfs(i+1,a[i],r)&&a[i]>l)return true;
	if(dfs(i+1,l,a[i])&&a[i]>r)return true;
	return false;
}
int main(){
	int T;
	cin>>T;
	while(T--){
	for(int i=0;i<10;i++)
		cin>>a[i];
	if(dfs(0,0,0))cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;

int n, k;// , a = 0, b = 0;
bool f = 1;
stack<int> s1, s2;

int main(){
	cin >> n;
	REP(i, n){
		REP(j, 10){
			cin >> k;
			if (j == 0){
				s1.push(k);
				//a = s1.top();
			}
			else if (j == 1){
				s2.push(k);
				//b = s2.top();
			}
			else{
				if (s1.top() < k || s2.top() < k){
					if (k - s1.top() > k - s2.top()){
						s2.push(k);
					}
					else{
						s1.push(k);
					}
					//a = s1.top();
					//b = s2.top();
				}
				else{
					f = 0;
				}
			}
			//cout << a << b << "\n";
		}
		if (f){
			cout << "YES\n";
		}
		else{
			cout << "NO\n";
		}
	}
}

C++: #include<stdio.h>
 
int unname(int *ball,int i,int b,int c)
{
    if(i==10) return 1;
    if(c<ball[i]){
        c=ball[i];
        i++;
        return unname(ball,i,b,c);
    }
    if(b<ball[i]){
        b=ball[i];
        i++;
        return unname(ball,i,b,c);
    }
    return 0;
}
 
int main()
{
    int ball[10];
    int result,i;
    int b=0,c=0;
    for(i=0;i<10;i++)
    {
        scanf("%d",&ball[i]);
    }
    c=ball[0];
    i=0;
    result=unname(ball,i,b,c);
    if(result==1) printf("YES\n");
    else printf("NO\n");
    return 0;
}

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

C++: /*
Á·Ï°Ìâ£ºBall_AOJ 0033
*/
#include <cstdio>
#include <cstring>
using namespace std;

int a[15];
int mark[15];
int count;

void dfs(int x)
{
	mark[x] = 1;
	for(int i=x+1; i<=9-i; i++)
		if(a[x]<a[i])
		{
			return dfs(i);
		}
		else
		{
			count++;
			return ;
			
		}
}

int main()
{
	int T;
	scanf("%d", &T);
	while(T--)
	{
		count=0;
		bool flag=false;
		memset(mark, 0, sizeof(mark));
		for(int i=0; i<10; i++)
			scanf("%d", &a[i]);
		for(int i=0; i<10; i++)
		{
			if(mark[i]==0)
				dfs(i);
		}
		if(count<=2)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
int main(){
	int N, i;
	int num[11];
	cin >> N;
	while( N-- > 0 ){
		for( i = 0; i < 10; i++ ){
			cin >> num[i];
		}
		stack<int> st1;
		stack<int> st2;
		for( i = 0; i < 10; i++ ){
			if( st1.empty() ){
				st1.push(num[i]);
				continue;
			}else if( st2.empty() ){
				st2.push(num[i]);
				continue;
			}
			if( st1.top() > num[i] && st2.top() > num[i] ){
				cout << "NO" << endl;
				break;
			}else if( st1.top() > st2.top() ){
				st1.push(num[i]);
			}else{
				st2.push(num[i]);
			}
		}
		if( i == 10 ) cout << "YES" << endl;
	}
}

C++: #include <stdio.h>
#include <string.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int a[10], dp[16][16];

bool can() {
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    rep (i, 10) {
        rep (j, 11) if (dp[i][j]) {
            const int pre = i == 0 ? 0 : a[i-1];
            if (a[i] > j) dp[i+1][pre] = 1;
            if (a[i] > pre) dp[i+1][j] = 1;
        }
    }
    rep (i, 11) if (dp[10][i]) return true;
    return false;
}

int main() {
    int T;
    scanf("%d", &T);
    while (T--) {
        rep (i, 10) scanf("%d", a+i);
        puts(can() ? "YES" : "NO");
    }
    return 0;
}