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 <limits.h>
#include <queue>
#include <algorithm>
#include <map>


using namespace std;

typedef pair<int,int> P;


const int N=10000;
int ball[10];
int n=0;

int A[10],B[10];

bool solve(int i,int a,int b,bool IS_A){

  //cout<<"a,b:"<<a<<","<<b<<endl;
  
  if(i==10) return true;

  if(IS_A){
    A[a]=ball[i];
    if(a>0 && A[a-1]>A[a]){
      //cout<<"hoge"<<endl;
      return false;
    }
    a++;
  }
  else{
    B[b]=ball[i];
    if(b>0 && B[b-1]>B[b]){
      //cout<<"huge"<<endl;
      return false;
    }
    b++;
  }
  
  bool t1,t2;
  
  //when ball[i] is pushed into A or B
  return (solve(i+1,a,b,true)||solve(i+1,a,b,false));
}





int main(){

  cin>>n;
  
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>ball[j];
    }
    if(solve(0,0,0,true)||solve(0,0,0,false)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }


  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,a;
  int b = 11,c = 11;
  cin >> n;
  while(n--){
    for(int i = 0;i < 10;i++){
      cin >> a;
      if(b > a)b = a;
      else if(c > a)c = a;
      else {
	cout << "NO" << endl;
	return;
      }  
    }
    cout << "YES" << endl;
  }
}

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>

using namespace std;

int main(void)
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i=0; i<n; i++) {
        int a[10];
        bool f = 0;
        for(int j=0; j<10; j++) cin >> a[j];
        for(int j=0; j<8; j++) {
            if(a[j] > a[j+1] && a[j+1] > a[j+2]) {
                f = 1;
                break;
            }
        }
        printf("%s\n", f ? "NO" : "YES");

    }

    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>

typedef long long LL;
using namespace std;

const int cnt = 10;
int num[cnt];
vector<int> a, b;

bool DFS(int i)
{
	if (i == 10) return true;
	if (num[i] > a.back()) {
		// cout << i << " sum1 " << num[i] << endl;
		a.push_back(num[i]); if (DFS(i + 1)) return true; a.pop_back();
	}
	if (num[i] > b.back()) {
		// cout << i << " sum2 " << num[i] << endl;
		b.push_back(num[i]); if (DFS(i + 1)) return true; b.pop_back();
	}
	return false;
}


int main()
{
	int T;
	scanf("%d", &T);
	while(T--) {
		for (int i = 0; i < cnt; i++) scanf("%d", &num[i]);
		a.clear(); b.clear(); b.push_back(num[0]); a.push_back(0);
		if (DFS(1)) cout << "YES\n";
		else cout << "NO\n";
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(void){
	int n,a,b,c;
	bool f;
	cin>>n;
	for(int i=0;i<n;i++){
		f=true;b=0;c=0;
		for(int j=0;j<10;j++){
			cin>>a;
			if(b>a&&c>a){
				f=false;
				break;
			}else if(b<a && c<a){
				if(b>=c)b=a;
				else c=a;
			}else if(b<a){
				b=a;
			}else if(c<a){
				c=a;
			}
		}
		if(f)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int ball[10];
bool can = false;

void search(int r,int l,int n){
  cout << n << endl;
  if(n>=10) can = true;
  if(r<ball[n]) search(ball[n],l,n+1);
  if(l<ball[n]) search(r,ball[n],n+1);

}
 
int main(){
  int n;
  cin >> n;
  REP(i,n){
	REP(i,10) cin >> ball[i];
	int right=0;
	int left=0;
	can = false;
	search(right,left,0);
	if(can) cout << "Yes" << endl;
	else cout << "No" << endl;
  }

}

C++: #include <iostream>
 
using namespace std;
 
int main()
{
    int n, s, t, c, p, f;
    cin >> n;
     
    while(n--)
    {
        s = f = t = 0;
        for(int i = 0; i < 10; i++)
          {
            cin >> p;
            if(p < s && p < t){
                f = 1;
            }
                else if(p > s){
                s = p;
            } 
                else if(p > t){
                t = p;
            }  
                else {
                f = 1;
            }
        }
        if(f == 0){
            cout << "YES" << endl;
        } 
            else {
            cout << "NO" << endl;
        }
    }
     
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  for(int t=0;t<n;t++){
    int a,d,b=0,c=0,end=0;
    cin >> a;
    b=a;
    cin >> a;
    c=a;
    for(int i=2;i<10;i++){
      cin >> a;
      if(b>c){
	if(b<a){
	  b=a;
	}
	else if(c<a){
	  c=a;
	}
	else{
	  end++;
	}
      }
      else{
	if(c<a){
	  c=a;
	}
	else{
	  end++;
	}
      }
    }
    if(end==0){
      cout << "YES" << endl;
    }
    else{
      cout << "NO" << endl;
    }
  }
}

C++: /*
* @Author: key
* @Date:   2016-03-04 11:52:34
* @Last Modified by:   key
* @Last Modified time: 2016-03-04 12:37:55
*/

#include <iostream>

using namespace std;

int c[10];

int a[10],b[10];

bool flag;

void dfs(int x,int y,int z){
    if(x > 9){
        flag = true;
        return;
    }

    if(flag)
        return;

    if(y < 0 || c[x] > a[y]){
        a[y+1] = c[x];
        dfs(x+1,y+1,z);
    }

    if(z < 0 || c[x] > b[z]){
        b[z+1] = c[x];
        dfs(x+1,y,z+1);
    }

}

int main(){

    int n;

    cin >> n;

    while(n--){
        flag = false;
        for(int i = 0; i < 10; i++){
            cin >> c[i];
            a[i] = 0;
            b[i] = 0;
        }
        dfs(0,-1,-1);
        if(flag)
            cout << "Yes" <<endl;
        else
            cout << "No" << endl;
    }

    return 0;
}

C++: #include <stdio.h>


void solve(){
	int tan;
	int sho;

	int flg = 0;
	for (int i=0; i<10; ++i){
		int tama;
		scanf("%d", &tama);
		if (!i) {
			tan = tama;
			continue;
		}
		if (i==1) {
			sho = tama;
			continue;
		}
		if (i%2 == 0){
			if (tama < tan) flg = 1;
			tan = tama;
		}else {
			if (tama < sho) flg = 1;
			sho = tama;
		}
	}
	printf("%s\n", flg?"NO":"YES");
}

int main (){
	int t;
	scanf("%d", &t);
	while (t --){
		solve();
	}
	return 0;
}