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

int main() {
	int n;
	int d[10];
	int va[10];
	int vb[10];

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

		int ca = 0, cb = 0;
		va[0] = d[0];
		ca++;
		if (d[1] > va[0]) {
			va[1] = d[1];
			ca++;
		}

		else {
			vb[0] = d[1];
			cb++;
		}

	for (int j = 2; j < 10; j++) {

			if (d[j] > va[ca-1]) {
				va[ca] = d[j];
				ca++;
			}

			else if (d[j] > vb[cb-1]) {
				vb[cb] = d[j];
				cb++;
			}

			else {
				goto FINLOOP;
			}

		}

	FINLOOP:

	if (ca + cb == 10) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

		for (int i = 0; i < 10; i++) {
			va[i] = 0;
		}
		for (int i = 0; i < 10; i++) {
			vb[i] = 0;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

int a[11];
bool ok = false;

void solve(int i, vector<int> x, vector<int> y) {
    if(i >= 10) {
        bool tmp = true;

        rep(j, x.size()-1) {
            if (x[j] > x[j+1]) tmp = false;
        }
        rep(j, y.size()-1) {
            if (y[j] > y[j+1]) tmp = false;
        }

        ok |= tmp;
        return;
    }

    x.push_back(a[i]);
    solve(i+1, x, y);
    x.pop_back();
    y.push_back(a[i]);
    solve(i+1, x, y);
    y.pop_back();

    return;
}

int main() {
    int n;
    cin >> n;
    rep(i, n) {
        rep(j, 10) cin >> a[j];
        ok = false;
        vector<int> x, y;
        solve(0, x, y);
        cout << (ok ? "YES" : "NO") << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int a[10],n;

bool dfs(int i,int j,int k)
{
    if(i==10) return 1;
    if(a[i]>j&&a[i]>k) return dfs(i+1,a[i],k) || dfs(i+1,j,a[i]);
    else if(a[i]>j) return dfs(i+1,a[i],k);
    else if(a[i]>k) return dfs(i+1,j,a[i]);
    return 0;
}

int main()
{
    //mine
    ios::sync_with_stdio(false);
    cin>>n;
    while(n--){
        for(int i=0;i<10;i++) cin>>a[i];
        if(dfs(0,0,0)) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

C++: //
// Created by yijiezhu on 12/20/16.
//

#include <bitset>
#include <iostream>
using namespace std;

int n, ball[10];

bool valid(int iter) {
    int left = 0, right = 0;
    auto bs = bitset<10>(iter);
    for (int i = 0; i < 10; i++) {
        if (bs[i]) {
            if (ball[i] < left) return false;
            left = ball[i];
        } else {
            if (ball[i] < right) return false;
            right = ball[i];
        }
    }
    return true;
}

int main() {
    cin >> n;
    while (n-- > 0) {
        for (int i = 0; i < 10; i++) {
            cin >> ball[i];
        }
        bool found = false;
        for (int iter = 0; iter < (1 << 10); iter++) {
            if (valid(iter)) {
                cout << "YES\n";
                found = true;
                break;
            }
        }
        if (!found) cout << "NO\n";
    }
}

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

int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		int k = 10;
		int x = 0, y = 0;
		int i;
		bool flag = true;
		while (k--)
		{
			cin >> i;
			if (i > y) y = i;
			else if (i > x) x = i;
			else flag = false;
		}
		if (flag) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n, i, j;
	int ball[10], blast = 0, clast = 0, min = 11, m = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < 10; j++)
		{
			scanf("%d" , &ball[j]);
		}
		blast = ball[0];
		for (j = 1; j < 10; j++)
		{
			if (blast < ball[j])
				blast = ball[j];
			else if (clast < ball[j])
				clast = ball[j];
			else
			{
				m = 1;
				break;
			}
		}
		if (m == 1)
		{
			printf("NO\n");
			m = 0;
		}
		else
		{
			printf("YES\n");
		}

	}
	return 0;
}

C++: #include <iostream>
#include <vector>

using namespace std;

typedef vector<int> VI;

bool dfs(const VI &balls, int idx, int l, int r) {
  if (idx >= 10) return true;
  int n = balls[idx];
  if (n > l && dfs(balls, idx+1, n, r)) return true;
  if (n > r && dfs(balls, idx+1, l, n)) return true;
  return false;
}

void solve() {
  VI balls;
  for (int i = 0; i < 10; i++) {
    int n;
    cin >> n;
    balls.push_back(n);
  }
  if (dfs(balls, 0, 0, 0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    solve();
  }

  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#pragma region defins
#define ll long long
#define loop(i,n) for (int i = 0; i < n; i++)
#define loops(i,f,n) for (int i = (f); i < n; i++)
#define INF 100000000000000
#define sort(a) sort(a.begin(),a.end())
#define rsort(a) sort(a.rbegin(),a.rend())
using namespace std;
#pragma endregion
vector<int> balls(10);
bool dfs(int now, int btop, int ctop)
{
	if (now == 9)return true;
	if (balls[now] > btop)dfs(now + 1, balls[now], ctop);
	else if (balls[now] > ctop)dfs(now + 1, btop, balls[now]);
	else return false;
}

int main()
{
	int n; cin >> n;
	loop(i, n)
	{
		loop(i, 10)cin >> balls[i];
		cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
	}
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

const int MAX_N = 10;
const int n = MAX_N;
int t;
int a, b, c;

int main()
{
  cin >> t;

  while(t--){
    bool ok = true;
    cin >> c;
    b = 0;
    rep(i, n){
      cin >> a;
      if(b > c) swap(b, c);
      if(a > c){ c = a;  continue; }
      if(a > b){ b = a;  continue; }
      ok = false;
      break;
    }
    puts(ok ? "YES" : "NO");
  }

  return 0;
}

C++: #include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>


using namespace std;

#define FOR(x) for(int i = 0; i < x; i++)

stack<short> x, y;
short a[10], n, j, i;

bool solve(short c, bool judge){
	if(c == 10) return true;
	if(x.top() < a[c]){
		x.push(a[c]);
		if(solve(c + 1, true)) return true;
	}
	if(y.top() < a[c]){
		y.push(a[c]);
		if(solve(c + 1, false)) return true;
	}
	if(judge) x.pop();
	else y.pop();
	return false;
}

int main(){
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		x.push(0);
		y.push(0);
		for(j = 0; j < 10; j++)
			scanf("%d", &a[j]);
		if(solve(0, true)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}