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 <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#define INF 1000000000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define all(x) (x).begin(),x.end()
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

int a[11];

int dfs(int left,int right,int cnt){
  //cout<<left<<" "<<right<<" "<<cnt<<endl;
  if(cnt==10)return cnt;
  if(left<a[cnt]&&right<a[cnt]) cnt=max(dfs(a[cnt],right,cnt+1),dfs(left,a[cnt],cnt+1));
  else if(left<a[cnt])cnt=dfs(a[cnt],right,cnt+1);
  else if(right<a[cnt]) cnt=dfs(left,a[cnt],cnt+1);
  
  return cnt;
}

int main(){
  int n;
  cin>>n;
  rep(i,n){
    rep(j,10)cin>>a[j];
    //rep(j,10)cout<<a[i]<<" ";
    //cout<<endl;
    if(dfs(a[0],-INF,1)==10)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
    int n,ball;
    cin>>n;
    for(int i=0; i<n; i++){
        int a=0,b=0,flg=0;
        for(int j=0; j<10; j++){
            cin>>ball;
            if(ball>a) a=ball;
            else if(ball>b) b=ball;
            else flg=1;
        }
        cout<<(flg==0?"YES":"NO")<<endl;
    }
}

C++: #include <stdio.h>
#include <vector>
#include <iostream>

using namespace std;

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

	bool flag = true;

	int n;
	cin >> n;
	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
							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;
	}
}

C++: #include<stdio.h>

#include<string.h>

int a[13], vis[13], flag;

void dfs(int x, int l, int r)
{

    int i;

    if(x == 11) return; 

    if(flag) return ;

    if(a[x] > l) dfs(x + 1, a[x], r);

    else  if(a[x] > r) dfs(x + 1, l, a[x]);

    else  {flag = 1; return;}
}

int main()

{

	int T, i, j, k;

	scanf("%d", &T);

	while(T--)

	{

		flag = 0;

		for(i = 1; i <= 10; i++)

		scanf("%d", &a[i]);

		memset(vis, 0, sizeof(vis));

		dfs(1, 0, 0);

		if(flag) printf("NO\n");

		else printf("YES\n");

	}

return 0;

}

C++: #include <iostream>
using namespace std;
int main (){
	int N;
	int L = 0;
	int R = 0;
	cin >> N;
	int T[N][10];
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < 10; ++j)
		{
			cin >> T[i][j];			
		}
	}
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < 10; ++j)
		{
			if(L < T[i][j]){
				L = T[i][j];
				if(j == 9){
					cout << "YES\n";
				}
			}else if(R < T[i][j]){
				R = T[i][j];
				if(j == 9){
					cout << "YES\n";
				}
			}else{
				cout << "NO\n";
				break;
			}
		}
	}
	return 0;
}

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

using namespace std;

int main(void) {
    int N, a, b, c;
    cin >> N;
    for (; N--; ) {
        b = c = 0;
        bool ok = true;
        for (int i = 0; i < 10; i++) {
            cin >> a;
            if (a < b && a < c) {
                ok = false;
                break;
            } else if (a > b && b > c) {
                b = a;
            } else {
                c = a;
            }
        }
        cout << (ok ? "YES" : "NO") << endl;
    }
    return 0;
}

C++: 
#include <cstdio>

const int MAXN = 15;
int a[MAXN], flag;

void dfs(int p, int b, int c)
{
    if(p == 10)
    {
        flag = 1;
        return;
    }
    if(a[p] > b) dfs(p + 1, a[p], c);
    if(a[p] > c) dfs(p + 1, b, a[p]);
}

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

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

int n;
int has_put;
int a[10];

int main() {
    scanf("%d", &n);
    for (int T=0; T<n; T++) {
        for (int i=0; i<10; i++) {
            scanf("%d", &a[i]);
        }

        has_put = 0;
        for (int bit=0; bit<1024; bit++) {
            int pre1 = -1;
            int pre2 = -1;
            int possible = 1;

            for (int i=0; i<10; i++) {
                if ((bit>>i)&1) {
                    if (a[i] < pre1) {
                        possible = 0;
                        break;
                    }
                    pre1 = a[i];
                } else {
                    if (a[i] < pre2) {
                        possible = 0;
                        break;
                    }
                    pre2 = a[i];
                }
            }

            if (possible) {
                puts("YES");
                has_put = 1;
                break;
            }
        }

        if (!has_put) {
            puts("NO");
        }
    }
}

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

int main() {
  int n;
  cin >> n;
  int t;
  int i, j;
  for (i = 0; i < n; i++) {
    queue<int> q;
    for (j = 0; j < 10; j++) {
      cin >> t;
      q.push(t);
    }
    stack<int> a, b;
    a.push(q.front());
    q.pop();
    b.push(0);
    while (q.size()) {
      if (a.top() < q.front()) {
        a.push(q.front());
      } else if (b.top() < q.front()) {
        b.push(q.front());
      } else {
        cout << "NO" << endl;
        break;
      }
      q.pop();
      if (q.size() == 0) {
        cout << "YES" << endl;
      }
    }
  }
  return 0;
}

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

int n,b[10];

bool dfs(int l, int r, int c)
{
	if(c==10) return true;

	if(l<b[c])
	{
		if(dfs(b[c],r,c+1)) return true;
	}
	if(r<b[c])
	{
		if(dfs(l,b[c],c+1)) return true;
	}
	return false;
}


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