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<vector>
#include<string>
#pragma region defins
#define ll long long
#define loop(i,n) for (int i = 0; i < n; i++)
#define loops(i,f,n) for (int i = (f); i < n; i++)
#define INF 100000000000000
#define sort(a) sort(a.begin(),a.end())
#define rsort(a) sort(a.rbegin(),a.rend())
using namespace std;
#pragma endregion
vector<int> balls(10);
bool dfs(int now, int btop, int ctop)
{
	if (now == 9)return true;
	if (balls[now] > btop)dfs(now + 1, balls[now], ctop);
	else if (balls[now] > ctop)dfs(now + 1, btop, balls[now]);
	else return false;
}

int main()
{
	int n; cin >> n;
	loop(i, n)
	{
		loop(i, 10)cin >> balls[i];
		cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
	}
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

const int MAX_N = 10;
const int n = MAX_N;
int t;
int a, b, c;

int main()
{
  cin >> t;

  while(t--){
    bool ok = true;
    cin >> c;
    b = 0;
    rep(i, n){
      cin >> a;
      if(b > c) swap(b, c);
      if(a > c){ c = a;  continue; }
      if(a > b){ b = a;  continue; }
      ok = false;
      break;
    }
    puts(ok ? "YES" : "NO");
  }

  return 0;
}

C++: #include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>


using namespace std;

#define FOR(x) for(int i = 0; i < x; i++)

stack<short> x, y;
short a[10], n, j, i;

bool solve(short c, bool judge){
	if(c == 10) return true;
	if(x.top() < a[c]){
		x.push(a[c]);
		if(solve(c + 1, true)) return true;
	}
	if(y.top() < a[c]){
		y.push(a[c]);
		if(solve(c + 1, false)) return true;
	}
	if(judge) x.pop();
	else y.pop();
	return false;
}

int main(){
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		x.push(0);
		y.push(0);
		for(j = 0; j < 10; j++)
			scanf("%d", &a[j]);
		if(solve(0, true)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  for(int cs = 0 ; cs < n ; cs++){
    int A[10];
    for(int i = 0 ; i < 10 ; i++) cin >> A[i];

    int B = 0, C = 0;
    bool flag = 1;
    
    for(int i = 0 ; i < 10 ; i++){
      if(A[i] > B) B = A[i];
      else if(A[i] > C) C = A[i];
      else flag = 0;
      
      if(B < C) swap(B, C);
    }
    
    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int bl[10];
    bool ok[n];
    for (int i=0; i<n; i++) ok[i]=false;
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<10; j++)
        {
            cin>>bl[j];
        }
        if ((bl[0]<bl[2] && bl[2]<bl[4] && bl[4]<bl[6] && bl[6]<bl[8]) && (bl[1]<bl[3] && bl[3]<bl[5] && bl[5]<bl[7] && bl[7]<bl[9])) ok[i]=true;
    }
    for (int i=0; i<n; i++)
    {
        if (ok[i]) cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}

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

using namespace std;

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


  for(int q=0; q<n;q++) {
    
    vector <int> ball;
    
    ball.resize(10);
    for(int i=0;i<10;i++) cin >> ball[i];
    reverse(ball.begin(),ball.end());
    
    int a[10] = {0},b[11] = {0};
    a[0] = ball.back();
    ball.pop_back();
   int ac = 1;
   int bc = 1;
   int t;

    cout << "t:a:b" << endl;
    while(ball.empty() == false) {

      t = ball.back();
      ball.pop_back();
      // cout << t << endl;
      cout << t <<":"<< a[ac-1]<<":" << b[bc-1]<<endl;
      
      if(t > a[ac-1] && a[ac-1] >= b[bc-1]) {
	a[ac] = t;
	ac++;
      }
      else if(t > b[bc-1]) {
	b[bc] = t;
	bc++;
      } else break;
    }

    //  for(int i=0;i<ac;i++) cout << a[i] << endl;
    
    if(ac+bc == 11) cout << "YES" << endl << endl;
    else cout << "NO" << endl;

    ball.clear();

  }

  return 0;

}

C++: #include<iostream>
int main()
{
	int N;
	std::cin >> N;
	for (int i = 0; i < N; i++)
	{
		int b_back = 0, c_back = 0;
		bool is_OK = true;
		for (int j = 0; j < 10; j++)
		{
			int num;
			std::cin >> num;
			if (num < b_back && num < c_back)
			{
				is_OK = false;
			}
			else if (num > b_back && num < c_back)
			{
				b_back = num;
			}
			else if (num < b_back && num > c_back)
			{
				c_back = num;
			}
			else
			{
				if (b_back > c_back)
				{
					b_back = num;
				}
				else
				{
					c_back = num;
				}
			}
		}
		std::cout << (is_OK ? "YES" : "NO") << std::endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
#define INF 40
using namespace std;

int ball[12];
int flag ;
stack<int> A, B;


void dfs(int s)
{
	if (s >= 10)
	{
		flag = 1;
		return;
	}
	else if (ball[s] < A.top() && ball[s] < B.top())
	{
		return;
	}
	else {
		if (ball[s] > A.top())
		{
			A.push(ball[s]);
			dfs(s+1);
			A.pop();
		}
		if (ball[s] > B.top())
		{
			B.push(ball[s]);
			dfs(s+1);
			B.pop();
		}
	}
}


int main()
{
	int n;
	while (~scanf("%d",&n))
	{
		while (n--)
		{
			flag = 0;
			while (!A.empty())
			{
				A.pop();
			} 
			while (!B.empty())
			{
				B.pop();
			}
			A.push(0);
			B.push(0);
			memset(ball, 0, sizeof(ball));
			for (int i = 0;i < 10;i++)
			{
				scanf("%d", &ball[i]);
			}
			dfs(0);
			if (flag) printf("YES\n");
			else printf("NO\n");
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int a[12];
int n;
bool dfs(int b, int c, int ct) {
  if(ct == 10) return true;
  if(b < a[ct] && dfs(a[ct], c, ct + 1)) return true;
  if(c < a[ct] && dfs(b, a[ct], ct + 1)) return true;
  return false;
}

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