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<stdio.h>
int main(){
	int a;
	scanf("%d",&a);
	for(;a--;){
		int b[10];
		for(int i=0;i<10;i++)scanf("%d",b+i);
		bool ans=false;
		for(int i=0;i<1024;i++){
			int maxa=0;
			int maxb=0;
			bool val=true;
			for(int j=0;j<10;j++){
				if(i&1<<j){
					if(maxa<b[j])maxa=b[j];
					else val=false;
				}else{
					if(maxb<b[j])maxb=b[j];
					else val=false;
				}
			}
			if(val)ans=true;
		}
		printf(ans?"YES\n":"NO\n");
	}
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int f;
  int n;
  int in,b,c;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    f=b=c=0;
    for(int j=0;j<10;j++){
      scanf("%d",&in);
      if(in<=min(b,c)){
	f=1;
	break;
      }
      if(b>=c && b<in)b=in;
      else c=in;
    }
    if(f)printf("NO\n");
    else printf("YES\n");
  }
}

C++: #include <iostream>

int nums[10];

bool dfs(int index, int left, int right)
{
  // std::cout << index << std::endl;
  if (index == 10)
  {
    return true;
  }
  // try put at the larger one
  if (left >= right)
  {
    if (left < nums[index])
    {
      return dfs(index + 1, nums[index], right);
    }
    if (right < nums[index])
    {
      return dfs(index + 1, left, nums[index]);
    }
    return false;
  }
  if (right > left)
  {
    if (right < nums[index])
    {
      return dfs(index + 1, left, nums[index]);
    }
    if (left < nums[index])
    {
      return dfs(index + 1, nums[index], right);
    }
    return false;
  }
  return false;
}

int main()
{
  int count = -1;
  std::cin >> count;
  for (int i = 0; i < count; i++)
  {
    for (int j = 0; j < 10; j++)
    {
      std::cin >> nums[j];
    }
    if (dfs(0, -1, -1))
    {
      std::cout << "YES" << std::endl;
    }
    else
    {
      std::cout << "NO" << std::endl;
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>  

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; -i)
#define INF (1 << 30)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int n;
int ball[11] = {0};

bool solve(int a, int b, int c) {
	if(c == 10) return true;
	if(a < ball[c]) 
		if(solve(ball[c], b, c + 1)) return true;
	if(b < ball[c])	
		if(solve(a, ball[c], c + 1)) return true;
	return false;

}

int main() {
	scanf("%d", &n);
	rep(i, n) {
		rep(j, 10) scanf("%d", &ball[j]);
		printf("%s\n", (solve(0, 0, 0)) ? "YES" : "NO");
	}
	return 0;
}

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

using namespace std;

int n;
int stock[2][11];
int usea[11];

int dfs(int num, int r_num, int l_num) {
	int res = 0;

	if (usea[num+1] > stock[0][r_num]) {
		if (num == 9)
			return 1;
		stock[0][r_num + 1] = num;
		res = dfs(num + 1, r_num + 1, l_num);
		stock[0][r_num + 1] = -1;
		return res;
	}
	else if (usea[num+1] > stock[1][l_num]) {
		if (num == 9)
			return 1;
		stock[1][l_num + 1] = num;
		res = dfs(num + 1, r_num, l_num + 1);
		stock[1][l_num + 1] = -1;
		return res;
	}
	else {
		return 0;
	}
}


int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> usea[j];
		}
		stock[0][0] = -1;
		stock[0][1] = usea[0];
		stock[1][0] = -1;
		if (dfs(0, 1, 0)) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
		stock[0][0] = -1;
		stock[0][1] = -1;
		stock[1][0] = -1;
	}

	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int maxn = 1024;

int a[12], b[12], c[12];

int main() {
    int T; scanf("%d", &T);
    while(T--) {
        for(int i = 0; i < 10; ++i)
            scanf("%d", &a[i]);
        bool flag = false;
        for(int i = 0; i < maxn; ++i) {
            int pos1 = 0, pos2 = 0;
            for(int j = 0; j < 10; ++j) {
                if(i & (1 << j)) b[pos1++] = a[j];
                else c[pos2++] = a[j];
            }
            flag = false;
            for(int j = 0; j < pos1 - 1; ++j) {
                if(b[j] > b[j+1]) {
                    flag = true; break;
                }
            }
            if(flag) continue;
            for(int j = 0; j < pos2 - 1; ++j) {
                if(c[j] > c[j+1]) {
                    flag = true; break;
                }
            }
            if(flag) continue;
            break;
        }
        puts(flag ? "NO" : "YES");
    }
    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 <bits/stdc++.h>
#define INF 114514810
#define FOR(i, r, n) for(int i=(r); i<(n); i++) 
#define REP(i, n) FOR(i, (0), n)

using namespace std;

int n, ct = 1, d[13], flg = 1, t;
vector<int> x, y;

int judge(int ct){
	while (ct < 1023){
		t = ct;
		REP(i, 10){
			if (t & 1) x.push_back(d[i]);
			else y.push_back(d[i]);
			t >>= 1;
		}
		REP(i, x.size() - 1){
			if (x.at(i) > x.at(i + 1)) flg *= 0;
		}
		REP(i, y.size() - 1){
			if (y.at(i) > y.at(i + 1)) flg *= 0;
		}
		if (flg) return 1;
		x.clear(); y.clear(); t = 0; flg = 1; ct++;
	}
	return 0;
}

int main(){
	cin >> n;
	REP(k, n){
		REP(i, 10) cin >> d[i];
		if (judge(1)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

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

#include <string.h>

int a[10];

int memo[10][10+1][10+1];

int search(int i, int j, int k)
{
  if (memo[i][j][k] >= 0)
    return memo[i][j][k];
  
  if (i == 9)
    return memo[i][j][k] = a[i];

  int r = 0;

  if (a[i] > j)
    r = std::max(search(i + 1, a[i], k), r);
		 
  if (a[i] > k)
    r = std::max(search(i + 1, j, a[i]), r);
  
  return r;
}

int main(int argc, char** argv)
{
  int N;

  std::cin >> N;

  while (N --) {
    for (int i = 0; i < 10; i ++)
      std::cin >> a[i];

    memset(memo, -1, sizeof(memo));

    std::cout << (search(0, 0, 0) ? "YES" : "NO") << std::endl;
  }
}

C++: #include <iostream>

using namespace std;

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