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<cstdio>
#include<string>
#include<vector>
using namespace std;


int res=0;

int saiki(int ball[],int ttB,int ttC,int res){
	if(res==10)return res;
	if(ball[res]>ttB){
		return saiki(ball,ball[res],ttC,res+1);
	}
	if(ball[res]>ttC){
		return saiki(ball,ttB,ball[res],res+1);
	}
	return res;
}

int main(void){
	int a,b;
	int ball[11];
	int ttB=0,ttC=0;
	int n;
	scanf("%d",&n);
	for(a=0;a<n;a++){
		for(b=0;b<10;b++){
			ball[b]=0;
		}
		ttB=0;
		ttC=0;
		res=0;
		for(b=0;b<10;b++){
			scanf("%d",&ball[b]);
		}
		res=max(res,saiki(ball,ttB,ttC,res));
		if(res==10)printf("YES\n");else printf("NO\n");
	}
	return 0;
}

C++: #include <stdio.h>
int main(void)
{
	int a,b,c[10]={0},d,e[10]={0},f,g,i;
	scanf("%d",&a);
	for (b=0;b<a;b++)
	{
		for (i=0;i<10;i++)
		{
			scanf("%d",&f);
			c[i]=f;
		}
		for (g=1;g<8;g++)
		{
			if (c[g-1]<c[g]||c[g-1]<c[g+1])
			{
				e[g-1]=0;
			}
			else 
			{
				e[g-1]=1;
			}
		}
		if (e[0]==0&&e[1]==0&&e[2]==0&&e[3]==0&&e[4]==0&&e[5]==0&&e[6]==0&&e[7]==0&&e[8]==0&&e[9]==0)
		{
			printf("YES\n");
		}
		else 
		{
			printf("NO\n");
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string.h>

using namespace std;

int a[12];
int n;

bool dfs(int i, int left, int right){
    if(i == 10){
        return true;
    }

    if(a[i] > left && dfs(i + 1, a[i], right)){
        return true;
    }
    if(a[i] > right && dfs(i + 1, left, a[i])){
        return true;
    }
    return false;
}

void solve(){
    for(int i = 0; i < 10; ++i){
        cin>>a[i];
    }

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

int main(){
    cin>>n;
    while(n--){
        solve();
    }
    return 0;
}

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

string solve(int a, int b, int f) {
	if (f == 11) return "YES";
	
	int x;
	cin >> x;
	
	if (x > a) return solve(x, b, f + 1);
	if (x > b) return solve(a, x, f + 1);

	return "NO";
}

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

	for (int i = 0; i++ < n;) {
		cout << solve(0, 0, 0) << endl;
	}
	return 0;
}

C++: #include<stdio.h> 
#include<string.h>
int s[12];
bool p[12];
int flag,flag1,A;
void dfs(int com,int cur)
{
	if(cur==10)
	return;
	if(s[com]<=s[cur] && !p[cur])
		p[com]=true,p[cur]=true,dfs(cur,cur+1);
	else
		{
			if(flag1)
			flag1=0,A=cur;
	    	dfs(com,cur+1);	
		}
}
int main()
{
	int n;
	scanf("%d",&n);
	while(n--)
	{
		flag=1,flag1=1;
		memset(p,false,sizeof(p));
		for(int i=0;i<10;i++)
		scanf("%d",&s[i]);
		dfs(0,1);
		dfs(A,A+1);
		for(int i=0;i<10;i++)
			if(!p[i])
				flag=0;
		if(flag)
		printf("YES");
		else
		printf("NO");
		printf("\n");
	 } 
	return 0;
 }

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

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

		int left = 0, right = 0;
		int *pMin = NULL, *pMax = NULL;
		bool result = true;
		for(i = 0; i < N; i++)
		{
			pMin = &(left < right ? left : right);
			pMax = &(left < right ? right : left);

			if(*pMin > a[i])
			{
				result = false;
				break;
			}
			else if(*pMax < a[i])
				*pMax = a[i];
			else
				*pMin = a[i];
		}
		cout << (result ? "YES" : "NO") << endl;;
	}
	return 0;
}

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

int main(){
  int n;
  int tmp[10];

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

    for(int j = 0 ; j < 9 ; j++){
      if(!(tmp[j] < tmp[j+1])) cnt++;
    }
    
    //cout << cnt << endl;

    if(cnt <= 2) cout << "YES" << endl;
    else cout << "NO" <<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <climits>
#include <utility>

#define PRINT(STR) cout << STR << endl;
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define SPACE " "

typedef long long ll;

using namespace std;

int nextInt() { int n = -1; cin >> n; return n; }
double nextDouble() { double d = -1; cin >> d; return d; }
ll nextll() { ll n = -1; cin >> n; return n; }
string nextString() { string str; cin >> str; return str; }

int INF = 1LL << 25;
double EPS = 1e-9;
int numofbits(int bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

// BEGIN //////////////////////////////////////////////////////////////
int main() {
  int N = nextInt();
  REP(i, N) {
    stack<int> bs, cs;
    bool flag = true;
    bs.push(0);
    cs.push(0);
    REP(j, 9) {
      int a = nextInt();
      if (bs.top() < a) {
        if (cs.top() < a) {
          if (bs.top() > cs.top()) {
            bs.push(a);
          } else {
            cs.push(a);
          }
        } else {
          bs.push(a);
        }
      } else if (cs.top() < a) {
        cs.push(a);
      } else {
        flag = false;
        break;
      }
    }
    if (flag) {
      PRINT("YES");
    } else {
      PRINT("NO");
    }
  }
	return 0;
}
// END   //////////////////////////////////////////////////////////////

C++: #include <iostream>
#define _for(i,a,b) for(int i = (a); i < b; ++i)
#define _rep(i,a,b) for(int i = (a); i <= b; ++i)
using namespace std;
int a[10+2];
bool flag = 0;
void dfs(int i, int l, int r){
    if(flag) return;
    if(i == 10) {
        flag = 1;
        return;
    }
    if(a[i] > l) dfs(i+1, a[i], r);
    if(a[i] > r) dfs(i+1, l, a[i]);
}
int main(){
    int n;
    cin>>n;
    _for(len,0,n){
        _for(i,0,10) cin>>n;
    }
    dfs(0,0,0);
    if(flag) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int a[20], b[20], c[20];
		for(int j = 0; j < 10; j++){
			cin >> a[j]; 
		}

		int ai = 0, bi = 0, ci = 0;
		b[0] = 0;
		c[0] = 0;
		while(ai < 9){
			if(b[bi] > c[ci]){
				if(a[ai] > b[bi]){
					bi++;
					b[bi] = a[ai];
					ai++;
				}else if(a[ai] > c[ci]){
					ci++;
					c[ci] = a[ai];
					ai++;
				}else{
					break;
				}
			}else{
				if(a[ai] > c[ci]){
					ci++;
					c[ci] = a[ai];
					ai++;
				}else if(a[ai] > b[bi]){
					bi++;
					b[bi] = a[ai];
					ai++;
				}else{
					break;
				}
			}
		}

		if(ai == 9){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}