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 <bits/stdc++.h>

using namespace std;

void solve() {
  int a = 0, b = 0, c;
  bool f = true;
  for (int i = 0; i < 10; ++i) {
    cin >> c;
    if (c < a) f = false;
    else if (c < b) a = c;
    else b = c;
  }
  cout << (f ? "YES" : "NO") << endl;
}

int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) solve();
}

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

#define PRINT(STR) cout << STR << endl;
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define SPACE " "

typedef long long ll;

using namespace std;

int nextInt() { int n = -1; cin >> n; return n; }
double nextDouble() { double d = -1; cin >> d; return d; }
ll nextll() { ll n = -1; cin >> n; return n; }
string nextString() { string str; cin >> str; return str; }

int INF = 1LL << 25;
double EPS = 1e-9;
int numofbits(int bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

// BEGIN //////////////////////////////////////////////////////////////
int main() {
  int N = nextInt();
  REP(i, N) {
    stack<int> bs, cs;
    bool flag = true;
    bs.push(0);
    cs.push(0);
    REP(j, 10) {
      int a = nextInt();
      if (bs.top() < a) {
        bs.push(a);
      } else if (cs.top() < a) {
          cs.push(a);
      } else {
        flag = false;
        break;
      }
    }
    if (flag) {
      PRINT("YES");
    } else {
      PRINT("NO");
    }
  }
	return 0;
}
// END   //////////////////////////////////////////////////////////////

C++: #include<cstdio>
#include<algorithm>
#define MAXL 10
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int t,last1=0,last2=0;	//假?last1>last2
		bool flag=0;
		for(int j=1;j<=10;j++){
			scanf("%d",&t);
			if(last1<t)	last1=t;
			else
				if(last2<t)	last2=t;
				else flag=1;
			if(last1<last2)	swap(last1,last2);
		}
		if(flag==0)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++: #include <stdio.h>

int
main(void)
{
	char line[80];

	int b[10];

	int n;

	if (fgets(line, sizeof line, stdin) == NULL) {
		return 0;
	}
	if (sscanf(line, "%d", &n) != 1) {
		return 0;
	}

	while (n--) {
		fgets(line, sizeof line, stdin);
		sscanf(line, "%d %d %d %d %d %d %d %d %d %d",
			   &(b[0]), &(b[1]), &(b[2]), &(b[3]), &(b[4]), &(b[5]),
			   &(b[6]), &(b[7]), &(b[7]), &(b[9]));

		bool f = true;
		int s0 = 0;
		int s1 = 0;
		for (int t : b) {
			if (t > s0 && t > s1) {
				if (t - s0 <= t - s1) {
					s0 = t;
				} else {
					s1 = t;
				}
			} else 	if (t > s0) {
				s0 = t;
			} else 	if (t > s1) {
				s1 = t;
			} else {
				f = false;
				break;
			}
		}
		printf("%s\n", (f ? "YES" : "NO"));
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
 
int b[10];
  
bool dfs(int i,int j,int k){
  if(k==10)
    return true;
  if(i<b[k]){
    if(dfs(b[k],j,k+1))return true; 
  }
  if(j<b[k]){
    if(dfs(i,b[k],k+1))return true;
  }
  return false;
}
 
int main(){
  int a;
  cin >> a;
  while(a>0){
    for(int i=0;i<10;i++){
      cin >> b[i];
    }
    int p=dfs(0,0,0);
    if(p!=0)
      cout << "YES" << endl;
    else
      cout << "NO" <<endl;
    a--;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#include <map>
#include <sstream>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
using namespace std;

int ball[10];

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

int main(){
    int n;
    cin >> n;
    REP(i, n){
    	REP(j, 10){
    		cin >> ball[j];
    	}
    	if (dfs(0, 0, 0)) cout << "YES" << endl;
    	else cout << "NO" << endl;
    }
}

C++: #include <map>
#include <set>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <iostream>
#include <algorithm>
using namespace std;
bool flag;
int ball[15];
bool dfs(int x, int l, int r){
    if(ball[x] > l){
        if(x == 9) return true;
        if(dfs(x+1, ball[x], r)) return true;
    }
    if(ball[x] > r){
        if(x == 9) return true;
        if(dfs(x+1, l, ball[x])) return true;
    }
    return false;
}
int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    while(n--){
        for(int i = 0; i < 10; ++i) cin >> ball[i];
        bool flag = dfs(0, 0, 0);
        cout << (flag ? "YES" : "NO") << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
const int NUM=15;
int num[NUM];
bool vis[NUM];
void dfs(int i);
int main()
{
    int test;
    scanf("%d",&test);
    while(test--)
    {
        int ans=0;
        memset(vis,0,sizeof vis);
        for (int i=0; i<10; i++)
            scanf("%d",&num[i]);
        /*for (int i=0; i<10; i++)
        {
            if (!vis[i])
            {
                vis[i]=1;
                ans++;
                dfs(i);
            }
        }
        if (ans==1||ans==2)
            printf("YES\n");
        else
            printf("NO\n");*/
        int l=0,r=0,flag=1;
        for(int j=0; j<10; j++)
        {
            if(l<num[j])l=num[j];
            else if(r<num[j])r=num[j];
            else flag=0;
            if(flag==0)break;
        }
        if(flag)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}
/*void dfs(int i)
{
    for (int j=i+1; j<10; j++)
    {
        if (!vis[j]&&num[j]>=num[i])
        {
            vis[j]=1;
            dfs(j);
        }
    }
}*/