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

int main(){
	int n,a,flag;
	stack<int> b,c;
	cin >> n;
	for (int i = 0; i < n; i++){
		while (b.size()) b.pop();
		while (c.size()) c.pop();
		flag = 0;
		b.push(0);
		c.push(-1);
		for (int j = 0; j < 10; j++) {
			cin >> a;
			if (b.top() > c.top()){
				if (c.top() > a) flag = 1;
				else if (b.top() > a) c.push(a);
				else b.push(a);
			}
			else {
				if (b.top() > a) flag = 1;
				else if (c.top() > a) b.push(a);
				else c.push(a);
			}
		}
		if (flag) cout << "NO" << endl;
		else cout << "YES" << endl;
	}
}

C++: #include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <iostream>
using namespace std;
int n;
int a[15],b[15],c[15];
bool dfs(int i,int j)
{
    if(i + j == 10)
        return true;
    if(a[i] > b[i - 1]){
        b[i] = a[i];
        dfs(i + 1,j);
    }
    else
    {
        if(a[j] > c[j - 1]){
            c[j] = a[i];
            dfs(i,j + 1);
        }
    }
}
int main()
{
    while(~scanf("%d",&n))
    {
        while(n --){
            for(int i = 0; i < 10; i++)
                scanf("%d",&a[i]);
            memset(b,0,sizeof(b));
            memset(c,0,sizeof(c));
            int ans = dfs(0,0);
            if(ans == true)
                printf("YES\n");
            else
                printf("NO\n");
        }
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define INF INT_MAX/3
#define vc vector<int>
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define ll long long
#define eps 1e-14
int dx[] = { 1,-1,0,0,0 };
int dy[] = { 0,0,1,-1,0 };


int x[10];
vc ans;
void solve() {
	int left, r;
	left = x[0];
	r = 0;
	//?????¨?????§??§??????????????§?????¶??????????????´???????????\??????
	for (int i = 1; i < 10; i++) {
		//???????????¶??????????????????
		if (left > x[i] && r > x[i]) {
			//cout << "NO" << endl;
			ans.push_back(0);
			return;
		}
		//?????????????????¶????????????
		if (x[i] < left && r < x[i]){
			r = x[i];
			continue;
		}
		else if (x[i] < r&&left < x[i]) {
			left = x[i];
			continue;
		}
		else { //???????????????????????´???
			if (r < left) {
				left = x[i];
				continue;
			}
			else {
				r = x[i];
				continue;
			}
		}
		
	}
	//cout << "Yes" << endl;
	ans.push_back(1);
}

int main() {
	int n;
	cin >> n;
	REP(i, n) {
		REP(j, 10)
			cin >> x[j];
		solve();
	}
	for (int i = 0; i < ans.size(); i++) {
		if (ans[i] == 0)
			cout << "NO" << endl;
		else
			cout << "YES" << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int N;
  cin>>N;
  while(N--){
    int B,C=0,i=0,b[10];
    bool f=true;
    cin>>b[0]>>b[1]>>b[2]>>b[3]>>b[4]>>b[5]>>b[6]>>b[7]>>b[8]>>b[9];
    while(i<10){
      if(b[i]<B&&b[i]<C){
	f=false;break;
      }else if(B<b[i]){
	if(B<C&&C<b[i])C=b[i];
	else B=b[i];
      }else if(C<b[i]){
	C=b[i];
      }
      i++;
    }
    cout<<(f?"YES":"NO")<<endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
int a,b,temp,n;
int main()
{
    int n;
    cin>>n;
    while(n--){
        int flag=1;
        a=0,b=0;
        queue<int>que;
        //while(que.size())que.pop();
        for(int i=0;i<10;i++){
            cin>>temp;
            que.push(temp);
        }
        while(que.size()){
            temp=que.front();
            que.pop();
            if(temp<=a&&temp<=b){
                cout<<"NO\n";
                flag=0;
                break;
            }
            else if(temp<=a&&temp>b)b=temp;
            else if(temp<=b&&temp>a)a=temp;
            else {
                if(a>=b)a=temp;
                else b=temp;
            }
        }
        if(flag)cout<<"YES\n";
    }

    return 0;
}

C++: //-*-coding:utf-8-*-
//----------------------------------------------------------
// module: main
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0033
//----------------------------------------------------------
#include <algorithm>
#include <vector>
#include <deque>
#include <map>

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

const int MAXL = 10;

int numbers[MAXL];

bool solve(){
    int a = -1;
    int b = -1;
    for (int i = 0; i < 10; ++i)
        {
            if (a > b && b > 0) {
                if (numbers[i] > a) { a = numbers[i]; }
                else if (numbers[i] > b) { b = numbers[i]; }
                else return false;
            }
            else if (b > a && a > 0){
                if (numbers[i] > b) { b = numbers[i]; }
                else if (numbers[i] > a) { a = numbers[i]; }
                else return false;
            }
                
            if(a < 0){a = numbers[i]; continue; };
            if(b < 0){b = numbers[i]; continue; };
        }
    return true;
};

int main(int argc, char *argv[])
{
    int c;
    scanf("%d", &c);
    for (int i = 0; i < c; ++i)
        {
            scanf("%d %d %d %d %d %d %d %d %d %d", &numbers[0], &numbers[1], &numbers[2], &numbers[3], &numbers[4], &numbers[5], &numbers[6], &numbers[7], &numbers[8], &numbers[9]);
            bool result = solve();
            if ( solve() ){ printf("YES\n"); }
            else { printf("NO\n"); }
        }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;

int main(void) {

  int n;
  cin >> n;
  while(n != 0){
    n--;
    int l = 0;
    int r = 0;
    int tmp;
    bool f = true;
    for(int i=0; i<10; i++){
      cin >> tmp;
      if( l < tmp ) l = tmp;
      else if( r < tmp ) r = tmp;
      else f = false;
    }
    cout << ( f ? "YES" : "NO" ) << endl;
  }


  return 0;
}


// EOF

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

int n;
int a[10];
vector<int> l, r;
vector<int> emp;

bool dfs(int p){
//	printf("p=%d\n", p);
	/*
	printf("l ");
	for(int i=0; i<l.size(); i++){
		printf("%d ", l[i]);
	}
	printf("\nr ");
	for(int i=0; i<r.size(); i++){
		printf("%d ", r[i]);
	}
	printf("\n");
*/
	if(p == 10) return true;
	l.push_back(a[p]);
	if(l.size() == 1 || l[l.size() - 2] < l[l.size() - 1]){
		return dfs(p+1);
	}else{
		l.pop_back();
		r.push_back(a[p]);
		if(r.size() == 1 || r[r.size() - 2] < r[r.size() - 1]){
			return dfs(p+1);
		}else{
			r.pop_back();
			return false;
		}
	}
}

int main(){
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		l = emp;
		r = emp;
		for(int j=0; j<10; j++){
			scanf("%d", &a[j]);
		}
		if(dfs(0)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}