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 <vector>
#include <list>
#include <algorithm>
#include <string>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <complex>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

void solve()
{
    int arr[10];
    for (int i = 0; i < 10; ++i)
        cin >> arr[i];
    bool f = false;
    for (int bit = 0; bit < (1 << 10); ++bit)
    {
        bool judge = true;
        vector<int> v1, v2;
        for (int i = 0; i < 10; ++i)
        {
            if (bit >> i & 1)
                v1.push_back(arr[i]);
            else
                v2.push_back(arr[i]);
        }

        int n = v1.size();
        int m = v2.size();
        for (int i = 0; i < n - 1; ++i)
        {
            if (v1[i] < v1[i + 1])
                continue;
            else
                judge = false;
        }

        for (int i = 0; i < m - 1; ++i)
        {
            if (v2[i] < v2[i + 1])
                continue;
            else
                judge = false;
        }

        if (judge)
        {
            f = judge;
            break;
        }
    }
    if (f)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(3);

    int n;
    cin >> n;
    while (n--)
    {
        solve();
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <climits>
using namespace std;
int b = INT_MIN, c = INT_MIN;
bool push(int ball) {
    if(ball > b) b = ball;
    else if (ball > c) c = ball;
    else return(false);
    return(true);
}

int main(void) {
    int num, ans = 0; cin >> num;
    for(int r = 0; r < num; r++) {
        for(int c = 0; c < 10; c++) {
            int input; cin >> input;
            if(!push(input)) ans--;
        }
        if(ans == 0) cout << "YES" << endl;
        else if(ans < 0) cout << "NO" << endl;
    }
    return(0);
}

C++: #include <iostream>
using namespace std;
int main(){
  int b[111],c[111];
  int i,j;
  int a,n;
  int w=0,q=0;
  int x=0,y=0;
  cin >> n;
  for(i=0;i<n;i++){
    for(j=0;j<10;j++){
      cin >> a;
      if(j%2==0){
	b[x]=a;
	if(x==0){
	  x++;
	  continue;
	}
	if(b[x]>b[x-1]){
	  w++;
	}
	x++;
      }
      else{
	c[y]=a;
	if(y==0){
	  y++;
	  continue;
	}
	if(c[y]>c[y-1]){
	  q++;
	}
	y++;
      }
    }
    if(w>=4 && q>=4){
      cout << "YES" << endl;
    }
    else{
      cout << "NO" << endl;
    }
    w=0;
    q=0;
    x=0;
    y=0;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;

int x[15],lside[15],rside[15];
int n,kase;

void dfs(int i,int l,int r){
	if(i > 10){
		kase = 1;
		return ;	
	}
	if(kase)	return ;
	if(x[i]>lside[l]){
		lside[l+1] = x[i];
		dfs(i+1,l+1,r);
	}
	if(x[i]>rside[r]){
		rside[r+1] = x[i];
		dfs(i+1,l,r+1);
	}
}
int main(void){
	cin>>n;
	while(n--){
		for(int i=1;i<=10;i++)
			cin>>x[i];
		kase = 0;
		dfs(1,0,0);
		if(kase)	printf("YES\n");
		else	printf("NO\n");
	}
	return 0;
}

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

int n;
int a[10];


bool dfs(int i, int r, int l) {
    if (i == 9) return a[i] > r || a[i] > l;
    if ( dfs(i+1, a[i+1], l)) return true;
    if ( dfs(i+1, r, a[i+1])) return true;
    return false;
}

void solve() {
    if (dfs(0,a[0],a[0])) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;

int n, k;
stack<int> sb, sc;
bool f = 1;

int main(){
	cin >> n;
	REP(i, n){
		REP(j, 10){
			cin >> k;
			if (sb.empty()){
				sb.push(k);
			}
			else if (sc.empty()){
				sc.push(k);
				if (sb.top() < k){
					sc.pop();
					sc.push(sb.top());
					sb.pop();
					sb.push(k);
				}
			}
			else{
				if (sb.top() < k){
					sb.push(k);
				}
				else if (sc.top() < k){
					sc.push(k);
				}
				else{
					f = 0;
				}
			}
		}
		cout << sb.size() << sc.size() << endl;
		if (f){
			cout << "YES\n";
		}
		else{
			cout << "NO\n";
		}
		while (!sb.empty()){
			sb.pop();
		}
		while (!sc.empty()){
			sc.pop();
		}
		f = 1;
		cout << sb.size() << sc.size() << endl;
	}
}

C++: /*
* Filename:    aoj0033.cpp
* Desciption:  DFS
* Created:     2016-03-02
* Author:      JIngwei Xu [mail:xu_jingwei@outlook.com]
*
*/
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#define INT_MAX 2<<30
using namespace std;
//typedef long long ll;
int a[10],n;
int used[10];
bool ans=false;
bool check(){
	int ss=0;
	for (int i = 0; i < 10; i += 1)
	{
		if(used[i]==0){ss=a[i];break;}
	}
	if(ss==0)return true;
	for (int i = 0; i < 10; i += 1)
	{
		if(used[i]==0){
			if(a[i]<ss)return false;
			else ss=a[i];
		}
	}
	return true;
}
void dfs(int k,int rec){
	if(k==10){
		if(check())ans=true;
		return;
	}
	if(ans)return;
	if(a[k]>rec){
		used[k]=1;
		dfs(k+1,a[k]);
		used[k]=0;
		dfs(k+1,rec);
		if(ans)return;
	}
	else{
		used[k]=0;
		dfs(k+1,rec);
	}
}

int main()
{
	scanf("%d",&n);
	for (int i = 0; i < n; i += 1)
	{
		for (int j = 0; j < 10; j += 1)
		{
			scanf("%d",&a[j]);
		}
		memset(used,0,sizeof(used));
		ans=false;
		used[0]=1;
		dfs(1,a[0]);
		if(ans)printf("YES");
		else printf("NO");
		
	}
	return 0;
}