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;
#define forn(i,n) for(int i=0;i<int(n);i++)
int a[10];
int main(){
	int t;
	cin>>t;
	while(t--){
		forn(i,10) cin>>a[i];
		int fi=0,se=0;
		bool b=true;
		forn(i,10){
			if(fi<a[i]&&se<a[i]){
				if(fi<=se) se=a[i];
				else fi=a[i];
			}
			else if(fi<a[i]) fi=a[i];
			else if(se<a[i]) se=a[i];
			else{
				b=false;
				break;
			}
		}
		if(b) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
vector<int> A = {-1};
vector<int> B = {-1};
int num[10];
bool flag = false;
void push(int i)
{
	if (i == 10)
		flag = true;
	else
	{
		if (A.back() < num[i])
		{
			A.push_back(num[i]);
			push(i + 1);
			A.pop_back();
		}
		if (B.back() < num[i])
		{
			B.push_back(num[i]);
			push(i + 1);
			B.pop_back();
		}
	}
}
int main()
{
	int k;
	cin >> k;
	while (k--)
	{
		flag = false;
		for (int i = 0; i <= 9; ++i)
			cin >> num[i];
		push(0);
		if (flag == true)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <map>
#include <vector>
#include <queue>
#define LL long long
#define PII pair<int, int>
using namespace std;
const int MAXN = 40;

int p[10], pre1, pre2;

bool dfs(int pos) {
    if (pos >= 10) return true;
    int tmp1 = pre1, tmp2 = pre2;

    if (p[pos] > pre1) {
        pre1 = p[pos];
        if (dfs(pos + 1)) return true;
        pre1 = tmp1;
    }

    if (p[pos] > pre2) {
        pre2 = p[pos];
        if (dfs(pos + 1)) return true;
        pre2 = tmp2;
    }

    return false;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    int T;
    cin >> T;
    for (int t = 0; t < T; t++) {
        for (int i = 0; i < 10; i++) cin >> p[i];
        pre1 = pre2 = -1;
        if (dfs(0)) cout << "YES\n";
        else cout << "NO\n";
    }
}

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, 9) {
      int a = nextInt();
      if (bs.top() == cs.top()) {
        if (bs.top() > a) {
          flag = false;
          break;
        }
        bs.push(a);
      } else if (bs.top() > cs.top()) {
        if (bs.top() > a) {
          if (cs.top() > a) {
            flag = false;
            break;
          }
          cs.push(a);
        } else {
          bs.push(a);
        }
      } else {
        if (cs.top() > a) {
          if (bs.top() > a) {
            flag = false;
            break;
          }
          bs.push(a);
        } else {
          cs.push(a);
        }
      }
    }
    if (flag) {
      PRINT("YES");
    } else {
      PRINT("NO");
    }
  }
	return 0;
}
// END   //////////////////////////////////////////////////////////////

C++: #include <stdio.h>

int main(void) {
  int i, j, k, n, a[10];
  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    for(j = 0; j < 10; ++j) scanf("%d", &a[j]);
    int bea = 0, beb = -1, ans = 1;
    for(j = 0; j < 10; ++j) {
      if(bea > beb) {
        if(bea < a[j]) bea = a[j];
        else if(beb < a[j]) beb = a[j];
        else {
          ans = 0;
          break;
        }
      } else {
        if(beb < a[j]) beb = a[j];
        else if(bea < a[j]) bea = a[j];
        else {
          ans = 0;
          break;
        }
      }
    }
    if(ans) printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
int a[10];
stack<int> b[2];
bool dfs(int i, int to)
{
	if (i == 9)
	{
		if (a[i] > b[to].top() || a[i] > b[!to].top())
			return true;
		else
			return false;
	}
	else if (a[i] > b[to].top() && a[i] > b[!to].top())
	{
		b[to].push(a[i]);
		if (dfs(i+1, to))
			return true;
		b[to].pop();
		b[!to].push(a[i]);
		if (dfs(i+1, !to))
			return true;
		return false;
	}
	else if (a[i] > b[to].top())
	{
		b[to].push(a[i]);
		if (dfs(i+1, to))
			return true;
		b[to].pop();
		return false;
	}
	else if (a[i] > b[!to].top())
	{
		b[!to].push(a[i]);
		if (dfs(i+1, !to))
			return true;
		b[!to].pop();
		return false;
	}
	else
		return false;
}
int main()
{
	int n, i, j;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < 10; j++)
			cin >> a[j];
		b[0].push(0);
		b[1].push(0);
		if (dfs(0, 0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

C++: #include <iostream>

int main(void)
{
	int n;
	std::cin >> n;
	for(int j=0; j<n; j++)
	{
		int top[2]={0,0};
		for(int i=0; ; i++)
		{
			std::cout << top[0] << top[1] << std::endl;
			int next;
			std::cin >> next;
			if((top[0] < next)&&(top[1] < next))
			{
				if(top[0] < top[1])
					top[1]=next;
				else
					top[0]=next;
			}
			else if(top[0] < next)
				top[0]=next;
			else if(top[1] < next)
				top[1]=next;
			else
			{
				std::cout << "NO" << std::endl;
				for(int k=1; k+i < 10; k++)
					std::cin >>next;
				break;
			}

			if(i==9)
			{
				std::cout << "YES" << std::endl;
				break;
			}
		}
	}
	return 0;
}

C++: #include <stdio.h>

int main(void)
{
	int data[10];
	int n;
	int a, b;
	int j;
	
	scanf("%d", &n);
	
	a = b = 0;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < 10; j++){
			scanf("%d", &data[j]);
		}
		for (j = 0; j < 10; j++){
			if (a < data[j]){
				a = data[j];
			}
			else if (b < data[j]){
				b = data[j];
			}
			else {
				break;
			}
		}
		
		if (j == 10){
			puts("YES");
		}
		else {
			puts("NO");
		}
	}
	
	return (0);
}