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<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) {
	if (n = 9) {
		return true;
	}

	if (B < ball[n]) {
		return bfs(n + 1);
	}
	if (C < ball[n]) {
		return bfs(n + 1);
	}
	
	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)) {
			CO "YES" E
		}
		else {
			CO "NO" E
		}
	}
	
	return 0;
}

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

C++: #include<cstdio>
/*
2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
3 5 4 6 1 2 7 8 9 10
4 5 6 7 8 9 1 2 3 10
*/
int n;
int a[12];

int  dsf(int x, int num){
    //将所在数字???-1
    a[x] = -1;
    //向后遍?数?，?足条件?将num???当前数字，并且?用本方法。

    int flag2 = 0;

    for(int i = x; i < 10; i++){

        if(a[i] == num + 1){

            num = a[i];
            dsf(i,num);

            flag2 ++;//只要?行??条件，????1
        }
    }
    if(flag2 == 0)//?明数?中元素不符合条件
             return 0;
    if(flag2 > 2)
             return 0;
    return 1;
}
int main(){

    scanf("%d",&n);
    int i=1;
    while(i <= n){
        int flag = 1;

        //存数据
        for(int x = 0; x < 10; x++){
            scanf("%d",&a[x]);
        }

        //?用方法，将?足条件的数字改?-1
        for(int x = 0; x < 10; x++){
            if(a[x] != -1)
                if(dsf(x,a[x]) == 0)                     //只要??数?中有一个元素不符合条件，?跳出，避免将所有数据?入并???-1
                    break;
        }

        //遍?数?的数?是否都?-1
        for(int x = 0; x < 10; x++){

            if(a[x] != -1)
                flag = 0;
        }
        //判断并?出?果
        if(flag == 1) printf("YES\n");
            else printf("NO\n");

        i++;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int A[15];
int L[15];int R[15];
int n;

bool dfs(int i, int j, int k)
{
	
	if(i==10) return true;
	if(A[i] > L[j-1])
	{
		L[j] = A[i];
		if(dfs(++i,++j,k))
			return true;
	}
	if(A[i] > R[k-1])
	{
		R[k] = A[i];
		if(dfs(++i,j,++k))
			return true;	
	}	
	return false;
}
void solve()
{

	if(dfs(0,1,1))
		cout << "YES"<<endl;
	else
		cout <<"NO"<<endl;
}

int main()
{
	
	cin >>n;
	while(n--)
	{
		for(int i =0; i<10; i++)
			cin >> A[i];
		L[0] = R[0] = 0;		
		solve();
	}
}

C++: #include"iostream"
#include"stdio.h"
using namespace std;
int ball[11];
bool flag;
 
void Dfs(int i,int left,int right)
{
    if(flag) return;
    if(i==10) {flag=true;return;}
 
    if(ball[i]>left)
        Dfs(i+1,ball[i],right);
    if(ball[i]>right)
        Dfs(i+1,left,ball[i]);
}
 
int main()
{
    int t;
    while(scanf("%d",&t)==1)
    {
        while(t--){
            flag=false;
            for(int i=0;i<10;i++)
                cin>>ball[i];
            Dfs(0,0,0);
            if(flag)
                cout<<"YES"<<endl;
            else
                cout<<"NO"<<endl;
        }
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
	int N;

	cin >> N;

	for (int i = 0; i < N; i++){
		int  b = 1, c = 1;
		int num[10];
		int B[11] = { 0 }, C[11] = { 0 };
		bool flag = false;
		

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

		for (int i = 0; i < 10; i++){
			if (B[b-1] < num[i]){
				//cout << "B" << B[b-1] << ' '<< num[i]<< endl;
				B[b] = num[i];
				b++;
			}
			else{
				//cout << "C" << C[c - 1] << ' ' << num[i] << endl;
				if (C[c-1] < num[i]){
					C[c] = num[i];
					c++;
				}
				else{
					flag = true;
					break;
				}

			}
		}

		if (flag == false) cout << "YES" << endl;
		if (flag == true) cout << "NO" << endl;
	}
}

C++: #include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int n;
    cin >> n;
    rep(i, n){
        vector<int> b, c;
        b.push_back(-1);
        c.push_back(-1);
        bool flag = true;
        rep(j, 10){
            int a;
            cin >> a;
            if(flag){
                if(b[b.size()-1] < c[c.size()-1]){
                    if(c[c.size()-1] < a){
                        c.push_back(a);
                    }else if(b[b.size()-1] < a){
                        b.push_back(a);
                    }else{
                        flag = false;
                    }
                }else{
                    if(b[b.size()-1] < a){
                        b.push_back(a);
                    }else if(c[c.size()-1] < a){
                        c.push_back(a);
                    }else{
                        flag = false;
                    }
                }
            }
        }
        if(flag){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

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

int num[10];

bool f;
void dfs(int x, int l, int r) {
	if (x == 10) {
		f = true;
	}
	if (num[x] > l) {
		dfs(x + 1, num[x], r);
	}
	if (num[x] > r) {
		dfs(x + 1, l, num[x]);
	}
}

int main() {
	int T;
	cin >> T;
	cin.ignore();
	while (T--) {
		string line;
		getline(cin, line);
		stringstream ss(line);
		for (int i = 0; i < 10; i++) {
			ss >> num[i];
		}
		f = false;
		dfs(0, 0, 0);
		if (f) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}