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<iostream>
#include<cmath>
#include<cstring>
using namespace std;

const int MAX = 10;
int ball[MAX];
int can;
int n;

void dfs(int left, int right, int num){
	if(num == 10) can = 1;
	if(can != 0) return;
	if(ball[num] > left) dfs(ball[num], right, num+1);
	if(ball[num] > right) dfs(left, ball[num], num+1);
	return;
}

int main(){
	cin >> n;
	while(n--){
		for(int i = 0; i < 10; i++)
			cin >> ball[i];
		can = 0;
		dfs(0,0,0); 
		if(can == 0) cout << "NO" << endl;
		else cout << "YES" << endl;
	}
	return 0;
}

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

using namespace std;

int a[10];

bool dfs(int i, int B, int C)
{
    if(i == 10)
        return true;

    if(a[i] > B)
        return dfs(i + 1, a[i], C);
    
    if(a[i] > C)
        return dfs(i + 1, B, a[i]);
    
    return false;


}

int main()
{
    int N;
    cin >> N;
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < 10; j++)
        {
            cin >> a[j];
        }
        dfs(0, 0, 0);
        cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
    }
    

    return 0;
}

C++: #include <iostream>
using namespace std;
int b, c, cnt;
bool dfs(int x){
    if(x > b){
        b = x;
        return 1;
    }
    if(x > c){
        c = x;
        return 1;
    }
    return 0;
}

int main(void){
    int N, x;
    cin >> N;
    while(N != 0){
        b = 0;
        c = 0;
        cnt = 0;
        for(int i = 0; i < 10; i++){
            cin >> x;
            cnt += dfs(x);
        }
        if(cnt == 10)   cout << "YES" << endl;
        else    cout << "NO" << endl;
        N--;
    }
    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;
            }
        }
    }
}

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

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

using namespace std;

int n;
int stock[2][11];
int usea[11];

int dfs(int num, int r_num, int l_num) {
	int res = 0;

	if (usea[num] > stock[0][r_num]) {
		if (num == 9)
			return 1;
		stock[0][r_num + 1] = num;
		res = dfs(num + 1, r_num + 1, l_num);
		stock[0][r_num + 1] = -1;
		return res;
	}
	else if (usea[num] > stock[1][l_num]) {
		if (num == 9)
			return 1;
		stock[1][l_num + 1] = num;
		res = dfs(num + 1, r_num, l_num + 1);
		stock[1][l_num + 1] = -1;
		return res;
	}
	else {
		return 0;
	}
}


int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> usea[j];
		}
		stock[0][0] = -1;
		stock[0][1] = usea[0];
		stock[1][0] = -1;
		if (dfs(0, 1, 0)) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
		stock[0][0] = -1;
		stock[0][1] = -1;
		stock[1][0] = -1;
	}

	return 0;
}

C++: #include <iostream>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  cin>>n;
  while(n--){
    int a[10],b[2][11]={0},b1=1,b2=1,k=0;
    r(i,10)cin>>a[i];
    r(i,10){
      if(a[i]>b[1][b1-1])b[1][b1++]=a[i];
      else b[0][b2++]=a[i];
    }cout<<b1<<b2;
    r(i,b1-1){if(b[1][i]>b[1][i+1])k++;}
    r(i,b2-1){if(b[0][i]>b[0][i+1])k++;}
    if(k)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
  }
}

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

int main(void) {
	int n = 0;
	vector<string> r;
	scanf("%d",&n);
	for(int i=0; i<n; i++)
	{
		int a[10];
		scanf("%d %d %d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);
		int ca=a[0],cb=0;
		for (int j=1; j<=9; j++)
		{
			if (ca >= cb){
				if (ca < a[j])
				{
					ca = a[j];
				} else if(cb < a[j]) {
					cb = a[j];
				} else {
					r.push_back("NO");
					break;
				}
			} else {
				if (cb < a[j])
				{
					cb = a[j];
				} else if(ca < a[j]) {
					ca = a[j];
				} else {
					r.push_back("NO");
					break;
				}
			}
			if (j==9){r.push_back("YES");break;}
		}
	}
	for (int i=0; i<r.size(); i++)
	{
		cout << r[i] << endl;
	}
	return 0;
}

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

int main() {
    int n; cin >> n;  // ???????????????????????°
    
    while(n--){
        int balls[10] = {0};
        for(int i = 0; i < 10; i++) cin >> balls[i]; // ??????????????????????????\???
        
        bool isYES = true;  // ???10???????????????????????????????????????
        int topB = 0, topC = 0;  // ???B?????????C???????????¨????????????
        for(int i = 0; i < 10; i++){
            if (topB < balls[i]){
                topB = balls[i];
            } else if (topC < balls[i]) {
                topC = balls[i];
            } else {
                isYES = false;
                break;
            }
        }
        cout << (isYES ? "YES" : "NO") << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;

int a[20];

bool check(int x)
{
	int pre = 0;
	for (int i = 0; i < 10; i++) if (x & (1 << i))
	{
		if (a[i] < pre) return false;
		pre = a[i];
	}
	return true;
}

bool dfs(int i, int x, int pre)
{
	if (i == 10)
	{
		return check(x);
	}
	bool temp = false;
	if (a[i] > pre) temp = dfs(i + 1, x, a[i]);
	return temp || dfs(i + 1, x | (1 << i), pre);
}

int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		for (int i = 0; i < 10; i++) scanf("%d", &a[i]);
		printf("%s\n", dfs(1, 0, a[0]) ? "YES" : "NO");
	}
	return 0;
}

C++: #include <cstdio>
#include <algorithm>

using namespace std;

int solve(int* raw,int ri, int le, int t);

int main(){
  int time, i, j;
  int raw[10];
  scanf("%d",&time);
  for(i=0;i<time;i++){
    for(j=0;j<10;j++){
      scanf("%d",&raw[j]);
      }
    if(solve(raw,0,0,0)){
      printf("YES\n");
    }else printf("NO\n");
  }
    return 0;
}

  //solve???YES??????1NO??????0
int solve(int* raw, int ri, int le, int t){
  if(t==10){return 1;}
  int rid=0,led=0;
  if(ri<raw[t]) rid=solve(raw,raw[t],le, t+1);
  if(le<raw[t]) led=solve(raw,ri,raw[t], t+1);
  if(ri>=raw[t]&&le>=raw[t]) return 0;
  if(rid+led) return 1;
  else return 0;
  }