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 <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int n;
int array[10];

void solve() {
    int B=0;
    int C=0;
    rep(i,10) cin>>array[i];
    B = array[0];
    C = array[1];

    rep(i,10) {
        if(i==0 || i==1) continue;
        int t1 = array[i] - B;
        int t2 = array[i] - C;
        // cout<<t1<<","<<t2<<endl;
        if(t1<=0 && t2<=0) {
            cout<<"NO"<<endl;
            return;
        }
        else if(t1 > t2) {
            C = array[i];
        }
        else {
            B = array[i];
        }
    }

    cout<<"YES"<<endl;

}

int main() {
    cin>>n;
    rep(i,n) solve();
    return 0;
}

C++: #include <bits/stdc++.h>
 
using namespace std;
 
int n, ball[10];
 
bool solve(int idx, int l, int r) {
 
    if(idx >= 10) return true;
 
    bool ret = false;
    if(ball[idx] > l) ret = ret || solve(idx + 1, ball[idx], r);
    if(ball[idx] > r) ret = ret || solve(idx + 1, l, ball[idx]);
    return ret;
 
}
 
int main() {
 
    cin >> n;
 
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < 10; ++j) {
            cin >> ball[j];
        }
        cout << solve(0, 0, 0) ? "YES" : "NO" << endl;
    }
 
}

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) {
                b = a;
            } else if (a > c) {
                c = a;
            } else {
                ok = false;
                break;
            }
        }
        if (ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>

using namespace std;

int main() {

	stack<int> B, C;
	int n,ball;

	cin >> n;

	for(int j=0;j<n;j++){
		for (int i = 0; i < 10; i++) {
			cin >> ball;

			if (i == 0)
				B.push(ball);

			else if (B.top() > ball)

				if (C.empty())
					C.push(ball);

				else if (C.top() < ball)
					C.push(ball);

				else {
					cout << "NO" << endl;
					break;
				}

			else {
				if (B.top() < ball)
					B.push(ball);
				else {
					cout << "NO" << endl;
					break;
				}
			}

			if (i == 9)
				cout << "YES" << endl;
		}
		while (1) {
			B.pop();
			if (B.empty())
				break;
		}
		while (1) {
			C.pop();
			if (C.empty())
				break;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
int main(){
	int N, i;
	int num[11];
	cin >> N;
	while( N-- > 0 ){
		for( i = 0; i < 10; i++ ){
			cin >> num[i];
		}
		stack<int> st1;
		stack<int> st2;
		for( i = 0; i < 10; i++ ){
			if( st1.empty() ){
				st1.push(num[i]);
				continue;
			}else if( st2.empty() ){
				if( st1.top() < num[i] ){
					st1.push(num[i]);
					continue;
				}else{
					st2.push(num[i]);
					continue;
				}
			}
			if( st1.top() > num[i] ){
				if( st2.top() > num[i] ){
					cout << "NO" << endl;
					break;
				}else{
					st2.push(num[i]);
				}
			}else{
				if( st2.top() < num[i] ){
					if( st1.top() > st2.top() ){
						st1.push(num[i]);
					}else{
						st2.push(num[i]);
					}
				}
			}
		}
		if( i == 10 ) cout << "YES" << endl;
	}
}

C++: #include<cstdio>

using namespace std;


//引数はそれぞれ、入力配列のカウント変数、a[]のカウント変数,b[]のカウント変数,答え配列,筒を意味するaとb配列,成功判定flg変数
bool tansaku(int count,int n1,int n2,int ans[],int a[],int b[],bool flg)
{
	//カウントが１０になったときは成功したとき
	if (count == 10)
	{
		return true;
	}
	//既にflgがtrueならさっさと返す
	if (flg == false)
	{
		//最初はn1は１である
		if (a[n1] < ans[count])		//１つ前の要素と比べている
		{
			//a[n1]にans[count]を格納
			//最初に足しておくと動作が正しくなる
			n1++;					
			//答えを格納
			a[n1] = ans[count];
			//入力された配列に使うカウント変数
			count++;
			//再帰関数
			bool hozon = tansaku(count,n1,n2,ans,a,b,flg);
			//trueだった場合falseで上書きしないように調整
			if (hozon == true)
			{
				flg = true;
			}
		}
		//ひとつ前の要素と比べている
		if (b[n2] < ans[count])
		{
			//先に足す
			n2++;
			//b[n2](最初はn2 = 1)に小さい順に入れていく
			b[n2] = ans[count];
			//関数の前でインクリメント
			count++;
			//再帰関数
			bool hozon = tansaku(count,n1,n2,ans,a,b,flg);
			//trueだった場合上書きしないようにする
			if (hozon == true)
			{
				flg = true;
			}
		}
	}

	return flg;
}


int main(void)
{
	//何回回すか
	int n = 0;
	//10個のボール
	int a[10] = {0};
	//関数で送るためのいらない変数
	int damy[20] = {0};
	bool ans_flg[100] = {false};

	scanf("%d",&n);
	//n回文の入力
	for (int i = 0;i < n;i++)
	{
		scanf("%d %d %d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);
		if (tansaku(0,0,0,a,damy,damy,false) == true)
		{
			ans_flg[i] = true;
		}
	}

	for (int i = 0;i < n;i++)
	{
		if (ans_flg[i] == true)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}

	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>
#include <utility>
#include <list>
#include <cmath>
#include <unordered_map>

using namespace std;

typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;

const int INF = 1 << 29;
const LL MOD = 100000;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(), (c).end()

struct edge{ int to, cost; edge(int t, int c) :to(t), cost(c){} };

int main()
{
	//while (cin >> n)
	stringstream ss;
	//ss << "result" << i + 1 << ".txt";
	//FILE* fp_out = freopen(ss.str().c_str(), "w", stdout);

	int n;
	while (cin >> n)
	{
		rep(k, n)
		{
			vector<int> balls(10);
			rep(i, 10) cin >> balls[i];
			function<bool(int, int, int)> dfs = [&](int left, int right, int idx)
			{
				if (idx == 10) return true;
				int x = balls[idx];
				return (left < x && dfs(x, right, idx + 1)) ||
					(right < x && dfs(left, x, idx + 1));
			};

			cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
		}
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int ball,bal,n,a,flg;
  cin>>n;
  for(int i=0;i<n;i++){
    flg=0;
    ball=0;
    bal=0;
    for(int k=0;k<10;k++){
      cin>>a;
      if(ball<a){
	ball=a;
      }else if(bal<a){
	bal=a;
      }else{
	flg=1;
      }
    }
    if(flg==0){
      cout<<"YES"<<endl;
    }if(flg==1){
      cout<<"NO"<<endl;
    }
  }
  return 0;
}