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

bool flag;

int main()
{
	int n;
	cin>>n;
	int a[15];
	while(n--)
	{
		for(int i=0;i<10;i++)
			cin>>a[i];
		flag=0;
		int l=-1,r=-1;
		for(int i=0;i<10;i++)
		{
			if(a[i]>l) l=a[i];
			else if(a[i]>r) r=a[i];
			else flag=1;
		 } 
		 
		if(!flag)
		 	cout<<"YES"<<endl;
		else
		 	cout<<"NO"<<endl;
	}
}

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

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll; 
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;


ll n, a, C = 0, B = 0;

int main(){
	cin >> n;
	REP(i, n){
		C = 0, B = 0;
		REP(j, 10){
			cin >> a;
			if (a > B){
				B = a;
			}
			else if (a > C){
				C = a;
			}
			else{
				cout << "NO\n";
				break;
			}
			if (j == 9){
				cout << "YES\n";
			}
		}
	}
}

C++: #include <cstdio>
#include <stack>
#define NUM 10
using namespace std;

int N;
stack<int> B,C;

int main()
{
	//freopen("in","r",stdin);
	scanf("%d",&N);
	while(N--){
		int tmp;
		bool sol=true;
		for(int i=0;i<NUM;i++){
			scanf("%d",&tmp);
			if(B.empty())
				B.push(tmp);
			else if(tmp>B.top())
				B.push(tmp);
			else if(C.empty())
				C.push(tmp);
			else if(tmp>C.top())
				C.push(tmp);
			else
				sol = false;
		}
		if(sol)
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define Sort(x) sort((x).begin(),(x).end())
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

ll gcd(ll a,ll b){
    if(a<b){
        int t=a;a=b;b=t;
    }
    int c=a%b;
    while(c!=0){
        a=b;
        b=c;
        c=a%b;
    }
    return b;
}

ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}

bool isPrime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0)return false;
    }
    return true;
}

int kaizyo(int x){
    if(x==1)return x;
    else return x*kaizyo(x-1);
}

vector<int> v(10);
bool f=true;
bool dfs(int i,int top1,int top2){
    if(i==10)return true;
    
    if(top1>v[i]&&top2>v[i]){
        f=false;
        return false;
    }
    else if(top1<v[i]&&top2>v[i]) dfs(i+1,v[i],top2);
    else if(top1>v[i]&&top2<v[i])dfs(i+1,top1,v[i]);
    else if(top1<v[i]&&top2<v[i]){
        if(top1<top2)dfs(i+1,top1,v[i]);
        else dfs(i+1,v[i],top2);
    }
    if(f)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}
int main() {
    int n;
    cin>>n;
    rep(i,0,n){
        rep(i,0,10){
            cin>>v[i];
        }
        if(dfs(0,0,0))cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
int a[20];
using namespace std;
int main(){
	int m,n,p,q;
	scanf("%d",&n);
	while(n--){
		for(int i=0;i<10;i++){
			scanf("%d",&a[i]);
		}
		p = 0;q = -1;m = 1;
		for(int i=1;i<10;i++){
			if(q<0){
				if(a[i]>a[p]){
					p = i;m++;continue;
				}
				else{
					q = i;m++;continue;
				} 
			}
			else{
				if(a[p]>a[i]&&a[q]>a[i]) break;
				if(a[p]>a[i]&&a[q]<a[i]){
					q = i;m++;continue;
				} 
				if(a[p]<a[i]&&a[q]>a[i]){
					p = i;m++;continue;
				}
				if(a[p]<a[i]&&a[q]<a[i]){
					if(a[i]-a[p]>a[i]-a[q]){
						q = i;m++;continue;
					}
					else{
						p = i;m++;continue;
					}
				}
			}
		}
		if(m!=10) printf("NO\n");
		else printf("YES\n");
	} 
}

C++: #include <bits/stdc++.h>
using namespace std;

int inp[10];
int n;

bool dfs(int b, int c, int depth) {
  if (depth >= 10) return true;
  if (inp[depth] < b && inp[depth] < c) return false;
  if (inp[depth] > b) dfs(inp[depth], c, depth+1);
  if (inp[depth] > c) dfs(inp[depth], c, depth+1);
}

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

  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;cin>>n;
  rep(i,n){
    bool out=true;
    vector<int>a(1,0);
    vector<int>b(1,0);
    rep(j,10){
      int in;cin>>in;
      if(a[a.size()-1]<in)a.pb(in);
      else if(b[b.size()-1]<in)b.pb(in);
      else out=false;
    }
    if(out)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }

}

C++: #include<iostream>
#include<vector>
#include<stack>

int main(){
	int k;
	std::cin>>k;
	while(k>0){
		std::vector<int>v(10,0);
		std::stack<int>s;
		std::stack<int>s2;
		int a;
		for(int i=0;i<10;i++){
			std::cin>>v[i];
		}
		s.push(v[0]);
		s2.push(0);
		for(int i=1;i<10;i++){
			int x=s.top(),y=s2.top();
			if(v[i]>x&&v[i]>y){
				if(x>=y)s.push(v[i]);
				else s2.push(v[i]);
			}else if(v[i]>x&&v[i]<=y)s.push(v[i]);
			else if(v[i]<=x&&v[i]>y)s2.push(v[i]);
			else{
				std::cout<<"NO"<<std::endl;
				break;
			}if(i==9)std::cout<<"YES"<<std::endl;
		}
		k--;
	}
	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,r,n) for(int i=r;i<(int)n;i++)
using namespace std;
int in() {int x; cin >> x; return x;}

int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		bool ans = true;
		int r = -1, l = -2;

		for (int i = 0; i < 10; i++)
		{
			int x;
			cin >> x;

			if (min(r, l) > x)
			{
				ans = false;
				break;
			}
			if(r>l)swap(r,l);

			if(l<x)l=x;
			else r=x;

		}
		if(ans)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;


	}

}