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 <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i,n)   for (int i = 0; i < (n); ++i)
#define SORT(a)    sort((a).begin(), (a).end());
#define UNIQ(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define FIND(a,x)  find((a).begin(), (a).end(), (x)) != (a).end()
#define REVERSE(a) reverse((a).begin(), (a).end());

using namespace std;
using ll = long long;
using P = pair<int,int>;

const int MOD = 1000000007; // 10^9 + 7

int a[10];

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

  if (a[i] > b && dfs(i + 1, a[i], c)) return true;
  if (a[i] > c && dfs(i + 1, b, a[i])) return true;
  return false;
}

bool solve() {
  return dfs(0, -1, -1);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n; cin >> n;
  REP(i, n) {
    REP(j, 10) cin >> a[j];
    cout << (solve() ? "YES" : "NO") << endl;
  }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl

int main() {
	lint N;
	cin >> N;
	rep(t, N) {
		bool yes = true;
		vector<lint>A(10);
		rep(i, 10) {
			cin >> A[i];
		}
		deque<lint>B;
		deque<lint>C;
		B.push_front(0);
		C.push_front(0);
		rep(i, 10) {
			if (i == 0) {
				B.push_front(A[i]);
			}
			else {
				if (B.front() < A[i] && A[i] < C.front()) {
					B.push_front(A[i]);
				}
				else if (C.front() < A[i] && A[i] < B.front()) {
					C.push_front(A[i]);
				}
				else if (B.front() < A[i] && C.front() < A[i]) {
					if (B.front() > C.front()) {
						B.push_front(A[i]);
					}
					else {
						C.push_front(A[i]);
					}
				}
				else {
					cout << "NO" << endl;
					yes = false;
					break;
				}
			}
		}
		if (yes == true) {
			cout << "YES" << endl;
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to) 
void dfs(stack<int> s, stack<int> r, stack<int> l, bool &f) {
	if(s.empty()) {
		f = 1;
		return;
	}
	int x = s.top();
	if(r.empty() || r.top() < x) {
		s.pop();
		r.push(x);
		dfs(s,r,l,f);
		r.pop();
		s.push(x);
	}
	if(l.empty() || l.top() < x) {
		s.pop();
		l.push(x);
		dfs(s,r,l,f);
		l.pop();
		s.push(x);
	}
}
int main() {
	int n;
	cin >> n;
	while(n--) {
		int a[10];
		stack<int> s;
		rep(i,10) {
			cin >> a[i];
		}
		rep(i,10) {
			s.push(a[10-i-1]);
		}
		stack<int> r;
		stack<int> l;
		bool f = 0;
		dfs(s,r,l,f);
		if(f) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

int main(){
  int n;
  int a[10];
  cin>>n;
  while(n--){
    for(int i=0;i<10;i++) cin>>a[i];
    for(int i=0;i<8;i++){
      if(a[i]>a[i+1]&&a[i]>a[i+2]&&a[i+1]>a[i+2]){
	cout<<"NO"<<endl;
	break;
      }
      if(i==7) cout<<"YES"<<endl;
    }
  }
  return 0;
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;

int pow(int a,int n){
	if(n <= 0){
		return 1;
	}
	return a * pow(a,n - 1);
}

int main(){
	int n;
	int a[10];
	int ans1 = 0;
	int ans2 = 0;
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			scanf("%d",&a[j]);
		}
		for(int j = 0; j < 10; j++){
			if(ans1 >= ans2 && ans1 < a[j]){
				ans1 = a[j];
			}else if(ans2 > ans1 && ans2 < a[j]){
				ans2 = a[j];
			}else if(ans1 < a[j]){
				ans1 = a[j];
			}else if(ans2 < a[j]){
				ans2 = a[j];
			}else{
				printf("NO\n");
				break;
			}
			if(j == 9){
				printf("YES\n");
			}
		}
	}
	///////////////////////////////////
	//Sleep(200000);///////////////////// 提出するときは必ず外す！
	///////////////////////////////////
	return 0;

}

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

int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    int a, b = 0, c = 0;
    bool f = true;
    for (int i = 0; i < 10; ++i) {
      scanf("%d", &a);
      if (b < a) b = a;
      else if (c < a) c = a;
      else {
        puts("NO");
        f = false;
        break;
      }
    }
    if (f) puts("YES");
  }
}

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

using namespace std;

int main(){

	int n;
	cin>>n;

	int B=0,C=0;
	for(int i = 0; i < n; i++){
		bool f=false;
		for(int j = 0; j < 10; j++){
			int num;
			cin>>num;
			if(num>B&&num>C){
				if(num-B>num-C){
					C=num;
				}
				else
					B=num;
			}
			else if(num>B){
				B=num;
			}
			else if(num>C)
				C=num;
			else if(!f){
				f=true;
				cout<<"NO"<<endl;
//				break;
			}
		}
		if(!f)
			cout<<"YES"<<endl;
	}

	return 0;
}

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

int ball[10];

bool solve(int i, int a, int b){
	if (i == 10) return true;
	bool ans = false;
	if (a < ball[i]) ans = solve(i + i, ball[i], b);
	if (b < ball[i])ans = solve(i + i, a, ball[i]);
	return ans;
}

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

	for (int i = 0; i < n; i++){
		for (int j = 0; j < 10; j++){
			cin >> ball[j];
		}
		if (solve(0, 0, 0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;
}
//beatmaniaIIDX 23th copula

C++: #include <iostream>

using namespace std;

int main()
{
    int m;
    cin>>m;
    for(int l = 1; l <= m; ++l)
    {
        int llast = 0;
        int rlast = 0;
        int tmp;
        bool flag = true;
        for(int i = 0; i < 10; ++i)
        {
            cin>>tmp;
            if(tmp > llast)
            {
                if(tmp > rlast)
                {
                    if(tmp - llast < tmp - rlast)
                        llast = tmp;
                    else
                        rlast = tmp;
                }
                else
                    llast = tmp;
            }
            else if(tmp > rlast)
                rlast = tmp;
            else
                flag = false;
        }
        if(flag)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}