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 <stack>
#include <vector>

using namespace std;

int N;
int A_bottle[10];

stack<int> B_bottle,C_bottle;

bool dfs(int i){
	//A????????????i???????????°?????????????????????
	if (i==10){
		//?????????????????????????????????????????????
		return true;
	}

	if (B_bottle.empty() || B_bottle.top()<A_bottle[i]){
		//B????????????????????????
		B_bottle.push(A_bottle[i]);
		if (dfs(i+1)) return true;
		B_bottle.pop();
	}
	if (C_bottle.empty() || C_bottle.top()<A_bottle[i]){
		//C????????????????????????
		C_bottle.push(A_bottle[i]);
		if (dfs(i+1)) return true;
		C_bottle.pop();
	}
	return false;
}

int main(){
	vector<bool> out;
	cin>>N;
	for (int i=0;i<N;i++){
		for (int j=0;j<10;j++){
			cin>>A_bottle[j];
		}
		out.push_back(dfs(0));
	}
	for (vector<bool>::iterator ite=out.begin();ite!=out.end();ite++){
		cout<<(*ite ? "YES" : "NO")<<endl;
	}
	return 0;
}

C++: 

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>

using namespace std;
typedef long long ll;
int mod(ll a){
    int c=a%1000000007;
    if(c>=0)return c;
    else return c+1000000007;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/

/////////////////////////////////


int a[10];
stack<int>b,c;
bool flag=false;
void dfs(int k){
    if(k==10){
        flag=true;
        return;
    }
    if(b.top()<a[k]){
        b.push(a[k]);
        dfs(k+1);
        b.pop();
    }
    if(c.top()<a[k]){
        c.push(a[k]);
        dfs(k+1);
        c.pop();
    }
    return;
}


int main(){
    int n;cin>>n;
    while(n--){
        flag=false;
        for(int i=0;i<=9;i++)scanf("%d",&a[i]);
        b.push(a[0]),c.push(0);
        dfs(1);
        if(flag==true)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

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

int main() {
	int n, x;
	cin >> n;
	for (int lop = 0, a = 0, b = 0; lop < n; lop++) {
		bool f = true;
		for (int i = 0; i < 10; i++) {
			cin >> x;
			if (f) {
				if (a < x && b < x) {
					if (a < b) {
						b = x;
						continue;
					}
					a = x;
					continue;
				}
				if (a < x) {
					a = x;
					continue;
				}
				if (b < x) {
					b = x;
					continue;
				}
				f = false;
			}
		}
		cout << (f ? "YES" : "NO") << endl;
	}
	return 0;
}

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

#define MAX 10	// ÊÌ

int main()
{
	stack<int> B, C;
	int A;
	int n;
	int i;
	int flag;

	cin>>n;
	for (i = 0; i < n; i++) {
		while(B.size()) B.pop();
		while(C.size()) C.pop();
		flag = 1;
		while (B.size()+C.size() < MAX) {
			cin>>A;

			if (B.size()==0) {
				B.push(A);
				continue;
			}
			else if (C.size()==0) {
				C.push(A);
				continue;
			}

			if (B.top() >= C.top()) {
				if (B.top() < A) {
					B.push(A);
				} else if (C.top() < A) {
					C.push(A);
				} else {
					cout<<"NO"<<endl;
					flag = 0;
					break;
				}
			} else {
				if (C.top() < A) {
					C.push(A);
				} else if (B.top() < A) {
					B.push(A);
				} else {
					cout<<"NO"<<endl;
					flag = 0;
					break;
				}
			}
		}
		if (flag) cout<<"YES"<<endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

vector<int> a;
stack<int> b, c;

bool dfs(int i)
{
	if (i == 10) return true;

	bool res1 = false, res2 = false;

    if (b.empty() || b.top() < a[i]) {
        b.push(a[i]);
        res1 = dfs(i + 1);
        b.pop();
    }

    if (c.empty() || c.top() < a[i]) {
        c.push(a[i]);
        res2 = dfs(i + 1);
        c.pop();
    }

	return res1 || res2;
}

int main()
{
	int n; cin >> n;

	while (n--) {
		a.clear();
		while (b.size()) b.pop();
		while (c.size()) c.pop();

        for (int i = 0; i < 10; ++i) { int v; cin >> v; a.push_back(v); }

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

C++: #include <iostream>

using namespace std;

int main(void){

  int a,b,c,out;
  int n;
  cin >> n;
  while(n--){

    a = b = c = out = 0;

    for( int l = 10 ; l > 0 ; l-- ){
      cin >> a;
      if( b < a ){
	b = a;
      }
      else if( c < a ){
	c = a;
      }
      else out = a;
    }
    if( out == 0 )cout << "YES" << endl;
    else cout << "NO" << endl;
  }
 return 0;
}

C++: #include<iostream>
main(){int n,i,A,B,C;for(std::cin>>n;n-->0;puts(i-21?"YES":"NO"))for(i=B=C=0;std::cin>>A,i++<10;)if(B<A)B=A;else C<A?C=A:i=20;}

C++: #include<iostream>
using namespace std;
int T,num[20],flag,numa[20],numb[20];

void dfs(int t,int ta,int tb)
{
    if(flag)
        return ;
    if(t>=10)
    {
        flag=1;
        return ;
    }
    if(num[t]>numa[ta])
    {
        numa[ta+1]=num[t];
        dfs(t+1,ta+1,tb);
        if(flag)
            return ;
    }
    if(num[t]>numb[tb])
    {
        numb[tb+1]=num[t];
        dfs(t+1,ta,tb+1);
    }
}

int main()
{
    cin>>T;
    while(T--)
    {
        flag=0;
        numa[0]=0,numb[0]=0;
        for(int i=0;i<10;++i)
            cin>>num[i];
        dfs(0,0,0);
        if(flag)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}

C++: #include <iostream>
using namespace std;
int N,a[10];
bool ans;
bool test(int i){
	int b=0,c=0;
	for(int j=0;j<10;j++){
		if(i>>j&1){
			if(b>a[j])return false;
			else b=a[j];
		}else{
			if(c>a[j])return false;
			else c=a[j];
		}
	}
	return true;
}
int main()
{
    cin>>N;
	while(N--){
		ans=false;
		for(int i=0;i<10;i++)cin>>a[i];
		for(int i=0;i<1<<10;i++){
			if(test(i)){
				ans=true;
				break;
			}
		}
		if(ans)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
    return 0;
}

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

int balls[10];

bool dfs(int left, int right, int currentID){
	if(currentID > 9) return true;
	
	bool ok = false;
	if (left < balls[currentID]){
		ok = dfs(balls[currentID], right, currentID+1);
	}
	if (right < balls[currentID]){
		ok = dfs(left, balls[currentID], currentID+1);
	}
	return ok;
}

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

C++: #include <iostream>
using namespace std;
int N;
int V[10];

int dfs(int a, int b, int d) {
    if(d==10) return 1;
    int atry = 0, btry = 0;
    if(a < V[d]) atry = dfs(V[d], b, d+1);
    if(b < V[d]) btry = dfs(a, V[d], d+1);
    if(atry == 0 && btry == 0) return 0;
}

int main() {
    cin >> N;
    for(int i=0; i<N; i++) {
        for(int j=0; j<10; j++) cin >> V[j];
        int res = dfs(0,0,0);
        if(res) cout << "YES" << endl;
        else cout << "NO" << endl; 
    }
}