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>
using namespace std;


int main()
{
	int n;
	cin >> n;
	int a[11],min_a=0, min_b=0;
	bool flag=true;
	while (n--)
	{
		for (int i = 0; i < 10; i++)
			cin >> a[i];
		for (int j = 0; j < 10; j++)
		{
			if (a[j] >= min_a)
			{
				min_a = a[j];
			}
			else if (a[j] >= min_b)
			{
				min_b = a[j];
			}
			else
			{
				flag = false;
			}
		}
		if (flag==true)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
    return 0;
}

C++: #include<iostream>
#include<stack>

using namespace std;

int main() {

	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int A[10];
		for (int j = 0; j < 10; j++)cin >> A[j];
		stack<int> B, C;
		B.push(A[0]);
		for (int j = 1; j < 10; j++) {
			if (B.top() < A[j])B.push(A[j]);
			else if (C.empty() == 1)C.push(A[j]);
			else if (C.top() < A[j])C.push(A[j]);
			else {
				cout << "NO" << endl;
				break;
			}
			if (j == 9)cout << "YES" << endl;
		}
	}

	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

int n;
const int m = 10;
int *data;
int *lp;
int *rp;

//return...fail:0, success:1
bool dfs(int i, int l, int r)
{
	if (i == m)
		return true;

	if (i<m && l<m && lp[l-1]<data[i]) {
		lp[l] = data[i];
		if (dfs(i+1, l+1, r))
			return true;
	}

	if (i<m && r<m && rp[r-1]<data[i]) {
		rp[r] = data[i];
		if (dfs(i+1, l, r+1))
			return true;
	}

	return false;
}

int main()
{
	int i, j;
	data = (int *)calloc(m, sizeof(int));
	lp = (int *)calloc(m, sizeof(int));
	rp = (int *)calloc(m, sizeof(int));
	
	scanf("%d ", &n);
	for (i=0; i<n; i++) {
		for (j=0; j<m; j++)
			scanf("%d ", &(data[j]));

		memset(lp, 0, sizeof(int));
		memset(rp, 0, sizeof(int));

	lp[0] = data[0];
	if (dfs(1, 1, 0))
		puts("YES");
	else
		puts("NO");

/*
		//check input
		for (j=0; j<m; j++)
			printf("%d ", data[j]);
		puts("");
*/
	}

	free(data);
	free(lp);
	free(rp);
	return 0;
}

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

int A[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int B[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

bool isSorted(void)
{
	int i = 1;
	while(A[i]!=0 && i<=9)
	{
		if(A[i] < A[i-1]) return false;
		i++;
	}

	i = 1;
	while(B[i]!=0 && i<=9)
	{
		if(B[i] < B[i-1]) return false;
		i++;
	}

	return true;
}

int main(void)
{
	int n;
	cin >> n;
	bool enable = false;
	for(int i=0; i<n; i++)
	{
		int X[10];
		for(int j=0; j<10; j++)
			cin >> X[j];

		for(int j=0; j<1024; j++)
		{
			int a = 0, b = 0;
			int e = 1;
			for(int k=0; k<10; k++)
			{
				if( j & e )
				{
					A[a] = X[k];
					a++;
				}
				else
				{
					B[b] = X[k];
					b++;
				}
				e *= 2;
			}
			if(isSorted())
			{
				enable = true;
			}

			//initialize
			for(int j=0; j<10; j++)
			{
				A[j] = 0; B[j] = 0;
			}
		}
		if(enable) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

C++: #include <map>
#include <vector>
#include <queue>
#include <cmath>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <memory.h>
#include <algorithm>
#include <limits.h>

using namespace std;

int main()
{
	int T;

	cin>>T;
	while(T--)
	{
		int a,b;
		a=b=INT_MIN;
		int temp;
		int i;

		for(i=0;i<10;i++)
		{
			cin>>temp;
			if(temp>a)
			{
				a=temp;
				continue;
			}
			if(temp>b)
			{
				b=temp;
				continue;
			}
			break;
		}

		if(i==10)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }



#define index_of(a, x) distance(a.begin(), lower_bound(a.begin(), a.end(), x));
vector<int> longestSubstr(const vector<int>& a) {
	int n = (int)a.size();
	vector<int> A(n, iINF);
	vector<int> id(n);
	
	for (int i=0; i<n; i++) {
		id[i] = index_of(A, a[i]);
		A[ id[i] ] = a[i];
	}
	
	int m = *max_element(id.begin(), id.end());
	vector<int> b(m+1);
	for (int i=n-1; i>=0; i--) if (id[i] == m) b[m--] = a[i];
	return b;
}

#define MAX 10

int main() {
	int n; cin >> n;
	
	for_(i, 0, n) {
		vci a(MAX);
		for_(j, 0, MAX) cin >> a[j];
		vci b = longestSubstr(a);
		vci rest;
		
		for_(j, 0, MAX) if (!binary_search(all(b), a[j])) rest.pb(a[j]);
		
		bool ok = true;
		for_(j, 1, (int)rest.sz) if (rest[j-1]>rest[j]) ok = false;
		
		if (ok) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	cin>>n;
	while(n--){
		vector<int>in(10);
		rep(i,10)cin>>in[i];
		vector<int>a,b;
		a.pb(in[0]);
		bool h=true;
		loop(i,1,10){
			if(a[a.size()-1]<in[i])a.pb(in[i]);
			else if(b.size()==0||b[b.size()-1]<in[i])b.pb(in[i]);
			else {h=false;break;}
		}
		if(h)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

C++: // 2013/10/22 Tazoe

#include <iostream>
using namespace std;

int A[10];

bool DFS(int I, int B, int C){
	if(I==10)
		return true;

	if(A[I]>B && DFS(I+1, A[I], C))
		return true;

	if(A[I]>C && DFS(I+1, B, A[I]))
		return true;

	return false;
}

int main()
{
	int N;
	cin >> N;

	for(int i=0; i<N; i++){
		for(int j=0; j<10; j++){
			cin >> A[j];
		}

		if(DFS(0, 0, 0)){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}

	return 0;
}

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

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

	while(cin >> n){
		vector<int> ball;
		a = b = 0;
		check = true;
		rep(i,10){
			cin >> g;
			ball.insert( ball.begin(), g);
		}
		rep(i,10){
			if(a < ball.back() && b < ball.back()){
				if(a > b){
					a = ball.back();
				}else{
					b = ball.back();
				}
			}else if(a < ball.back()){
				a = ball.back();
			}else if(b < ball.back()){
				b = ball.back();
			}else{
				check = false;
			}
			ball.pop_back();
		}
		if(check) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}