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++: //AOJ 0033

#include<iostream>

using namespace std;

int main(){

	int n;

	cin>>n;

	int **data = new int*[n];
	for(int i=0;i<n;i++){
		data[i] = new int[10];
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			cin>>data[i][j];
		}
	}

	int youki[2]={0,0};
	int state = 0;
	int flag = 0;

	for(int i=0;i<n;i++){
		for(int k=0;k<2;k++){
			youki[k] = 0;
		}
		for(int j=0;j<10;j++){
			state = 0;
			flag = 0;
			for(int k=0;k<2;k++){

				if(youki[k]<=data[i][j]){
					youki[k] = data[i][j];
					state = 1;//ボール入れられた！
					break;
				}
			}
			if(state==0){
				cout<<"NO"<<endl;
				break;
			}
			if(state == 1 && j == 9){
				flag = 1;
			}
		}
		if(flag == 1){
			cout<<"YES"<<endl;

		}
		
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
	int n; cin >> n;
	for (int t = 0; t < n; ++t) {
		int a[10];
		for (int i = 0; i < 10; ++i) cin >> a[i];

		bool ans = false;
		for (int k = 0; k < (1 << 10); ++k) {
			int top[2] = {-1, -1};
			bool f = true;
			for (int i = 0; i < 10; ++i) {
				int tid = k & (1 << i) ? 1 : 0;
				if (a[i] < top[tid]) {
					f = false;
					break;
				}
				top[tid] = a[i];
			}
			ans |= f;
		}

		if (ans) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

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

int main(){

int N,x,y,n;

scanf("%d",&N);

for(int i=0;i<N;i++){
x=n=0;
y=-1;
	for(int j=0;j<10;j++){
		scanf("%d",&n);
		if(x>n && y>n){
			printf("\nNO");
			break;
		}
		else if((x>n && n>y)||(n>y && y>x))
			y=n;
		else if((y>n && n>x)||(n>x && x>y))
			x=n;
		if(j==9)
			printf("\nYES");
	}			
}
return 0;
}

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

int func( int *ball, int n, int cur, stack<int> b, stack<int> c){
    int ball_cur = ball[cur];
    int count=0;
    
    if(cur == n){
        return 1;
    }    
    if(b.empty() || b.top() < ball_cur ){
        b.push(ball_cur);
        count+=func(ball, n, cur+1, b, c);
        b.pop();
    }
    if(c.empty() || c.top() < ball_cur ){
        c.push(ball_cur);
        count+=func(ball, n, cur+1, b, c);
        c.pop();
    }
    return count;    
}

int main(){
    int n;
    int ball[10];
    stack<int> stk_b,stk_c;
    
    cin>>n;
    for(int i=0;i<n;++i){
        for(int j=0;j<10;++j){
            cin>>ball[j];
        }
        cout << (func(ball, 10, 0, stk_b, stk_c)?"Yes":"No") << endl;
        
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
#define RIGHT 1
#define LEFT 0
#define BALL 10
#define BAD 1

int main()
{
    int n;
    int num[BALL];
    int siden[BALL];
    cin >> n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<BALL;++j) {cin >> num[j]; }

        int temp,ans =0;
        for(int side=0;side<=0x3F;++side)
        {
            ans = 0;
            for(int j = 0;j<BALL;++j)
            {
                if(((side>>j)&1) ){siden[j] = RIGHT;}
                else {siden[j] = LEFT;}
            }
            int before = -1;
            for(int j=0;j<BALL;++j)
            {
                if(siden[j]==RIGHT)
                {
                    if(before > -1)
                    {
                        if(num[before]>num[j])ans = BAD;
                    }
                    before = j;
                }
            }
            before = -1;

            for(int j=0;j<BALL;++j)
            {
                if(siden[j]==LEFT)
                {
                    if(before > -1)
                    {
                        if(num[before]>num[j])ans = BAD;
                    }
                    before = j;
                }
            }
            if(ans==0)break;
        }
        if(ans==BAD) cout << "NO" << endl;
        else cout << "YES" << endl;
    }
    return 0;
}

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

#define MAX_W 100
#define MAX_H 100

char room[MAX_W][MAX_H];
int W,H;

const int direc[4][2] = {
    {0, -1},
    {1, 0},
    {0, 1},
    {-1, 0},
};

void dfs(const int& row, const int& col, const char c);

int main() {
    while(cin>>H>>W, W > 0) {
        int step = 0;
        int col, row;
        for (row = 0; row < H; ++row) {
            for (col = 0; col < W; ++col) {
                cin >> room[row][col];
            }
        }
        for (row = 0; row < H; ++ row) {
            for(col = 0; col < W; ++ col) {
                if(room[row][col] != '!') {
                    dfs(row, col, room[row][col]);
                    ++ step;
                }
            }
        }
        cout<<step<<endl;
    }
    return 0;
}

void dfs(const int& row, const int& col, const char c) {
    room[row][col] = '!';
    for(int d = 0; d < 4; ++ d) {
        int curRow = row + direc[d][1];
        int curCol = col + direc[d][0];
        if(curRow >= 0 && curRow < H && curCol >= 0 && curCol < W && room[curRow][curCol] == c) {
            dfs(curRow, curCol, c);
        }
    }
}

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

int main(){
	int N;
	bool N_Flag;
	int first, second, current;
	cin>>N;
	for(int i=0;i<N;i++){
		N_Flag = false;
		first = -1;
		second = -1;
		for(int k=0;k<10;k++){
			cin>>current;
			if(current>first){
				first = current;
			}else{
				if(current>second){
					second = current;
				}else{
					N_Flag = true;
//					break;  去掉break的目的是完成循环，耗尽多余的数字，以便下一循环的数据正确 
				}
			}
		}
		if(N_Flag){
			cout<<"NO"<<endl;
		}else{
			cout<<"YES"<<endl;
		}
	}
}

C++: #include<iostream>

int N;
int a[10];

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

		int lm = 0, rm = 0;

		bool f = true;

		for( int i = 0; i < 10; i++ )
		{
			if( a[i] > lm )
				lm = a[i];
			else if( a[i] > rm )
				rm = a[i];
			else 
				f = false;
		}

		if( f ) 
			puts( "YES" );
		else
			puts( "NO" );
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
main(){
  int n,a;
  srand((unsigned)time(NULL));
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>a;
    }
    if(rand()%2==0){
      cout<<"YES"<<endl;
    }
    else{
      cout<<"NO"<<endl;
    }
  }
}

C++: #include<iostream>
using namespace std;
int r[10],l[10];
int data[10];

bool solve(int n,int rt,int lt)
{
	if(n==10)
	{
		for(int i = 1; i <= rt ; ++i)
		{
			if(r[i-1]>r[i]&&r[i]!=0) return false;
		}
		for(int i = 1; i <= lt ; ++i)
		{
			if(l[i-1]>l[i]&&l[i]!=0) return false;
		}
		return true;
	}

	r[rt]=data[n];
	if(solve(n+1,rt+1,lt)) return true;
	r[rt]=0;
	l[lt]=data[n];
	if(solve(n+1,rt,lt+1)) return true;
	l[lt]=0;

	return false;
}

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