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>
using namespace std;
int check(int cc[10])
{
    int temp,z=0,x=0;
    for(int i=0;i<10;i++){
	if(cc[i]<x)return 10;
	else if(cc[i]>z)z=cc[i];
	else if(cc[i]<z&&cc[i]>x)x=cc[i];
    }
    return 1;
}

int main()
{
    int log,N,bb[10];
    cin>>N;    
    for(int i=0;i<N;i++){
    	for(int k=0;k<10;k++)cin>>bb[k];
    	log=check(bb);
	if(log==10)cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;

int a[10];

bool dfs(int k, int l, int r) {
	if (k == 10)
		return true;
	if (a[k] > l && dfs(k + 1, a[k], r))
		return true;
	if (a[k] > r && dfs(k + 1, l, a[k]))
		return true;
	return false;
}

int main() {
	int N;
	scanf("%d", &N);
	for (; N > 0; N--) {
		for (int i = 0; i < 10; i++)
			scanf("%d", &a[i]);
		printf(dfs(0, 0, 0) ? "YES\n" : "NO\n");
	}
}

C++: #include <iostream>

using namespace std;

int main( void )
{
	int n, input[10], stA[11], stB[11];
	cin >> n;
	while(n--) {
		for(int i=0; i < 10; ++i) {
			stA[i] = stB[i] = 0;
			cin >> input[i];
		}
		int idxI, idxA, idxB;
		idxI = 2; idxA = idxB = 0;
		stA[0] = input[0];
		if(stA[0] < input[1]) {
			stA[1] = input[1];
			idxA = 1;
		}
		else {
			stB[0] = input[1];
		}
		bool hit = true;
		while(10 > idxI && hit) {
			int tmp = input[idxI];
			if(stB[idxB] < stA[idxA]) { // A
				if(stA[idxA] < tmp) stA[++idxA] = tmp;
				else if(stB[idxB] < tmp) stB[++idxB] = tmp;
				else hit = false;
			}
			else {	// B
				if(stB[idxB] < tmp) stB[++idxB] = tmp;
				else if(stA[idxA] < tmp) stA[++idxA] = tmp;
				else hit = false;
			}
			++idxI;
		}
		if(idxI == 10 && hit)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

C++: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    input.readLine();
    while (input.ready())
    {
      String[] INPUT_STR = input.readLine().split(" ");

      System.out.println(solver(INPUT_STR));
    }

  }

  private static String solver(String[] array)
  {
    int currentA = 0;
    int currentB = 0;
    int currentC = 0;

    for (int i = 0; i < array.length; i++)
    {
      currentA = Integer.parseInt(array[i]);
      if (i % 2 == 0)
      {
        if (currentB > currentA)
        {
          return "NO";
        }
        currentB = currentA;
      }
      else
      {
        if (currentC > currentA)
        {
          return "NO";
        }
        currentC = currentA;
      }
    }
    return "YES";
  }

}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<map>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

bool memo[11][11];
int data[10];

bool ans(int p, int b, int c){
  if(memo[b][c]) return false;
  if(p == 10) return true;
  int d = data[p];
  if(b < d && ans(p+1, d, c)) return true;
  if(c < d && ans(p+1, b, d)) return true;
  memo[b][c] = true;
  return false;
}

int main(){
  int n;
  scanf("%d",&n);
  while(n --> 0){
    memset(memo,0,sizeof(memo));
    REP(i,10) scanf("%d",&data[i]);
    puts(ans(0,0,0)?"YES":"NO");
  }
  return 0;
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define range(i,b) rep(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
	int a,b;
	int n;
	int input;
	bool check;

	while(cin >> n){
		range(i,n){
			a = b = 0;
			range(i,10){
				check = true;
				cin >> input;
				if(input > a){
					a = input;
				}else if(input > b){
					b = input;
				}else{
					check = false;
				}
			}
			if(check) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.ball", "r", stdin);
	string str = "";
	int n;

	getline (cin, str );
	stringstream ssn(str);
	ssn >> n;

	int i,j;
	for (i = 0; i < n; ++i){
		vector <int> ball;
		getline (cin, str );
		stringstream ss(str);
		int b;
		while (ss >> b){
			ball.push_back(b);
		} // end while
		stack <int> A;
		stack <int> B;

		A.push (0);
		B.push (0);

		int size = ball.size();

		A.push (ball[0]);
		for (j = 1; j < size; ++j){
//			cout << "ball[" << j << "]: " << ball[j] << endl;
//			cout << "A:" << A.top() << " B: " << B.top() << endl;
			if (ball[j] < A.top() && ball[j] > B.top() ){
//				cout << "B in" << endl;
				B.push (ball[j]);
			}else if (ball[j] > A.top() && ball[j] < B.top() ){
//				cout << "A in" << endl;
				A.push (ball[j]);
			}else if (ball[j] > A.top() && ball[j] > B.top() ){
				if (ball[j] - A.top() < ball[j] - B.top() ){
//					cout << "A in" << endl;
					A.push (ball[j]);
				}else{
//					cout << "B in" << endl;
					B.push (ball[j]);
				} // end if 
			}else{
				cout << "NO" << endl;
				break;
			} // end if
		} // end for
		if (j == size ){
			cout << "YES" << endl;
		} // end if
	} // end for
		
	return 0;
}

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

int main(){
	int a;
	int b[10];
	cin>>a;
	
	for(int j=0;j<a;j++){
		
			int flg=0;
			
	for(int i=0;i<10;i++){
		cin>>b[i];
		}
		
		stack<int>ta,tb;
		ta.push(b[0]);
		tb.push(0);
		
		for(int k=1;k<10;k++){
			if(b[k]>ta.top()){ta.push(b[k]);}
			else if(b[k]>tb.top()){tb.push(b[k]);}
			else{
				flg++;
				break;
				}
			}
			if(flg==0){cout<<"YES"<<endl;}
			else{cout<<"NO"<<endl;}
		}
		return 0;
	}