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<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const int inf = 0x7f7f7f;
//const int maxn = ;

int main() {
//ios::sync_with_stdio(false);
#ifdef LOCAL
freopen("lll.in", "r", stdin);
//freopen(".out", "w", stdout);
#endif
	int t;
	cin >> t;
	while(t--) {
		int a;
		int lt = -1, rt = -1;
		bool flag = true;
		for(int i = 1; i <= 10; i++) {
			cin >> a;
			if(!flag) continue;
			if(a > lt && a > rt) {
				if(a - lt <= a - rt)
					lt = a;
				else
					rt = a;
			} else if(a > lt && a <= rt) {
				lt = a;
			} else if(a <= lt && a > rt) {
				rt = a;
			} else {
				flag = false;
			}
		}

		if(flag) 
			printf("YES\n");
		else 
			printf("NO\n");
	}
}

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

#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>

int main(void){
	int topB,topC;
	int n,tmp;
	int valid;
	
	for (scanf("%d", &n); n--;){
		topB=topC=0;
		valid=1;
		for (int i=0; i<10; i++){
			scanf("%d", &tmp);
			if (tmp > topB) topB=tmp;
			else if (tmp > topC)topC=tmp;
			else {
				valid=0; break;
			}
		}
		printf("%s\n",valid?"YES":"NO");
	}
	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>
#include<cstdlib>
#include<cmath>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;

int N;

int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };

int ball[10];

//int B = 0, C = 0;

int bfs(int n, int B, int C) {
	
	if (n == 10) {
		return true;
	}

	if (B < ball[n]) {
		B = ball[n];
		return bfs(n + 1, B, C);
	}
	if (C < ball[n]) {
		C = ball[n];
		return bfs(n + 1, B , C);
	}
	
	return false;

}

void input(void) {
	for (int i = 0; i < 10; i++) {
		CI ball[i];
	}
	return;
}


int main(void) {
	CI N;

	for (int i = 0; i < N; i++) {
		input();
		if (bfs(0, 0, 0)) {
			CO "YES" E
		}
		else {
			CO "NO" E
		}
	}
	
	return 0;
}

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

C++: #include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 25
using namespace std;
int n,m;
int tmax,tmin;
int a[Maxn];
int ans1[Maxn];
int ans2[Maxn];
int main()
{
    int f;
    cin>>n;
    while(n--)
    {
        f=1;
        MEM(a,0);
        MEM(ans1,0);
        MEM(ans2,0);
        for(int i=1; i<=10; i++)
            cin>>a[i];
        ans1[1]=a[1];
        ans2[0]=0;
        int p1=0,p2=0;
        int i;
        for(i=2; i<=10; i++)
        {
//            if(ans1[p1]>ans[p2])
//            {
//                tmax=ans1[p1];
//                tmin=ans2[p2];
//            }
//            else
//            {
//                tmax=ans2[p2];
//                tmin=ans1[p1];
//            }
            if(a[i]>ans1[p1])
            {
                ans1[++p1]=a[i];
            }
            else if(a[i]>ans2[p2])
            {
                ans2[++p2]=a[i];
            }
            else
            {
                cout<<"NO"<<endl;
                break;
            }
        }
        if(i>10)
            cout<<"YES"<<endl;
    }
}

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

int main()
{
	int n,a;

	std::cin >> n;

	std::vector<int> ball;

	for(int i=0; i<n; ++i)
	{
		for(int i=0; i<10; ++i)
		{
			std::cin >> a;

			ball.push_back(a);
		}
		
		int right=-1,left=-1;

		right = ball[0];

		bool flg1 = 1;

		bool rightOK;

		bool leftOK;

		for(int i=1; i<10; ++i)
		{
			rightOK = ball[i]>right;

			leftOK = (ball[i]>left || left==-1);

			if(rightOK && leftOK)
			{
				if(right>left)
				{
					right = ball[i];
				}
				else
				{
					left = ball[i];
				}
			}
			else if(rightOK)
			{
				right =  ball[i];
			}
			else if(leftOK)
			{
				left = ball[i];
			}
			else
			{
				flg1 = 0;

				break;
			}
		}

		std::cout << (flg1 ? "YES\n" : "NO\n");

		ball.clear();
	}
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

int main() {
	int n; cin >> n;
	int l = 0, r = 0;
	while (n--) {
		bool ok = true;
		rep(i, 10) {
			int b; cin >> b;
			if(l < b) l = b;
			else if (r < b) {
				r = b;
				if (l < r) swap(l, r);
			}
			else {
				ok = false;
			}
		}
		cout << (ok ? "YES" : "NO" ) << endl;
	}
	return 0;
}