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 <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int n;

bool dfs(queue<int> S,int l,int r){
  if(S.empty())
    return true;

  int x = S.front();
  S.pop();

  if(x < l&& x <r)
    return false;
  else if(x < l)
    return dfs(S,l,x);
  else if(x <r)
    return dfs(S,x,r);
  else 
    return dfs(S,x,r)||dfs(S,l,x);
}

int main()
{
  cin>>n;
  for(int i = 0;i < 2;i++){
    queue<int> S1;
    for(int j = 0;j < 10;j++){
      int ball;
      cin >>ball;
      S1.push(ball);
    }
    if(dfs(S1,0,0)){
      cout <<"YES"<<endl;
      }else
      cout <<"NO"<<endl;
  }
  return 0;
}

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

int main(){
	int n, ball;cin >> n;
	stack<int> r, l;
	while(n--){
		r.push(0);l.push(0);
		bool f = false;
		for(int i = 0;i < 10;i++){
			cin >> ball;
			if(f == true)continue;
			if(r.top() < ball){
				r.push(ball);
			}else if(l.top() < ball){
				l.push(ball);
			}else{
				f = true;break;
			}
		}
		while(!r.empty())r.pop();
		while(!l.empty())l.pop();
		if(f == false)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,a[10];
  cin >>n;
  while(n--){
    int lot[50][2],r = 0,l = 0,x = 0;
    for(int i=0; i<10; i++) cin >>a[i];
    for(int i=0; i<10; i++){
      if(l<a[i] && r<a[i]){
	lot[x][0] = l;
	lot[x][1] = i;
	x++;
	l = a[i];
      }
      else if(l<a[i]) l = a[i];
      else if(r<a[i]) r = a[i];
      else{
	if(x == 0){cout <<"NO"<<endl;break;}
	x--;
	l = lot[x][0];
	i = lot[x][1];
	r = a[i];
      }
      if(i == 9) cout <<"YES"<<endl;
    }
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
#define RIGHT 1
#define LEFT 0
#define BALL 10
#define BAD 1

int main()
{
    int n;
    int num[BALL];
    int siden[BALL];
    cin >> n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<BALL;++j) {cin >> num[j]; }

        int temp,ans =0;
        for(int side=0;side<=0x4F;++side)
        {
            ans = 0;
            for(int j = 0;j<BALL;++j)
            {
                if(((side>>j)&1) ){siden[j] = RIGHT;}
                else {siden[j] = LEFT;}
            }
            int before = -1;
            //right side
            for(int j=0;j<BALL;++j)
            {
                if(siden[j]==RIGHT)
                {
                    if(before > -1)
                    {
                        if(num[before]>num[j])ans = BAD;
                    }
                    before = j;
                }
            }
            before = -1;

            //left side
            for(int j=0;j<BALL;++j)
            {
                if(siden[j]==LEFT)
                {
                    if(before > -1)
                    {
                        if(num[before]>num[j])ans = BAD;
                    }
                    before = j;
                }
            }
            if(ans==0)break;
        }
        if(ans==BAD) cout << "NO" << endl;
        else cout << "YES" << endl;
    }
    return 0;
}

C++: #include<cstdio>

int a[10];

bool dfs(int k, int B,int C)

{

if(k == 10)

return true;

if(a[k]>B)

{

if(dfs(k+1,a[k],C)) return true;

}

if(a[k]>C)

{

if(dfs(k+1,B,a[k]))return true;

}

return false;

}



void slove()

{

if(dfs(0,0,0))printf("YES\n");

else printf("NO\n");

}



int main()

{

int t;

scanf("%d",&t);

while(t--)

{

for(int i = 0 ; i  < 10; i++)

scanf("%d",&a[i]);

slove();

}

return 0;

}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<map>
#include<queue>
#include<set>

using namespace std;
typedef pair<int,int> PII;
typedef long long ll;

int main(){
  int n,a,b,c;
	cin>>n;
	for(;n>0;n--){
		int i;
		a = b = 0;
		for(i=0;i<10;i++){
			cin>>c;
			if(min(a,b) > c)break;
			else (a >= b && c > a) ? a = c : b = c;
		}
		if(i==10)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
  return 0;
}

C++: #include <iostream>

using namespace std;

bool judge(int num){
	int i, n, q[2]={0,0};

	for (i=0; i<num; i++) {
		cin >> n;
		if (q[0]<n) q[0] = n;
		else if (q[1]<n) q[1] = n;
		else break;
	}

	return ((i==num)? true: false);
}

int main(){
	int i, n;

	if (cin >> n) {
	for (i=0; i<n; i++)
		cout << (judge(10)? "YES": "NO") << "\n";
	}

	return 0;
}

C++: #include<iostream>

using namespace std;

int tama[10],n;

bool Haireruka(int i,int left,int right){
	if(i==10)return true;
	if(tama[i]>left){
		if(Haireruka(i+1,tama[i],right))return true;
	}
	if(tama[i]>right){
		if(Haireruka(i+1,left,tama[i]))return true;
	}
	return false;
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		for(int i=0;i<10;i++){
			cin>>tama[i];
		}
		if(Haireruka(0,0,0))cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}return 0;
}

C++: #include<iostream>
#include<set>
#include<string>
#include<queue>
#include<string.h>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<stack>
#include<sstream>
using namespace std;
int num[11];
int preA, preB, x;
int res;
bool dfs(int preA,int preB,int x,int cnt) {
	if (cnt == 10) {
		return true;
	}
	if (x > preA) {
		preA = x;
		x = num[cnt + 1];
		dfs(preA, preB, x, cnt + 1);
	}
	if (x > preB) {
		preB = x;
		x = num[cnt + 1];
		dfs(preA, preB, x, cnt + 1);
	}
	if (x < preA&&x < preB)
		return false;
}
int main() {
	int t;
	cin >> t;
	while (t--) {
		for (int i = 1; i <= 10; i++)
			cin >> num[i];
		preA = num[1];
		preB = 0;
		x = num[2];
		int cnt = 2;
		if (dfs(preA, preB, x, cnt))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

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

int main(){
	int n,ball,tp[2],con,bad;
	
	cin >> n;
	
	while(n--){
		
		tp[0] = tp[1] = 0;
		
		for(int i = 0; i < 10; i++){
			cin >> ball;
			
			if(tp[0] > tp[1]){
				con = 0;
			}else{
				con = 1;
			}
			
			if(ball > tp[con]){
				tp[con] = ball;
			}else if(ball > tp[!con]){
				tp[!con] = ball;
			}else{
				bad = 1;
			}
		}
		
		if(bad){
			cout << "NO" << endl;
			bad = 0;
		}else{
			cout << "YES" << endl;
		}
	}
	
	return 0;
}