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<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=100,inf=0x3f3f3f3f;
int n,a[maxn],b[maxn],c[maxn],ok=0;
bool dfs(int x,int y,int t){
	if(t==11) {
		ok=1;
	}
	if(a[t]>b[x-1]){
		b[x]=a[t];
		dfs(x+1,y,t+1);
	}
	if(a[t]>c[y-1]){
		c[y]=a[t];
		dfs(x,y+1,t+1);
	}

}
int main()
{
	//freopen("read.txt", "r", stdin);
	cin>>n;
	while(n--){
		for(int i=1;i<=10;i++)cin>>a[i];
		ok=0;
		dfs(1,1,1);
		if(ok==1)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	//fclose(stdin);
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include<stack>

using namespace std;
int t[11];
stack<int> a;
stack<int> b;
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
       while(!a.empty())
        a.pop();
       while(!b.empty())
        b.pop();
        int flag=0;
        memset(t,0,sizeof(0));
        for(int i=0;i<10;i++)
        {
            scanf("%d",&t[i]);
        }
       // sort(t,t+10,cmp);
        a.push(t[0]);
        b.push(0);
        for(int i=1;i<10;i++)
        {
            if(t[i]>a.top()&&t[i]<=b.top())
                a.push(t[i]);
            else if(t[i]<=a.top()&&t[i]>b.top())
                b.push(t[i]);
             else if(t[i]>a.top()&&t[i]>b.top())
             {
                 if(a.top()>b.top())
                  a.push(t[i]);
                 else
                    b.push(t[i]);
                    
             }
               
                else if(t[i]<=a.top()&&t[i]<=b.top())
              {
                  flag=1;
                  break;
              }
        }
        if(flag)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;



    }
}

C++: #include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n; cin >> n;
  for (int _ = 0; _ < n; ++_) {
    V<> a(10); for (int i = 0; i < 10; ++i) cin >> a[i];
    bool ok = false;
    for (int bit = 0; bit < 1 << 10; ++bit) {
      V<> b, c;
      for (int i = 0; i < 10; ++i) if (bit & 1 << i) {
        b.push_back(a[i]);
      } else {
        c.push_back(a[i]);
      }
      if (is_sorted(begin(b), end(b)) and is_sorted(begin(c), end(c))) {
        ok = true;
        break;
      }
    }
    cout << (ok ? "YES" : "NO") << '\n';
  }
}

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

using namespace std;

int main()
{
        int set_number, L, R, flag = 0;
        cin >> set_number;
        array< int, 10 > ar;

        for ( int i = 0 ; i < set_number ; i++ )
        {
                for ( int j = 0 ; j < 10 ; j++ )
                {
                        cin >> ar[j];
                }

                L = ar[0];
                R = 0;
                for ( int j = 1 ; j < 10 ; j++ )
                {
                        if ( L < ar[j] )
                        {
                                L = ar[j];
                        }
                        else if ( L > ar[j] )
                        {
                                if ( R < ar[j] )
                                {
                                        R = ar[j];
                                }
                                else
                                {
                                        fprintf( stdout, "No\n" );
                                        flag = 1;
                                        break;
                                }
                        }
                }

                if ( flag == 0 )
                {
                        fprintf( stdout, "Yes\n" );
                }
        }

        return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
int ta[10];
bool dfs(int h,int a,int b){
	if(h==9)return true;
	int now=ta[h];
	bool ret=0;
	if(now>a)ret=dfs(h+1,now,b);
	if(now>b)ret=dfs(h+1,a,now);
	return ret;
}

int main(){
	int n;
	cin>>n;
for(int i=0;i<n;i++){
for(int i=0;i<10;i++)cin>>ta[i];
(dfs(0,0,0))?cout<<"YES"<<endl:cout<<"NO"<<endl;
}
	return 0;
}

C++: #include <iostream>

#define MAX 10
using namespace std;

int main(){
  int count;
  int ball1,ball2,ball;
  cin >> count;
  for(int i=0;i<count;i++){
    ball1=0;ball2=0;
    for(int j=0;j<MAX;j++){
      cin >>ball;
      //cout << ball1 << " " << ball2 << endl;
      //      cout << ball << endl;
      //cout << j << endl;
      if(ball1 < ball || ball2 < ball){
	if(ball2<ball){
	  ball2=ball;
	}
	else{
	  ball1 = ball;
	}
	if(j==MAX-1){
	  cout << "YES";
	}
      }
      else{
	cout << "NO";
	for(int k=0;k<MAX-j;k++) cin >>ball;
	break;
      }
    }
    cout << endl;
  }
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n--){
    int lot[10],save[100][2]={0},tag=0,a,b;
    bool f = true;
    for(int i=0; i<10; i++) cin >>lot[i];
    a = lot[0];
    b = 0;
    for(int i=1; i<10; i++){
      if(a<lot[i] && b>lot[i]) a = lot[i];
      else if(a>lot[i] && b<lot[i]) b = lot[i];
      else if(a<lot[i] && b<lot[i]){
	save[tag][0] = a;
	save[tag][1] = i;
	a = lot[i];
	tag++;
      }
      else if(a>lot[i] && b>lot[i]){
	if(tag == 0){
	  f = false;
	  break;
	}
	else{
	  a = save[tag-1][0];
	  i = save[tag-1][1];
	  b = lot[i];
	  tag--;
	}
      }
    }
    if(f) cout <<"YES"<<endl;
    else cout <<"NO"<<endl;
  }
  return 0;
}