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<algorithm>
#include<iomanip>
#include<string>
#include<cmath>
#include<stack>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn =  10 + 8;

int n;
int g[maxn];

int main()
{
    scanf("%d", &n);
    while(n--)
    {
        memset(g, 0, sizeof g);
        stack<int> p,q;
        p.push(0); q.push(0);
        for(int i = 0; i < 10; ++i) cin >> g[i];
        int i = 0;
        while(true)
        {
            if(i == 10) break;
            if(g[i] > p.top()) {p.push(g[i]);}
            else {
                if(g[i] > q.top())
                {
                    q.push(g[i]);
                }
            }
            i++;
        }
        if(p.size() + q.size() == 12) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int tama[10];

bool Haireruka(int i,int left,int right){
	if(tama[i]<left){
		if(Haireruka(i+1,tama[i],right))return true;
	}
	if(tama[i]<right){
		if(Haireruka(i+1,left,right))return true;
	}
	return false;
}

int main(){
	for(int i=0;i<10;i++){
		cin>>tama[i];
	}
	if(Haireruka(0,0,0))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

C++: #include<cstdio>
int main()
{
    int N,ba[10],B,C,ju;
    scanf("%d",&N);
    for(int i=0;i<N;i++)
    {
        ju=0;
        B=0;
        C=-1;
        for(int j=0;j<10;j++)
        {
            scanf("%d",&ba[j]);
        }
        for(int j=0;j<10;j++)
        {
            if(ba[j]>B&&ba[j]>C)
            {
                if(B>C)B=ba[j];
                else C=ba[j];
            }
            else if(ba[j]>B)B=ba[j];
            else if(ba[j]>C)C=ba[j];
            else ju++;
        }
        if(ju==0)printf("YES\n");
        if(ju>=1)printf("NO\n");
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

vector<int> a;
stack<int> b, c;

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

	bool res1 = false, res2 = false;

	if (b.empty()) {
		b.push(a[i]);
		res1 = dfs(i + 1);
		b.pop();
    } else if(c.empty()) {
		c.push(a[i]);
		res2 = dfs(i + 1);
		c.pop();
    } else if (b.size() && c.size()) {
        if (b.top() < a[i]) {
            b.push(a[i]);
            res1 = dfs(i + 1);
            b.pop();
        } else if (c.top() < a[i]) {
            c.push(a[i]);
            res2 = dfs(i + 1);
            c.pop();
        }
    }

	return res1 || res2;
}

int main()
{
	int n; cin >> n;

	while (n--) {
		a.clear();
		while (b.size()) b.pop();
		while (c.size()) c.pop();

		for (int i = 0; i < 10; ++i) { int v; cin >> v; a.push_back(v); }

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

C++: #include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
int n;
int ba[10];
bool bfs(int l,int r,int x)
{
	if(x==10) return true;
	if(ba[x]<l&&ba[x]<r) return false;
	if(l<ba[x]&&bfs(ba[x],r,x+1)) return true;
	if(r<ba[x]&&bfs(l,ba[x],x+1)) return true;
	return false;
}

int main()
{
	cin>>n;
	for(;n>0;n--){
		for(int i=0;i<10;i++){
			scanf("%d",&ba[i]);
		}
		if(bfs(0,0,0)) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

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

int B, C, num[20], b, c;

string dfs(int x){
    if(x == 10)  return "YES";
    else if(B>num[x]){
        if(C<num[x]){
            C = num[x];
            return dfs(x+1);
        }
        else return "NO";
    }
    else if(B<num[x]){
        B = num[x];
        return dfs(x+1);
    }
}

int main(void){
    int N;
    while(cin >> N){
    B = 0;
    C = 0;
    for(int i=0; i<10; i++){
        cin >> num[i];
    }
    string str = dfs(0);
    cout << str << endl;
    }
    return 0;
}

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

int data[10];
bool sumilation(int left,int right,int num){
	if(num == 10) return true;
	
	if(left < data[num]){
		if(sumilation(data[num],right,num+1)) return true;
	} 
	if(right < data[num]){
		if(sumilation(left,data[num],num+1)) return true;
	}
	return false;
	
	
}

int main(){
	int times;
	cin >> times;
	for(int i=0;i<times;i++){
		for(int k=0;k<10;k++)
		cin >> data[k];
		if(sumilation(0,0,0) == true){
		cout << "YES" << endl;
		} else {
		cout << "NO" <<endl;
		}
		
		
	}

}

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

int main(){
  int N; 
  cin >> N;

  for(int i=0; i<N; i++){
    vector<int> balls(10);
    for(int j=0; j<10; j++) cin >> balls[j];

    priority_queue<int> A, B;
    A.push(0); B.push(0);

    bool flag = true;
    for(int j=0; j<10; j++){
      if(A.top() > balls[j] && B.top() > balls[j]){
        if(flag) cout << "NO" << endl; 
        flag = false;
      } else if (A.top() < balls[j] && B.top() > balls[j]){
        A.push(balls[j]);
      } else if (A.top() > balls[j] && B.top() < balls[j]){
        B.push(balls[j]);
      } else {
        if(A.top() > B.top()){
          A.push(balls[j]);
        } else {
          B.push(balls[j]);
        }
      }
    }

    if(flag) cout << "YES" << endl;
  }
}

C++: #include <iostream>
using namespace std;
const int N = 10;
int main(){
    int n;
    cin >> n;
    while(n--) {
        bool ans = true;
        int a, b=-1, c=-1;
        for(int i=1; i<=N; i++) {
            cin >> a;
            if(ans) {
                if(a > b)
                    b = a;
                else if(a > c)
                    c = a;
                else
                    ans = false;
       }
    }
    if(ans) puts("YES");
    else puts("NO");
}
}

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

using namespace std;

int main() {
	vector<int> left;
	vector<int> right;
	vector<int> all;

	bool flag = true;

	int n;
	cin >> n;
	if (n == 0) return -1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else  if (all.size() == n*j) {

						}
						else {
							flag = false;
						}
						
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}

		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
		flag = true;
	}

	return 0;
}