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<cstdio>
#include<cstring>
using namespace std;

int a[10];
int b[10],c[10],lb,lc;
int vis[10];
int n,m,t;

bool dfs(int s,int e)
{
    int cnt = 0;
    if(s==e) return true;

    if(!lb || b[lb-1] < a[s])
    {
        cnt++;
        b[lb++] = a[s];
        if(dfs(s+1,e)) return true;
        lb--;
        b[lb] = 0;
    }
    if(!lc || c[lc-1] < a[s])
    {
        cnt++;
        c[lc++] = a[s];
        if(dfs(s+1,e)) return true;
        lc--;
        c[lc] = 0;
    }
    return false;
}

int main()
{
    scanf("%d",&t);
    while(t--)
    {
        for(int i=0;i<10;i++)
            scanf("%d",&a[i]);
        lb = 0, lc = 0;
        if(dfs(0,10)) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

C++: #include<iostream>
#include<queue>
#include<stack>
using namespace std;
int main()
{
	int n;
	cin>>n;
	stack<int>q;
	stack<int>p;
	while(n--){
		
		q.push(0);
		p.push(0);
		int f=1;
		for(int i=1;i<=10;i++)
		{
			int t;
			cin>>t;
			if(p.top()<t)
			p.push(t);
			else if(q.top()<t)
			q.push(t);
			else{
				f=0;
			}
		}
		if(f==0)
		cout<<"NO"<<endl;
		else
		cout<<"YES"<<endl;
		while(!q.empty())
		q.pop();
		while(!p.empty())
		p.pop();
	
	}
 }

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

int main() {
	int n;
	cin >> n;
	for ( int i = 0; i < n; i++ ){
		deque<int>b,c;
		bool endflag = false;
		int dummy;
		cin >> dummy;
		b.push_back( dummy );
		cin >> dummy;
		c.push_back( dummy );
		for ( int j = 0; j < 8; j++ ){
			cin >> dummy;
			if ( !endflag ) {
				if ( dummy > b[b.size()-1] )	b.push_back( dummy );
				else if ( dummy > c[c.size()-1] )	c.push_back( dummy );
				else {
					cout << "NO" << endl;
					endflag = true;
				}
			}
		}
		if( !endflag )	cout << "YES" << endl;
	}
	
	return 0;
}

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

int l=0, r=0;
bool flag=true;

void solve(int N) {
	int a = 0;
	while (N > 0) {
		for (int i = 0; i < 10; i++) {
			cin >> a;
			if (a > l)
				l = a;
			else if (a > r)
				r = a;
			else 
				flag = false;
			if (l < r)
				swap(l, r);
		}
		if (flag == true)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
		N--;
	}
}
int main() {
	int n = 0;
	cin >> n;
	solve(n);
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  int a[10];
  int f,s;
  bool flg=true;
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>a[j];
    }
    f=0;s=0;flg=true;
    for(int i=0;i<10;i++){
      if(a[i]<f){
	if(a[i]<s)flg=false;
	else s=a[i];
      }
      else f=a[i];
    }
    if(flg)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}

C++: #include <iostream>

using namespace std;

int main(void){

  int a;
  int b[10] = {0};
  int c[10] = {0};
  int out[10] = {0};

  int n;
  cin >> n;
  while(n--){

    for( int l = 10 ; l > 0 ; l-- ){
    cin >> a;
    int i = 0;
    int j = 0;
    int k = 0;
    if( b[i] < a ){
    b[i++] = a;
    }
    else if( c[j] < a ){
	c[j++] = a;
      }
    else out[k++] = a;
    }
    if( out[0] == 0 )cout << "YES" << endl;
    else cout << "NO" << endl;
  }
 return 0;
}

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

using namespace std;

int a[10];
int l, r;

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

    bool res = false;

    int tmp;

    if (l <= a[i]) {
        tmp = l;
        l = a[i];
        res = res || dfs(i + 1);
        l = tmp;
    }

    if (r <= a[i]) {
        tmp = r;
        r = a[i];
        res = res || dfs(i + 1);
        r = tmp;
    }

    return res;
}

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

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

C++: #include <stdio.h>
#include <vector>
#include <iostream>

using namespace std;

int main() {
	vector<int> left;
	vector<int> right;
	vector<int> all;

	bool flag = true;

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else
							flag = false;
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}

		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO"<<endl;
		flag = true;
	}

	return 0;
}

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

using namespace std;

#define TEMP_T template<typename T>
TEMP_T void sort(T& v){ sort(v.begin(), v.end()); }
TEMP_T void revs(T& v){ reverse(v.begin(), v.end()); }
TEMP_T void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end())); }
TEMP_T void show(T& v, char delim=' ', char end='\n'){ for(int i=0; i<v.size()-1; i++) cout << v[i] << delim; cout << v[v.size()-1] << end; }
TEMP_T T    cums(T& v){ T r; r.push_back(v[0]); for(int i=1; i<v.size(); i++) r.push_back(r[i-1] + v[i]); return r; }
TEMP_T void maxe(T& v, T m){ v = max(v, m); }
TEMP_T void mine(T& v, T m){ v = min(v, m); }

static inline int in(){ int x; scanf("%d", &x); return x; }

struct Solver {
  Solver(vector<int> bs) : bs(bs) {}
  bool solve(int it=0, int a=0, int b=0){
    if (it == bs.size()) return true;
    if (a < bs[it] && solve(it + 1, bs[it], b)) return true;
    if (b < bs[it] && solve(it + 1, a, bs[it])) return true;
    return false;
  }
  vector<int> bs;
};

int main()
{
  int n = in();
  for (int i = 0; i < n; i++){
    vector<int> bs;
    for (int j = 0; j < 10; j++){
      bs.push_back(in());
    }
    Solver solver(bs);
    if (solver.solve()) puts("YES");
    else puts("NO");
  }
  return (0);
}

C++: #include <iostream>
using namespace std;
int main()
{
cout<<"YES"<<endl;
cout<<"NO"<<endl;
}

C++: #include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
int a[10];
bool ans;
void dfs(int i,int r,int l){
	if(i==10)return;
	if(a[i]<r&&a[i]<l){
		ans=0;
		return;
	}
	if(r<a[i])dfs(i+1,a[i],l);
	if(l<a[i])dfs(i+1,r,a[i]);
}
int main(){
	int t;
	cin>>t;
	while(t--){
		ans=1;
		for(int i=0;i<10;i++)cin>>a[i];
		dfs(0,0,0);
		if(ans)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

C++: #include<cstdio>

int main(void){
	int n,i,j;
	int a[1024][10];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<10;j++){
			scanf("%d",&a[i][j]);
		}
	}
	
	for(i=0;i<n;i++){
		int b[10],c[10];
		b[0]=a[i][0];
		bool x=true;
		int k=0,l=0;
		for(j=1;j<10;j++){
			if(a[i][j]>b[k]){
				k++;
				b[k]=a[i][j];
			}else {
				c[l]=a[i][j];
				l++;
			}
		}

		for(j=0;j<l-2;j++){
			if (c[j]>c[j+1]){
				x=false;
			}
			//if(c[j]>c[j+1]) break;
		}
		if(x==true){
			printf("YES\n");
		} else{
			printf("NO\n");
		}	
	}
	return 0;
}