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 <vector>
int ball[10];
int left = 0,right = 0;
bool dfs(int de,int left, int right){//??????????????§???????????????
	if(de == 10)return true;
	if(left < ball[de] ){
		left = ball[de];
		return dfs(de + 1,left,right);
	}
	if(right < ball[de]){
		right = ball[de];
		return dfs(de + 1,left,right);
	}
	return false;
}

int main(){
	int n;
	std::cin >> n;
	while(n--){
		for(int i = 0; i < 10; ++i){
			std::cin >> ball[i];
		}
		left = 0, right = 0;
		if(dfs(0,0,0))std::cout << "YES" << std::endl;
		else std::cout << "NO" << std::endl;
	}
}

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


int main()
{
	int n;
	cin >> n;
	int a[11],min_a=0, min_b=0;
	bool flag=true;
	while (n--)
	{
		for (int i = 0; i < 10; i++)
			cin >> a[i];
		for (int j = 0; j < 10; j++)
		{
			if (a[j] >= min_a)
			{
				min_a = a[j];
			}
			else if (a[j] >= min_b)
			{
				min_b = a[j];
			}
			else
			{
				flag = false;
			}
		}
		if (flag==true)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
    return 0;
}

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

using namespace std;

int main() {

	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int A[10];
		for (int j = 0; j < 10; j++)cin >> A[j];
		stack<int> B, C;
		B.push(A[0]);
		for (int j = 1; j < 10; j++) {
			if (B.top() < A[j])B.push(A[j]);
			else if (C.empty() == 1)C.push(A[j]);
			else if (C.top() < A[j])C.push(A[j]);
			else {
				cout << "NO" << endl;
				break;
			}
			if (j == 9)cout << "YES" << endl;
		}
	}

	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

int n;
const int m = 10;
int *data;
int *lp;
int *rp;

//return...fail:0, success:1
bool dfs(int i, int l, int r)
{
	if (i == m)
		return true;

	if (i<m && l<m && lp[l-1]<data[i]) {
		lp[l] = data[i];
		if (dfs(i+1, l+1, r))
			return true;
	}

	if (i<m && r<m && rp[r-1]<data[i]) {
		rp[r] = data[i];
		if (dfs(i+1, l, r+1))
			return true;
	}

	return false;
}

int main()
{
	int i, j;
	data = (int *)calloc(m, sizeof(int));
	lp = (int *)calloc(m, sizeof(int));
	rp = (int *)calloc(m, sizeof(int));
	
	scanf("%d ", &n);
	for (i=0; i<n; i++) {
		for (j=0; j<m; j++)
			scanf("%d ", &(data[j]));

		memset(lp, 0, sizeof(int));
		memset(rp, 0, sizeof(int));

	lp[0] = data[0];
	if (dfs(1, 1, 0))
		puts("YES");
	else
		puts("NO");

/*
		//check input
		for (j=0; j<m; j++)
			printf("%d ", data[j]);
		puts("");
*/
	}

	free(data);
	free(lp);
	free(rp);
	return 0;
}

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

int A[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int B[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

bool isSorted(void)
{
	int i = 1;
	while(A[i]!=0 && i<=9)
	{
		if(A[i] < A[i-1]) return false;
		i++;
	}

	i = 1;
	while(B[i]!=0 && i<=9)
	{
		if(B[i] < B[i-1]) return false;
		i++;
	}

	return true;
}

int main(void)
{
	int n;
	cin >> n;
	bool enable = false;
	for(int i=0; i<n; i++)
	{
		int X[10];
		for(int j=0; j<10; j++)
			cin >> X[j];

		for(int j=0; j<1024; j++)
		{
			int a = 0, b = 0;
			int e = 1;
			for(int k=0; k<10; k++)
			{
				if( j & e )
				{
					A[a] = X[k];
					a++;
				}
				else
				{
					B[b] = X[k];
					b++;
				}
				e *= 2;
			}
			if(isSorted())
			{
				enable = true;
			}

			//initialize
			for(int j=0; j<10; j++)
			{
				A[j] = 0; B[j] = 0;
			}
		}
		if(enable) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

C++: #include <map>
#include <vector>
#include <queue>
#include <cmath>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <memory.h>
#include <algorithm>
#include <limits.h>

using namespace std;

int main()
{
	int T;

	cin>>T;
	while(T--)
	{
		int a,b;
		a=b=INT_MIN;
		int temp;
		int i;

		for(i=0;i<10;i++)
		{
			cin>>temp;
			if(temp>a)
			{
				a=temp;
				continue;
			}
			if(temp>b)
			{
				b=temp;
				continue;
			}
			break;
		}

		if(i==10)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }



#define index_of(a, x) distance(a.begin(), lower_bound(a.begin(), a.end(), x));
vector<int> longestSubstr(const vector<int>& a) {
	int n = (int)a.size();
	vector<int> A(n, iINF);
	vector<int> id(n);
	
	for (int i=0; i<n; i++) {
		id[i] = index_of(A, a[i]);
		A[ id[i] ] = a[i];
	}
	
	int m = *max_element(id.begin(), id.end());
	vector<int> b(m+1);
	for (int i=n-1; i>=0; i--) if (id[i] == m) b[m--] = a[i];
	return b;
}

#define MAX 10

int main() {
	int n; cin >> n;
	
	for_(i, 0, n) {
		vci a(MAX);
		for_(j, 0, MAX) cin >> a[j];
		vci b = longestSubstr(a);
		vci rest;
		
		for_(j, 0, MAX) if (!binary_search(all(b), a[j])) rest.pb(a[j]);
		
		bool ok = true;
		for_(j, 1, (int)rest.sz) if (rest[j-1]>rest[j]) ok = false;
		
		if (ok) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	cin>>n;
	while(n--){
		vector<int>in(10);
		rep(i,10)cin>>in[i];
		vector<int>a,b;
		a.pb(in[0]);
		bool h=true;
		loop(i,1,10){
			if(a[a.size()-1]<in[i])a.pb(in[i]);
			else if(b.size()==0||b[b.size()-1]<in[i])b.pb(in[i]);
			else {h=false;break;}
		}
		if(h)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}