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<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1009;
int a[maxn];
int b[maxn];
int c[maxn];
int ln,lm,flag;
int t;
bool erjinzhi()
{
    for(int i=0;i<1024;i++)
    {
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        ln=0;
        lm=0;
        flag=1;
        for(int j=i,cnt=0;cnt<10;cnt++,j>>=1)
        {
            if(j&1)
            b[ln++]=a[cnt];
            else
            c[lm++]=a[cnt];
        }
        for(int k=1;k<ln;k++)
        {
            if(b[k-1]>b[k])
            {
                flag=0;
                break;
            }
        }
        if(flag)
        for(int k=1;k<lm;k++)
        {
            if(c[k-1]>c[k])
            {
                flag=0;
                break;
            }
        }
        if(flag)return true;
    }
    return false;
}
int main()
{
    scanf("%d",&t);
    while(t--)
    {

     for(int i=0;i<10;i++)
     scanf("%d",&a[i]);
     bool fl=erjinzhi();
     if(fl)
     printf("YES\n");
     else
     printf("NO\n");
    }
    return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int n;
	while (n--){
	bool yes=true;
		stack<int> s1;
		stack<int> s2;
		s1.push(0);
		s2.push(0);
		REP(i, 10){
			int a;
			cin >> a;
			if (s1.top() <= s2.top()){
				if (s1.top() < a)
					s1.push(a);
					continue;
			}
			if (s2.top() < a){
					s1.push(a);
					continue;
			}
			yes=false;

		}
		if (yes)
			cout << "YES"<<endl;
			else
				cout << "NO" << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <algorithm>
#define HEIGHT 10

using namespace std;

int a[HEIGHT];
/*
void solve(){
	bool f=true;
	int right,left;
	right = left = 0;
	for(int i=0;i<HEIGHT;i++){
		if(right<a[i] && left<a[i]){
			if(right<left){
				left = a[i];
			} else {
				right = a[i];
			}
		} else if(right<a[i]){
			right = a[i];
		} else if(left<a[i]){
			left = a[i];
		} else {
			f = false;
			break;
		}
	}
	if(f) printf("YES");
	else printf("NO");
}*/

bool back(int right, int left, int n){
	if(n == 10) return true;
	bool result = false;
	if(right<a[n]) result = result || back(a[n],left,n+1);
	if(left<a[n]) result = result || back(right,a[n],n+1);
	return result;
}

void solve(){
	if(back(0,0,0)) printf("YES");
	else printf("NO");
}
			
int main(){
	
	int lp;
	scanf("%d",&lp);
	
	for(int i=0;i<lp;i++){
		for(int j=0;j<HEIGHT;j++){
			scanf(" %d",&a[j]);
		}
		solve();	
	}
	return 0;
}

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

int Balls[10];

bool fork(int balls[], int i, int b, int c) {
    if (i == 10) return true;
    if (b > balls[i] && c > balls[i]) return false;
    if (b < balls[i]) fork(balls, i + 1, balls[i], c);
    if (c < balls[i]) fork(balls, i + 1, b, balls[i]);
}


int main() {
    int n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> Balls[j];
        if(fork(Balls, 0, 0, 0)) {cout << "YES" << endl;}
        else(){cout << "NO" << endl;}
        }

    }
        return 0;
}

C++: 
#include <iostream>

using namespace std;

int main() {
	const bool debug = false;
	int N;
	cin >> N;

	int* balls = new int[N * 10];
	for (int i = 0; i < N * 10; i++) {
		cin >> balls[i];
	}

	for (int j = 0; j < N; j++) {
		bool isYes = true;
		int hole[2] = { 0,0 };
		for (int i = 0; i < 10; i++) {
			if (hole[0] < balls[i+j*10]) {
				hole[0] = balls[i + j * 10];
				if (debug)
					cout << "" << balls[i + j * 10] << "\n";
			} else if (hole[1] < balls[i + j * 10]) {
				hole[1] = balls[i + j * 10];
				if (debug)
					cout << "  " << balls[i + j * 10] << "\n";

			} else {
				if (debug)
					cout << "falure\n";
				isYes = false;
				break;
				
			}
		}
		cout << (isYes ? "YES" : "NO") << "\n";
	}
}

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

int main()
{
int n;
scanf("%d", &n);
for(int testcase = 0; testcase < n; ++testcase) {
bool yes = false;
int s = 10;
vector<int> x;
x.resize(s);
for(int i = 0; i < s; ++i)
scanf("%d", &x[i]);
for(int bit = 0; bit < (1 << s); ++bit) {
int count = 0;
for(int i = 0; i < s; ++i)
count += (bit >> i) & 1;
if(count != s / 2)
continue;
bool valid = true;
for(int lr = 0; lr < 2; ++lr) {
int prev = -100;
for(int i = 0; i < s; ++i) {
if((bit >> i) == lr) {
if(prev >= x[i]) {
valid = false;
break;
}
prev = x[i];
}
}
}
if(valid) {
yes = true;
break;
}
}
printf("%s\n", yes ? "YES" : "NO");
}
return 0;
}

C++: #include <iostream>
using namespace std;
int a[20];
int b,c;
int main(){
    int ti;
    cin>>ti;
    while(ti--){
        b=c=0;
        bool flag=1;
        for(int i=1;i<=10;i++){
            cin>>a[i];
        }
        for(int i=1;i<=10;i++){
            if(b>a[i]&&c>a[i]){
                cout<<"NO"<<endl;
                flag=0;
                break;
            }
            if(a[i]>b){
                b=a[i];
                continue;
            }
            if(a[i]>c){
                c=a[i];
                continue;
            }
        }
        if(flag){
            cout<<"YES"<<endl;
        }
    }
}