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 <iostream>
#include <cstring>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
using namespace std;
const int manx = 500;
stack <int> a;
stack <int> b;
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int input;
        int flag = true;
        scanf("%d",&input);
        a.push(input);
        b.push(0);
        for(int i = 1 ; i < 10 ; i++)
        {
            scanf("%d",&input);
            int ai = input - a.top();
            int bi = input - b.top();
            if(ai <= 0 && bi <= 0)
            {
                flag = false;
                //printf("NO\n");
                break;
            }
            if(ai > 0 && bi <= 0)
                a.push(input);
            if(bi > 0 && ai <= 0)
                b.push(input);
            if(ai > 0 && bi > 0)
            {
                if(ai > bi )
                    b.push(input);
                if(ai <= bi)
                    a.push(input);
            }
        }
        if(flag == false)
            printf("NO\n");
        if(a.size() + b.size() == 11)
            printf("YES\n");
        while(!a.empty())
            a.pop();
        while(!b.empty())
            b.pop();
    }
    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

class Pipe
{
private:
	queue<int> pipe;
	vector<int> a, b;
public:
	Pipe( queue<int> input )
	{
		pipe = input;
	}

	void pushA()
	{
		a.push_back( pipe.front() );
		pipe.pop();
	}

	void pushB()
	{
		b.push_back( pipe.front() );
		pipe.pop();
	}

	bool empty()
	{
		return pipe.size() == 0;
	}

	bool sorted()
	{
		for ( unsigned int i = 0; i + 1 < a.size(); i++ )
		{
			if ( a[i + 1] < a[i] )
			{
				return false;
			}
		}

		for ( unsigned int i = 0; i + 1 < b.size(); i++ )
		{
			if ( b[i + 1] < b[i] )
			{
				return false;
			}
		}

		return true;
	}
};

bool dfs()
{
	int buffer;
	queue<int> que;
	for ( int i = 0; i < 10; i++ )
	{
		cin >> buffer;
		que.push( buffer );
	}

	Pipe init( que );
	stack<Pipe> st;
	st.push( init );

	while ( !st.empty() )
	{
		Pipe current = st.top();
		st.pop();

		if ( current.empty() )
		{
			if ( current.sorted() )
			{
				return true;
			}
			else
			{
				continue;
			}
		}
		
		Pipe next = current;
		next.pushA();
		st.push( next );

		next = current;
		next.pushB();
		st.push( next );
	}

	return false;
}

int main()
{
	int n;

	cin >> n;

	for ( int i = 0; i < n; i++ )
	{
		cout << ( dfs() ? "YES" : "NO" ) << endl;
	}
	
	return 0;
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a = -1, b = -1;
		int num;
		bool ans = true;
		for (int j = 0; j < 10; j++) {
			if (a > b)swap(a, b);
			cin >> num;
			if (num > b)b = num;
			else if (num > a)a = num;
			else ans = false;
		}
		cout << (ans ? "YES" : "NO") << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
	int ball;
	int n;
	while(cin >> n){
		bool flag = true;
		int B=0, C=0;
		for(int i=0; i<n; i++){
			for(int j=0; j<10; j++){
				cin >> ball;
				if(flag){
					if(B < ball) B=ball;
					else if(C < ball) C=ball;
					else flag=false;
				}
			}
			if(flag) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int n,left,right,x,ans;
	
	cin>>n;
	while(n--)
	{
		left=0,right=0,ans=1;
		
		for(int i=0;i<10;++i)
		{
			cin>>x;
			if(x>left&&x>right)
			{
				if(left>right)
					left=x;
				else
					right=x;		
			}	
			else	if(x>left)
			{
				left=x;
			}
			else 	if(x>right)
			{
				right=x;
			}
			else
			{
				ans=0;
				break;
			}
		}	
		if(ans)
			cout<<"YES\n";
		else
			cout<<"NO\n";	
	}
	
	return 0;
}

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 < n;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<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
	int a,b;
	int n;
	int g;
	bool check;
	vector<int> ball(10);

	while(cin >> n){
		a = b = 11;
		check = true;
		rep(i,10){
			cin >> g;
			ball.push_back(g);
		}
		rep(i,10){
			if(a > ball.back()){
				a = ball.back();
				ball.erase( --ball.end() );
			}else if(b > ball.back()){
				b = ball.back();
				ball.erase( --ball.end() );
			}else{
				check = false;
			}
		}
		if(check) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

C++: #include <iostream>
#define MAX(a,b) ((a>b)?(a):(b))
using namespace std;

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