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 <array>

using namespace std;

int main()
{
        int set_number, L, R, flag = 0;
        cin >> set_number;
        array< int, 10 > ar;

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

                L = ar[0];
                R = 0;
                for ( int j = 1 ; j < 10 ; j++ )
                {
                        if ( L < ar[j] )
                        {
                                L = ar[j];
                        }
                        else if ( L > ar[j] )
                        {
                                if ( R < ar[j] )
                                {
                                        R = ar[j];
                                }
                                else
                                {
                                        fprintf( stdout, "No\n" );
                                        flag = 1;
                                        break;
                                }
                        }
                }

                if ( flag == 0 )
                {
                        fprintf( stdout, "Yes\n" );
                }
        }

        return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
int ta[10];
bool dfs(int h,int a,int b){
	if(h==9)return true;
	int now=ta[h];
	bool ret=0;
	if(now>a)ret=dfs(h+1,now,b);
	if(now>b)ret=dfs(h+1,a,now);
	return ret;
}

int main(){
	int n;
	cin>>n;
for(int i=0;i<n;i++){
for(int i=0;i<10;i++)cin>>ta[i];
(dfs(0,0,0))?cout<<"YES"<<endl:cout<<"NO"<<endl;
}
	return 0;
}

C++: #include <iostream>

#define MAX 10
using namespace std;

int main(){
  int count;
  int ball1,ball2,ball;
  cin >> count;
  for(int i=0;i<count;i++){
    ball1=0;ball2=0;
    for(int j=0;j<MAX;j++){
      cin >>ball;
      //cout << ball1 << " " << ball2 << endl;
      //      cout << ball << endl;
      //cout << j << endl;
      if(ball1 < ball || ball2 < ball){
	if(ball2<ball){
	  ball2=ball;
	}
	else{
	  ball1 = ball;
	}
	if(j==MAX-1){
	  cout << "YES";
	}
      }
      else{
	cout << "NO";
	for(int k=0;k<MAX-j;k++) cin >>ball;
	break;
      }
    }
    cout << endl;
  }
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n--){
    int lot[10],save[100][2]={0},tag=0,a,b;
    bool f = true;
    for(int i=0; i<10; i++) cin >>lot[i];
    a = lot[0];
    b = 0;
    for(int i=1; i<10; i++){
      if(a<lot[i] && b>lot[i]) a = lot[i];
      else if(a>lot[i] && b<lot[i]) b = lot[i];
      else if(a<lot[i] && b<lot[i]){
	save[tag][0] = a;
	save[tag][1] = i;
	a = lot[i];
	tag++;
      }
      else if(a>lot[i] && b>lot[i]){
	if(tag == 0){
	  f = false;
	  break;
	}
	else{
	  a = save[tag-1][0];
	  i = save[tag-1][1];
	  b = lot[i];
	  tag--;
	}
      }
    }
    if(f) cout <<"YES"<<endl;
    else cout <<"NO"<<endl;
  }
  return 0;
}

C++: /*
P135
POJ 2718 Smallest Difference
*/


#include <iostream>
#include <map>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <functional>
#include <string.h>
using namespace std;

int a[10];
void read()
{
    for(int i=0; i<10; ++i)
        scanf("%d", a+i);
}

void solve()
{
    int x1=0, x2=0;
    bool ans = true;
    for(int i=0; i<10; ++i)
    {
        if(x1 < x2) swap(x1, x2);
        if(x1 < a[i]) x1 = a[i];
        else if(x2 < a[i]) x2 = a[i];
        else {ans = false; break;}
    }
    if(ans) printf("YES\n");
    else printf("NO\n");
}



vector<int> L_bucket;
vector<int> R_bucket;

bool dfs2(int d){
    if(d == 10) return true;
    bool flag;
    if(L_bucket.size() == 0 || L_bucket.back() < a[d]){
        L_bucket.push_back(a[d]);
        flag = dfs2(d+1);
        L_bucket.pop_back();
    }
    if(flag) return true;
    if(R_bucket.size() == 0 || R_bucket.back() < a[d]){
        R_bucket.push_back((a[d]));
        flag = dfs2(d+1);
        R_bucket.pop_back();
    }
    if(flag) return true;
    return false;
}

void solve2()
{
    if(dfs2(0)) printf("YES\n");
    else printf("NO\n");
}

int main()
{
    int T;
    scanf("%d", &T);
    while(T--){
        read();
        solve2();
    }
}

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

int data[10];

int solve(int i, int a, int b){

  if(i == 10) return 1;

  int ans = 0;
  if(data[i] > a) ans += solve(i+1, data[i], b);
  if(data[i] > b) ans += solve(i+1, a, data[i]);

  return ans;
}

int main(){

  int n;

  cin >> n;
  while(n--){

    for(int i=0;i<10;i++) cin >> data[i];

    if(solve(0, 0, 0)) cout << "YES\n";
    else cout << "NO\n";

  }

}

C++: #include<cstdio>

int main(){
	int n, b, c, t;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		b = c = 0;
		for(int j = 0; j < 10; j++){
			scanf("%d", &t);
			if(b < t){
				b = t;
			}else{
				if(c < t){
					c = t;
				}else{
					t = 11;
					break;
				}
			}
			if(b < c){
				t = b;
				b = c;
				c = t;
			}
		}
		if(t - 11){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}

C++: #pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin>>n;
    while(n--){
        vector<int> a(10);
        for(int i=0; i<10; i++) cin>>a[i];

        string ans = "NO";
        for(int bit=0; bit<(1<<10); bit++){
            vector<int> l, r;
            for(int i=0; i<10; i++){
                if(bit & (1 << i)) l.emplace_back(a[i]);
                else r.emplace_back(a[i]);
            }

            bool valid = true;
            for(int i=0; i+1<l.size(); i++){
                if(l[i] > l[i+1]) valid = false;
            }
            for(int i=0; i+1<r.size(); i++){
                if(r[i] > r[i+1]) valid = false;
            }

            if(valid) ans = "YES";
        }

        cout << ans << endl;
    }

    return 0;
}