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 <vector>
#include <array>
#include <stack>

int main()
{
	std::vector<int> a;
	std::vector<int> b;

	int n = 0;
	std::cin >> n;

	while (n--)
	{
		bool is_failure = false;

		int datas[10] = { 0 };
		std::cin >> datas[0] >> datas[1] >> datas[2] >> datas[3] >> datas[4] >> datas[5] >> datas[6] >> datas[7] >> datas[8] >> datas[9];

		std::stack<int> stack_a{};
		std::stack<int> stack_b{};

		for (auto data : datas)
		{
			if (stack_a.empty())
			{
				stack_a.push(data);
				continue;
			}

			if (stack_a.top() < data)
			{
				stack_a.push(data);
				continue;
			}

			if (stack_b.empty())
			{
				stack_b.push(data);
				continue;
			}

			if (stack_b.top() < data)
			{
				stack_b.push(data);
				continue;
			}

			is_failure = true;
			break;
		}

		if (false == is_failure)
		{
			std::cout << "YES" << std::endl;
		}
		else
		{
			std::cout << "NO" << std::endl;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include "stdio.h"
#include <string>
int si[10];
bool stack(int left, int right, int i){
	if (i == 9){
		if (left < si[i] || right < si[i]){
			return true;
		}
		else return false;
	}
	else if (left <= si[i]){
		return stack(si[i], right, i + 1);
	}
	else if (right <= si[i]){
		return stack(left, si[i], i + 1);
	}
	else return false;
}
int main(){
	int n;
	std::cin >> n;
	for (int e = 0; e<n; e++){
		for (int ai = 0; ai<10; ai++){
			std::cin >> si[ai];
		}
		if (stack(0, 0, 0) == true){
			std::cout << "YES\n";
		}
		else {
			std::cout << "NO\n";
		}
	}
}

C++: #include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int T;
int t[10];

bool solve(){
  int left=0,right=0;
  rep(i,10){
    if(t[i] < left && t[i] < right) return false;
    if(t[i] > left){
      if(t[i] > right && left < right){
        right = t[i];
      }
      else{
        left = t[i];
      }
    }
    else{
      right = t[i];
    }
  }
  return true;
}

int main(){
  cin>>T;
  while(T--){
    rep(i,10){
      cin>>t[i];
    }
    cout<<(solve() ? "YES" : "NO")<<endl;
  }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n,a,b,c;
	bool f;
	cin>>n;
	for(int i=0;i<n;i++){
		f=true;b=0;c=0;
		for(int j=0;j<10;j++){
			cin>>a;
			if(b>a&&c>a){
				f=false;
				break;
			}else if(b<a && c<a){
				if(b>=c)b=a;
				else c=a;
			}else if(b<a){
				b=a;
			}else if(c<a){
				c=a;
			}
		}
		if(f)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

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

using namespace std;

int main(){

	int n;
	cin>>n;

	int B=0,C=0;
	for(int i = 0; i < n; i++){
		bool f=false;
		vector<int> numList;
		for(int j = 0; j < 10; j++){
			int t;
			cin>>t;
			numList.push_back(t);
		}

		for(int j = 0; j < 10; j++){
			int num=numList[j];
			if(num>B&&num>C){
				if(num-B>num-C){
					C=num;
				}
				else
					B=num;
			}
			else if(num>B){
				B=num;
			}
			else if(num>C)
				C=num;
			else{
				f=true;
				cout<<"NO"<<endl;
				break;
			}
		}
		if(!f)
			cout<<"YES"<<endl;
	}

	return 0;
}

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

int main()
{
    int N;
    scanf("%d",&N);
    for(int i=0;i<N;++N) {
        int ball[10],index=0;
        for(int i=0;i<10;++i) {
            scanf("%d",&ball[i]);
        }
        while(index+2 <= 9) {
            if(ball[index] < ball[index+1]) {
                ++index;
                continue;
            } else if (ball[index] < ball[index+2]) {
                ++index;
                continue;
            } else {
                puts("NO");
                return -1;
            }
        }
        puts("YES");
        return 0;
    }
}

C++: #include<stdio.h>
int main(){
  int n;
  scanf("%d",&n);
  int ball[10];
  int i,j;
  for(j=0;j<n;j++){
    for(i=0;i<10;i++) scanf("%d",&ball[i]);
    int a=0,b=0;
    for(i=0;i<10;i++){
      if(a<ball[i]) a = ball[i];
      else if(b<ball[i]) b = ball[i];
      else{
	printf("NO\n");
	break;
      }
      if(i==9) printf("YES\n");
    }
  }
  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 if(d[j]<va[ca-1]||d[j]<vb[ca-1]){
				cout << "NO" << endl;
				goto FINLOOP;
			}
		}

	cout << "YES" << endl;
	FINLOOP:
		for (int i = 0; i < 10; i++) {
			va[i] = 0;
		}
		for (int i = 0; i < 10; i++) {
			vb[i] = 0;
		}
	}
	return 0;
}

C++: #include <cstdio>
#define loop(var,time) for (var = 0; var < (time); var++)
int balls[10];

bool dfs(int right, int left, int index) {\
    if (index == 10) { return true; }
    if (balls[index] > right) {
        if (dfs(balls[index], left, index + 1)) { return true; }
    }
    if (balls[index] > left) {
        if (dfs(right, balls[index], index + 1)) { return true; }
    }
    return false;
}

int main() {
    int n;
    int tmp,i;
    scanf("%d", &n);
    loop(tmp, n) {
        loop(i,10) {
            scanf("%d", &balls[i]);
        }
        if (dfs(0,0,0)) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
}

C++: #include<cstdio>
int main()
{
	int n;
	scanf("%d", &n);
	while (n--)
	{
		int a[10];
		int b[10], c[10];
		int i,p;
		int cas=0;
		for (i = 0; i < 10; i++)
		{
			scanf("%d", &a[i]);
			if (a[i] == 1)
				p = i;
		}
		for (i = 1; i < p;i++)
		if (a[i] < a[i - 1])
			cas = 1;

		for (i = p + 1; i < 10; i++)
		{
			if (a[i]>a[p - 1] && a[i]>a[p])
				a[p - 1] = a[i];
			if (a[i] > a[p] && a[i] < a[p - 1])
				a[p] = a[i];
			if (a[i] < a[p])
				cas = 1;
		}
		if (cas == 1)
		{
			printf("NO\n");
			break;
		}
		printf("YES\n");

	}
}

C++: #include<iostream>

int ball[10];
int ls = 0, rs = 0;
bool res = true;

int main(){
	int n;
	std::cin >> n;
	for (int j = 0; j < n; j++){
		for (int i = 0; i < 10; i++)std::cin >> ball[i];

		for (int i = 0; i < 10; i++){
			int d1 = ball[i] - ls, d2 = ball[i] - rs;

			if (d1 > 0 && d2 > 0){
				if (d1 <= d2)ls = ball[i];
				else rs = ball[i];
			}
			else if (d1 > 0 && d2 < 0)ls = ball[i];
			else if (d1 < 0 && d2 > 0)rs = ball[i];
			else res = false;
		}

		std::cout << (res ? "YES" : "NO") << std::endl;
	}
	return 0;
}