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++: /*
Á·Ï°Ìâ£º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;
	if(x==9)
	{
		count++;
		return ;
	}
	for(int i=x+1; i<=9; i++)
		if(a[x]<a[i]&&mark[i]==0)
		{
			return dfs(i);
		}
		else
		{
			if(i==9)
				count++;
			continue;
		}
	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 <stdio.h>

int main(void){
    int next;
    int n;
    int atop,btop;
    
    scanf("%d", &n);
    for (int i=0; i<n; i++){
        atop = btop = 0;
        for (int j=0; j<10; j++){
            scanf("%d", &next);
            if (next<atop && next<btop){
                printf("NO\n");
                break;
            }
            else if (next<atop && next>btop) btop = next;
            else if (next>atop && next<btop) atop = next;
            else (atop<btop?btop:atop) = next;
            if (j==9) printf("YES\n");
        }
    }
    
    return 0;
}

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

int main(void){

    vector<int> input(10,0);
    
    int times;
    cin >> times;

    while(times > 0){

        for(int i = 0;i < 10;i++){
            cin >> input[i];
        }
        vector<int> a(10,0);
        vector<int> b(11,0);
        a[0] = input[0];
        int j = 1,k = 0,flag = 1;
        int keep1 = 0,keep2 = 0;
        
        for(int i = 1;i < 10;i++){

            if(a[j-1] < input[i] && b[k] < input[i]){
                a[j++] = input[i];
            }else if(b[k] < input[i]){
                b[k] = input[i];
            }else{
                flag = 0;
                break;
            }
        }

        if(flag){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
        times--;
    }




    return 0;
}

C++: #include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
    int N,pre,current,second_pre;
    bool NO_FLG;

    scanf("%d",&N);
    for(int i=0;i<N;i++){
        pre = -1;
        second_pre = -1;
        NO_FLG = false;
        for(int k = 0; k < 10; k++){
            scanf("%d",&current);	//????????????????????????
            if(k == 0){	//??????????????????????????´?????????????????????
                pre = current;
            }else{
                if(pre > current){	//1?????????????????????????????§????????´???,current?????????1????????????????§????
                    if(second_pre == -1){	//?°?????????°????????\?????????????§????
                        second_pre = current;
                        NO_FLG = true;
                    }else{
                        if(second_pre > current){
                            printf("NO\n");
                            NO_FLG = true;
                            break;
                        }else{
                            second_pre = current;
                            NO_FLG = false;
                        }
                    }
                }else{ //pre < current
                	pre = current;
                }
            }
        }
        if(!NO_FLG)printf("YES\n");

    }
    return 0;
}

C++: #include <stack>
#include <cstdio>
using namespace std;
  int main(){
    int k,n,i,j,x[10];
    scanf("%d",&n);
for(k=0;k<n;k++){
    for(i=0;i<10;i++){
       scanf("%d",&x[i]);
}
stack<int> B;
stack<int> C;
B.push(x[0]);
for(i=1;i<=9;i++){
if(x[i-1]>x[i]){
C.push(x[i]);
goto ccc;
}else{
	B.push(x[i]);
	goto bbb;
}
bbb:;
}
ccc:
for(j=i;j<9;j++){
if(B.top()<x[j+1]){
B.push(x[j+1]);
}else if(C.top()<x[j+1]){
	C.push(x[j+1]);
}else{
	printf("NO\n");
	goto aaa;
}
}
printf("YES\n");
aaa:;
}
return 0;
  }

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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  cin >> n;
  while(n--) {
    int a[10];
    REP(i,10) {
      cin >> a[i];
    }
    int i;
    for (i=0; i<(1<<10); i++) {
      int s=0,t=0;
      int j;
      for (j=0; j<10; j++) {
        if (1&(i>>j)) {
          if (a[j]>s)
            s=a[j];
          else
            break;
        } else {
          if (a[j]>t)
            t=a[j];
          else
            break;
        }
      }
      if (j==10) break;
    }
    if (i!=(1<<10))
      cout << "YES" << endl;
    else
      cout <<"NO" <<endl;
  }
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;

int main(){
	int i,j,N,ball;
    cin>>N;
    for(i=0;i<N;i++){
		int ri=0,le=0,flg=0;
		for(j=0;j<10;j++){
			cin>>ball;
			if(ri<ball){
				ri=ball;
			}else if(le<ball){
				le=ball;
			}else{
				flg=1;
			}
		}		
		if(flg==0){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
    }
    return 0;
}

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

using namespace std;

const int BALL_NUM = 10;

static bool
judge_ball(const vector<int> &ball, const int right_head, const int left_head, const int fall_ball) {

	if (10 <= fall_ball) {
		return true;
	}

	if (right_head < ball.at(fall_ball)) {
		if (true == judge_ball(ball, ball.at(fall_ball), left_head, fall_ball + 1)) {
			return true;
		}
	}
	if(left_head < ball.at(fall_ball)) {
		if (true == judge_ball(ball, right_head, ball.at(fall_ball), fall_ball + 1)) {
			return true;
		}
	}

	return false;
}

int main(void) {
	// input
	int data_num;
	cin >> data_num;
	vector<vector<int>> ball_set(data_num, vector<int>(10,0));
	for (int i = 0; i < data_num; i++) {
		for (int j = 0; j < BALL_NUM; j ++) {
			cin >> ball_set.at(i).at(j);
		}
	}

// judge true or false
for (int i = 0; i < data_num; i ++) {
	// int right_head = ball_set.at(i).at(0)
	// int left_head = 0;
	// int fall_ball = 1;

	if (true == judge_ball(ball_set.at(i), ball_set.at(i).at(0), 0, 1)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

return 0;
}

C++: #include <iostream>
// #include <algorithm>

using namespace std;

bool dfs(int i, int left, int right, int* balls) {
    if(i == 10)
        return true;

    if(balls[i] > left && dfs(i+1, balls[i], right, balls))
        return true;

    if(balls[i] > right && dfs(i+1, left, balls[i], balls))
        return true;

    return false;
}

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

        if(dfs(1, balls[0], 0, balls))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}