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<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
using namespace std;

string func(stack<int>,stack<int>,stack<int>);

int main(){
		  stack<int> s,st,right,left;
		  int loop,num;

		  cin>>loop;
		  for(int i=0;i<loop;i++){

					 while(!s.empty()) s.pop();
					 while(!st.empty()) st.pop();
					 while(!right.empty()) right.pop();
					 while(!left.empty()) left.pop();
					 right.push(0);left.push(0);

					 for(int l=0;l<10;l++){
								cin>>num;
								s.push(num);
					 }
					 while(!s.empty()){
								st.push(s.top());
								s.pop();
					 }

					 cout<<func(st,right,left)<<endl;
		  }
		  return 0;
}

string func(stack<int> st,stack<int> right, stack<int> left){
		  if(st.empty()) return "YES";

		  if(right.top()<st.top()){
					 right.push(st.top());
					 st.pop();
					 if(func(st,right,left)=="YES") return "YES";
					 else{
								st.push(right.top());
								right.pop();
					 }
		  }
		  if( left.top()<st.top()){
					 left.push(st.top());
					 st.pop();
					 if(func(st,right,left)=="YES") return "YES";
					 else{
								st.push(left.top());
								left.pop();
					 }
		  }

		  return "NO";
}

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

C++: #include<iostream>
#include<cstring> 
using namespace std;
int a[10];
bool vis[10];
int main(){
	int t;
	cin>>t;
	while(t--){
		memset(vis, 0, sizeof vis);
		for(int i = 0; i < 10; i++) cin>>a[i];
		int now = 0;
		for(int i = 1; i < 10; i++){
			if(a[i] > a[now]){
				now = i;
				vis[now] = 1;
			}
		}
		bool flag = true;
		now = -1;
		for(int i = 1; i < 10; i++){
			if(!vis[i]){
				if(now == -1) now = i;
				else{
					if(a[i] < a[now]){
						flag = false;
						break;
					}
					else now = i;
				}
			}
		}
		if(flag) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

C++: #include<stdio.h>
int main(void)
{
	int n,i,sum,t,aaa,bbb,nnn;
	char ch,a[10000];
	scanf("%d",&n);
	getchar();
	while(n--)
	{
		t=0;i=0;
		sum=0;aaa=0;bbb=0;
		while((ch=getchar())!='\n')
			a[i++]=ch;
		nnn=i;
		for(i=0;i<nnn;i++)
		{
			if(a[i]>='1'&&a[i]<='9')
			{
				if(a[i+1]=='0')
					sum=10,i++;
				else
					sum=a[i]-'0';
				if(aaa==0)
					aaa=sum;
				else
				{
					if(aaa<sum&&bbb<sum)
						t=1;
					if(aaa>sum)
						bbb=sum;
					else
					{
						if(bbb>sum)
							aaa=sum;
						else
						{
							if(aaa>bbb)
								aaa=sum;
							else
								bbb=sum;
						}
					 } 
				}
			}
			
		}
		if(t==1)
			printf("YES\n");
		else
			printf("NO\n");
	}
}

C++: #include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

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

typedef vector <int> VI;
int a, b;

bool solve( VI L, int d ) {
  if ( d >= (int)L.size() ) {
    return true;
  }
  int ba = a;
  int bb = b;
  if ( L[d] > a ) {
    a = L[d];
    if ( solve( L, d + 1 ) ) return true;
    a = ba;
  }
  if ( L[d] > b ) {
    b = L[d];
    if ( solve( L, d + 1 ) ) return true;
    b = bb;
  }
  return false;
}

int main() {
  int n;
  while ( cin >> n ) {
    for ( int i = 0; i < n; ++ i ) {
      VI L( 10 );
      for ( int j = 0; j < 10; ++ j ) {
	cin >> L[j];
      }
      a = 0;
      b = 0;
      cout << ( solve( L, 0 ) ? "YES" : "NO" ) << endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main(){
  int N;
  cin >> N;
  int boll[10];
  stack<int> B,C;
  for(int i=0;i<N;i++){
    B.push(0); C.push(0);
    for(int j=0;j<10;j++) cin >> boll[j];
    for(int j=0;j<10;j++){
        if(boll[j]>B.top()) B.push(boll[j]);
        else if(boll[j]>C.top()) C.push(boll[j]);
        else{
          cout << "NO" << endl;
          break;
        }
        if(j==9) cout << "YES" << endl;
    }
  }
  return 0;
}

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

int a[10];

bool dfs(int id, int l_last, int r_last){
	if (id == 10)
		return true;
	if (a[id] > l_last && dfs(id + 1, a[id], r_last))
		return true;
	if (a[id] > r_last && dfs(id + 1, l_last, a[id]))
		return true;
	return false;
}

void solve(){
	if (dfs(0, -1, -1))
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i){
		for (int j = 0; j < 10; ++j)
			cin >> a[j];
		solve();
	}
	return 0;
}