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<algorithm>
#include<cstring>
using namespace std;
int main(){
  int ball[11],n,a[11],b[11];
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin >> ball[j];
    }
    int a_num,b_num;
    a_num = b_num = 0;
    for(int j=0;j<10;j++){
      if(j == 0){
	a[a_num] = ball[j];
	a_num++;
      }else if(ball[j]>a[a_num-1] || ball[j]>b[b_num-1]){
	// bの方が差が小さいとき
	if(ball[j]-a[a_num-1] > ball[j]-b[b_num-1]){
	  b[b_num] = ball[j];
	  b_num++;
	}else {
	  a[a_num] = ball[j];
	  a_num++;
	}
      }
    }
    if(a_num+b_num==10)cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

C++: #include <cstdio>

int main(){
  int n;
  scanf("%d",&n);
  while(n--){
    int a=0,b=0,m;
    for(int i=0; i<10; i++){
      scanf("%d",&m);
      if(a<m)
	a=m;
      else if(b<m)
	b=m;
      else{
	printf("NO\n");
	while(getchar()!='\n');
	goto hoge;
      }

      if(a<b){
	int c; 
	c=a;a=b;b=c;
      }
    }
    printf("YES\n");
  hoge: ;
  }
}

C++: #include <stdio.h>

int main(void)
{
	int tubeM[10];
	int tube1[10], tube2[10];
	int i, j, k;
	int n;
	int ans;
	
	for (i = 0; i < 10; i++){
		tube2[i] = 0;
	}
	
	scanf("%d", &n);
	
	while(n){
		for (i = 0; i < 10; i++){
			scanf("%d", &tubeM[i]);
		}
		
		tube1[0] = tubeM[0];
		for (i = 1, j = 0, k = 0; i < 10; i++){
			if (tubeM[i] > tube1[j]){
				tube1[j + 1] = tubeM[i];
				j++;
			}
			else {
				tube2[k] = tubeM[i];
				k++;
			}
		}
		
		ans = 0;
		for (i = 1; tube2[i] != 0; i++){
			if (tube2[i - 1] > tube2[i]){
				ans = 1;
				break;
			}
		}
		
		if (ans == 0){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
		
		n--;
	}
	
	return (0);
}

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

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("%lld", &x); return (x); }

int main()
{
	int n;
	int containerTop[2];
	bool flag;
	n = in();
	loop(i, 0, n)
	{
		containerTop[0] = containerTop[1] = -1;
		flag = true;
		
		loop(j, 0, 10)
		{
			int ball = in();
			if( containerTop[0] < ball )
			{
				containerTop[0] = ball;
			}
			else if( containerTop[1] < ball )
			{
				containerTop[1] = ball;
			}
			else
			{
				flag = false;
			}
		}
		printf("%s\n", flag ? "YES" : "NO");
	}
	return (0);
}

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

int main() {
  int n; cin >> n;
  while (n--) {
    vector<int> a(10); for (int i = 0; i < 10; ++i) cin >> a[i];
    stack<int, deque<int>> s0({a[0]}), s1({0});
    for (int i = 1; i < 10; ++i) {
      int m = 10, mpos = -1;
      if (s0.top() < a[i]) {
        if (a[i] - s0.top() < m) {
          m = a[i] - s0.top();
          mpos = 0;
        }
      }
      if (s1.top() < a[i]) {
        if (a[i] - s1.top() < m) {
          m = a[i] - s1.top();
          mpos = 1;
        }
      }
      if (mpos == -1) {
        cout << "NO" << endl;
        break;
      }
      ( (mpos) ? s1 : s0 ).push(a[i]);
      if (i == 9) cout << "YES" << endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#include<cstdio>
#define MAXN 2555
#define INF 0x3f3f3f3f
#define v first
#define b second
using namespace std;
queue<int>q;
queue<int>p;
int s[15];
bool flag;
void dfs(int x)
{
   if(x==10)
   {
      flag=true;
      return ;
   }
   if(s[x]>q.front())
   {
      q.push(s[x]);
      dfs(x+1);
      q.pop();
   }
   if(s[x]>p.front())
   {
      p.push(s[x]);
      dfs(x+1);
      p.pop();
   }
   return ;
}
int main()
{
   int t;
   scanf("%d",&t);
   while(t--)
   {
      flag=false;
      for(int i=0;i<10;i++)
         scanf("%d",&s[i]);
      q.push(0);
      p.push(0);
      dfs(0);
      if(flag)
         cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
   }
   return 0;
}

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

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

    cin >> n;

    while( n-- )
    {
        stack<int> b, c;
        b.push(0);
        c.push(0);

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

        for( int i = 0; i < 10; i++ )
        {
            if( b.top() == 0 || c.top() == 0 )
            {
                if( a[i] > b.top() )
                    b.push(a[i]);
                else
                    c.push(a[i]);
            }
            else if( b.top() > c.top() )
            {
                if( a[i] > b.top() )
                    b.push(a[i]);
                else
                {
                    if( a[i] > c.top() )
                        c.push(a[i]);
                    else
                    {
                        cout << "NO" << endl;
                        break;
                    }
                }
            }
            else
            {
                if( a[i] > c.top() )
                    c.push(a[i]);
                else
                {
                    if( a[i] > b.top() )
                        b.push(a[i]);
                    else
                    {
                        cout << "NO" << endl;
                        break;
                    }
                }
            }
        }
        if( b.size() + c.size() == 12 )     //初期値0が2つのスタックに入っている。
            cout << "YES" << endl;
    }
    return 0;
}

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

#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))

int n;
int a[11];

bool rec(int idx, int l, int r) {
   if (idx == 10) return true;

   bool x = false, y = false;
   int val = a[idx];
   if (l < val) x = rec(idx+1, val, r);
   if (r < val) y = rec(idx+1, l, val);

   return x || y;
}

int main() {
   cin >> n;
   while (n--) {
      rep (i, 10) cin >> a[i];
      puts(rec(0, -1, -1)?"YES":"NO");
   }

   return 0;
}