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<cstdio>
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
#include<stack>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()

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

int main(void){
  stack<int> st1;
  stack<int> st2;
  
  int n ;
  cin>>n;
  bool ans;
  rep(j,n){
    ans = false;
    st1.push(0);
    st2.push(0);
    rep(i,10){
      int inp;
      
      cin>>inp;

      if(st1.top()<inp){
	st1.push(inp);
      }else if(st2.top()<inp){
	st2.push(inp);
      }else{
	ans= true;
      }

    }
  if(!ans)cout<<"YES";
  else cout<<"NO";
  cout<<endl;
  }

}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
#include <functional>
const int INF =1e5;
const int MOD = 1e9 + 7;
using namespace std;
typedef pair<int,int> P;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define pb push_back
vector<int> a;
vector<int> b;
int v[10];
bool dfs(int);

int main(){
    int n;
    cin>>n;
    while(n>0){
        rep(i,10){
            cin>>v[i];
        }
        a.erase(all(a));
        b.erase(all(b));
        if(dfs(0)){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
        n--;
    }
    return 0;
}

bool dfs(int i){
    if(i==10) return true;
    vector<int>::iterator itr;
    if(a.size()>0){
        itr= a.end();
        if(v[i]>*itr){
            a.pb(v[i]);
            if(dfs(i+1)) return true;
            a.pop_back();
        }
    }else{
        a.pb(v[i]);
        if(dfs(i+1)) return true;
        a.pop_back();
    }
    if(b.size()>0){
        itr= b.end();
        if(v[i]>*itr){
            b.pb(v[i]);
            if(dfs(i+1)) return true;
            b.pop_back();
        }
    }else{
        b.pb(v[i]);
        if(dfs(i+1)) return true;
        b.pop_back();
    }
    if(i>0){
        vector<int>::iterator itr2;
        itr= a.end();
        itr2= b.end();
        if(v[i]<=*itr && v[i]<=*itr2)return false;
    }
    return false;
}

C++: #include <iostream>

using namespace std;

int main(void) {
    int N, a, b, c;
    cin >> N;
    for (; N--; ) {
        b = c = 0;
        bool ok = true;
        for (int i = 0; i < 10; i++) {
            cin >> a;
            if (a < b && a < c) {
                ok = false;
                break;
            } else if (a < b) {
                c = a;
            } else if (a < c) {
                b = a;
            } else if (c > b) {
                c = a;
            } else {
                b = a;
            }
        }
        cout << (ok ? "YES" : "NO") << endl;
    }
    return 0;
}

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;
}