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 <string>
using namespace std;

int main(){
	int n, a, b, in;
	cin >> n;
	for(int i=0;i<n;i++){
		a = 0;
		b = 0;
		for(int j=0;j<10;j++){
			cin >> in;
			if(in>a){
				a = in;
			}
			else if(in>b){
				b = in;
			}
			else{
				cout << "NO" << endl;
				break;
			}
			if (j==9){
				cout << "YES" << endl;
			}
		}
	}
	return 0;
}

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

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

    while (n--) {
        int left = 0, right = 0;
        bool flag = true;
        for (int i = 10; i--;) {
            int x;
            cin >> x;
            if (x > left)
                left = x;
            else if (x > right)
                right = x;
            else {
                flag = false;
                break;
            }
            if (left < right)
                swap(left, right);
        }
        cout << (flag ? "YES" : "NO") << endl;
    }

    return 0;
}

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

int main(){
	int N;
	int A[11];
	int cnt1=0;
	cin>>N;
	while(1){
		
		if(cnt1==N){
			break;
		}
		cnt1++;
		for(int i=1;i<=10;i++){
			cin>>A[i];
		}
		int B=A[1];
		int Z[11];
		for(int i=1;i<=10;i++){
			Z[i]=0;
		}
		int C=0;
		int cnt2=0;
		int su=0;
		for(int i=2;i<=10;i++){
			if((B+1==A[i])){
				B=A[i];
				cnt2++;
			}
			else if((C+1==A[i])){
				C=A[i];
				cnt2++;
				Z[i]=C;
				su=0;

			}
			else if(B<A[i]){
				B=A[i];
				
				cnt2++;

			}
			else if(C<A[i]){
				C=A[i];
				Z[i]=C;
				su=0;
				cnt2++;
			}
			for(int q=1;q<=10;q++){
				if(B+1==Z[q]){
					su=1;
				}
			}
			
		}
		if(cnt2==9){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}
	return 0;	
}

C++: #include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
 
using namespace std;
 
int s[10]={0};
 
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        for(int i=0;i<10;i++)
            scanf("%d",&s[i]);
        int a=0,b=0;
        bool flag=0;
        for(int i=0;i<10;i++)
        {
            if(s[i]<a&&s[i]<b)
            {
                flag=1;
                break;
            }
            else if(s[i]<a&&s[i]>b)b=s[i];
            else if(s[i]>a&&s[i]<b)a=s[i];
            else
            {
                a=a>b?s[i]:a;
                b=a<b?s[i]:b;
                if(a==b)a=s[i];
            }
        }
        if(flag)printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}

C++: #include<cstdio>

using namespace std;

int boal[11];
bool ans;


void BFS(int L,int R,int c){
	
	if(c == 10 || ans){
		ans = true;
		return;
	}
	
	if(L < boal[c]){
		L = boal[c];
		BFS(L,R,c+1);
	}
	if(R < boal[c]){
		R = boal[c];
		BFS(L,R,c+1);
	}
}

int main(void){
	int n;
	while(scanf("%d", &n) != EOF){
		for(int j = 0; j < n; j++){
			ans = false;
			for(int i = 0; i < 10; i++){
				scanf("%d", &boal[i]);
			}
			
			BFS(0,0,0);
			
			printf("%s\n",ans?"YES":"NO");
		}
	}
	return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <map>

using namespace std;

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

typedef vector<int> vi;

int main()
{
	int n;
	scanf("%d", &n);
	rep(i, n){
		bool can = true;
		int left = 0, right = 0;
		rep(j, 10){
			int a;
			scanf("%d", &a);
			if(min(left, right) > a){
				can = false;
				break;
			}
			if(max(left, right) < a){
				if(left<right) right = a;
				else left = a;
			}else{
				if(left<right) left = a;
				else right = a;
			}
		}

		puts(can ? "YES" : "NO");
	}

	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int a[10];
int main() {
	int n; cin >> n;
	rep(k, n) {
		rep(i, 10)scanf("%d", &a[i]);
		rep(i, 1 << 10) {
			stack<int>s[2];
			rep(j, 10)if (s[(i >> j) & 1].empty() || a[j] > s[(i >> j) & 1].top())s[(i >> j) & 1].push(a[j]);
			if (s[0].size() + s[1].size() == 10) { puts("YES"); break; }
			if (i == (1 << 10) - 1)puts("NO");
		}
	}
	return 0;
}

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

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

int a[10];

bool dfs(int i, vector<int>& l, vector<int>& r) {
  if (i == 10) return true;
  bool res = false;
  if (l.empty() || l.back() < a[i]) {
    l.emplace_back(a[i]);
    res |= dfs(i + 1, l, r);
    l.pop_back();
  }
  if (r.empty() || r.back() < a[i]) {
    r.emplace_back(a[i]);
    res |= dfs(i + 1, l, r);
    r.pop_back();
  }
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N;
  cin >> N;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> a[j];
    }
    vector<int> l, r;
    cout << (dfs(0, l, r) ? "YES" : "NO") << endl;
  }

  return 0;
}

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

int a[10];

int main() {
	int T;
	cin >> T;
	while (T--) {
		bool ans = true;
		for (int i = 0; i < 10; ++i) {
			cin >> a[i];
		}
		int l, r;
		l = r = 0;
		for (int i = 0; i < 10; ++i) {
			if (a[i] > l) {
				l = a[i];
			} else if (a[i] > r) {
				r = a[i];
			} else {
				ans = false;
				break;
			}
		}
		cout << (ans ? "YES" : "NO") << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <sstream>
#include <cstdio>
#include <stack>
using namespace std;

// Ball(0033)
int main()
{
	int N;
	while (cin >> N) {
		for (int i = 0; i < N; ++i) {
			vector<int> ball(10);
			for (int j = 0; j < 10; ++j)
				cin >> ball[j];

			int prev = ball.front();
			ball[0] = -1;
			for (int j = 1; j < ball.size(); ++j) {
				if (prev < ball[j]) {
					prev = ball[j];
					ball[j] = -1;
				}
			}

			prev = -1;
			for (int j = 0; j < ball.size(); ++j) {
				if (prev == -1 && ball[j] != -1) {
					prev = ball[j];
					ball[j] = -1;
				} else {
					if (prev < ball[j]) {
						prev = ball[j];
						ball[j] = -1;
					}
				}
			}

			if (count(ball.begin(), ball.end(), -1) == 10)
				cout << "YES" << endl;
			else
				cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>

using namespace std;

int A[10];
int n;

bool dfs(int, int, int);

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n; i++)
  {
  for(int i = 0; i < 10; i++)
    scanf("%d", &A[i]);

    cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
  }
  return 0;
}

bool dfs(int ai, int b, int c)
{
  if(ai == 10)
    return true;
  int bb = b;
  int bc = c;
  bool ans = false;
  if(A[ai] > b)
  {
    b = A[ai];
    //cout << b  << " into B" << ai << endl;
    ans = ans || dfs(ai + 1, b, c);
    b = bb;
  }
  if(A[ai] > c)
  {
    c = A[ai];
    //cout << b  << " into C" << ai << endl;
    ans = ans || dfs(ai + 1, b, c);
    c = bc;
  }
  return ans;
}