Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	for i := 0; i < n; i++ {
		a := -1
		b := -1
		ans := true
		// それぞれの筒の一番上にあるたまの数字に着目すればよい
		for j := 0; j < 10; j++ {
			x := nextInt()
			if x > a {
				a = x
			} else if x > b {
				b = x
			} else {
				ans = false
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

C++: #include <iostream>
#include <queue>
using namespace std;

int n;
queue<int> q;

int main(){
	cin >> n;
	int tmp;
	for(int I=0;I<n;I++){
		q = queue<int>();
		int a = 0;
		for(int i = 0; i < 10; i++){
			cin >> tmp;
			if(a<tmp){
				a = tmp;
			}
			else{
				q.push(tmp);
			}
		}
		a = 0;
		bool f = false;
		while(q.size() > 0){
			tmp = q.front(); q.pop();
			if(a < tmp){
				a = tmp;
			}
			else{
				f = true;
				break;
			}
		}
		if(f){
			cout << "NO" << endl;
		}
		else{
			cout << "YES" << endl;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<fstream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<complex>
#include<set>
#include<map>
#include<list>
#include<vector>
#include<deque>
using namespace std;
typedef long long ll;
typedef vector<int>vec;
typedef vector<vec>mat;
const int INF = 0x3f3f3f3f;
const int Mod = 1e9 + 7;
const double eps = 1e-7;
int main() {
	int a[10];
	int n = 0;
	cin >> n;
	while (n--) {
		int flag = 0;
		memset(a, 0, sizeof(a));
		for (int i = 0; i < 10; i++)
			cin >> a[i];
		for (int cnt = 0; cnt < 1024; cnt++) {//cnt :number of choices
			deque<int> B; deque<int> C;
			for (int i = 0; i < 10; i++) {
				if ((cnt >> i) & 1)B.push_front(a[i]);
				else C.push_front(a[i]);
			}
			reverse(B.begin(), B.end()); reverse(C.begin(), C.end());
			if (is_sorted(B.begin(), B.end()) && is_sorted(C.begin(), C.end())) {
				flag = 1;
				break;
			}
		}
		if (flag)puts("YES");
		else puts("NO");
	}
	//system("pause");
	return 0;
}

C++: #include<cstdio>

int a[10];

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

bool solve(){
    for(int i=0;i<10;i++){
        scanf("%d",a+i);
    }
    return dfs(0,0,0);
}

int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        if(solve()) printf("YES\n");
        else printf("NO\n");
    }
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
//	cut here before submit 
//	freopen ("testcase.Ball", "r", stdin );
	int n;
	scanf ("%d", &n );
	rep (i, n ){
		vector<int> ball(10, 0 );
		rep (j, 10 ){
			scanf ("%d", &ball[j] );
		} // end rep
		stack<int> A, B;
		A.push (ball[0] );
		B.push (0 );
		bool ok = true;
		for (int i = 1; i < 10; i++ ){
			if (A.top() < ball[i] ){
				A.push (ball[i] );
			}else
			if (B.top() < ball[i] ){
				B.push (ball[i] );
			}else{
				ok = false;
				break;
			} // end if
		} // end for
		if (ok ){
			printf ("YES\n" );
		}else{
			printf ("NO\n" );
		} // end if
	} // end loop
		
	return 0;
}

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

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
using namespace std; 

#define MAX 10

int N;
int in[MAX];
vector<string> vs;
string s;

void dfs(int l, int r, int cnt) {
	if(cnt == MAX) s = "YES";
	if(in[cnt] > l) dfs(in[cnt],r,cnt+1);
	if(in[cnt] > r) dfs(l,in[cnt],cnt+1);
}

void solve()
{
	s = "NO";
	dfs(0,0,0);
	vs.pb(s);
}

void input()
{
	cin >> N;
	rep(i,0,N) {
		rep(j,0,MAX) cin >> in[j];
		solve();
	}
}

int main(void)
{
	input();
	rep(i,0,vs.size()) cout << vs[i] << endl;
	return 0;
}

C++: //
// Create by 神舟 on 2015-02-20
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cctype>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <set>
#include <vector>
using namespace std;

#define CLR(x) memset(x,0,sizeof x)
#define ll long long
#define inf 0x3f3f3f3f
const int maxn=1e5+5;
const int MOD=5e5+5;
int n,flag,num[maxn],l[maxn],r[maxn];
void dfs(int ln,int rn)
{

    if(ln+rn==10) flag=1;
    if(flag) return;
    if(num[ln+rn+1]>l[ln]){
        l[ln+1]=num[ln+rn+1];
        dfs(ln+1,rn);
    }
    if(num[ln+rn+1]>r[rn]){
        r[rn+1]=num[ln+rn+1];
        dfs(ln,rn+1);
    }
}
int main()
{
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(0);

	scanf("%d",&n);
	while(n--){
        flag=0;
        CLR(l);
        CLR(r);
        CLR(num);
        l[0]=r[0]=-inf;
        for(int i=1;i<11;scanf("%d",num+i++));
        dfs(0, 0);
        if(flag) printf("YES\n");
        else printf("NO\n");
	}
	return 0;
}

C++: #include <stdio.h>

int main()
{
	int N, ball[10], B[10], C[10], b, c, k;

	scanf("%d", &N);

	for (int i = 0; i < 2; i++){
		scanf("%d %d %d %d %d %d %d %d %d %d", &ball[0], &ball[1], &ball[2], &ball[3], &ball[4], &ball[5], &ball[6], &ball[7], &ball[8], &ball[9]);

		b = 0;
		c = 0;
		k = 0;
		for (int j = 0; j < 10; j++){
			if(b < ball[j] && (ball[j] - b) <= (ball[j] - c)) b = ball[j];
			else if(c < ball[j]) c = ball[j];
			else {k = 1; break;}
		}

		if(k == 0) printf("YES\n");
		else printf("NO\n");
	}
	
	return 0;
}

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

int main()
{
int n;
scanf("%d", &n);
for(int testcase = 0; testcase < n; ++testcase) {
bool yes = false;
int s = 10;
vector<int> x;
x.resize(s);
for(int i = 0; i < s; ++i)
scanf("%d", &x[i]);
for(int bit = 0; bit < (1 << s); ++bit) {
int count = 0;
for(int i = 0; i < s; ++i)
count += (bit >> i) & 1;
if(count != s / 2)
continue;
bool valid = true;
for(int lr = 0; lr < 2; ++lr) {
int prev = -100;
for(int i = 0; i < s; ++i) {
if(((bit >> i) & 1)== lr) {
if(prev >= x[i]) {
valid = false;
break;
}
prev = x[i];
}
}
}
if(valid) {
yes = true;
break;
}
}
printf("%s\n", yes ? "YES" : "NO");
}
return 0;
}

C++: #include<stdio.h>

#include<string.h>

int a[13],vis[13],flag;

void dfs(int x,int l,int r)

{

    int i;

    if(x==11)return; 

    if(flag)return ;

    if(a[x]>l)dfs(x+1,a[x],r);

    else  if(a[x]>r)dfs(x+1,l,a[x]);

    else  {flag=1;return;}

  

}

int main()

{

int T,i,j,k;

scanf("%d",&T);

while(T--)

{

flag=0;

for(i=1;i<=10;i++)

scanf("%d",&a[i]);

memset(vis,0,sizeof(vis));

dfs(1,0,0);

if(flag)printf("NO\n");

else printf("YES\n");

}

return 0;

}