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>
#include<vector>
#include<deque>
#define INF int(1e9)
using namespace std;
int read()
{
    int f=1,x=0;
    char c=getchar();
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
    while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
    return f*x;
}
bool flag;
int ball[11];
void DFS(int left,int right,int now)
{
	if(now>10)
	{
		flag=1;	
		return ;
	}
	if(ball[now]>left&&ball[now]>right) 
		return ;	
	if(ball[now]<left)
		DFS(ball[now],right,now+1);
	else
		DFS(left,ball[now],now+1);
	return ;
}
int main()
{
	int t=read();
	while(t!=0)
	{
		t--;
		flag=0;
		for(int i=10;i>=1;i--)
			ball[i]=read();
		DFS(INF,INF,1);
		if(flag==1)
			printf("YES\n");
		else
			printf("NO\n");
	}
    return 0;
}

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

int B[12], C[12], num[12], b, c;

bool dfs(int b, int c, int i){
    if(i == 10) return true;
    B[b+1] = num[i];
    C[c+1] = num[i];
    if(B[b]<num[i] && dfs(b+1, c, i+1)){
        return true;
    }
    if(C[c]<num[i] && dfs(b, c+1, i+1)){
        return true;
    }
    return false;
}

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

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

using namespace std;

typedef deque <int> Deq;

bool flag;
int ball[10], a;

void dfs(Deq B, Deq C, int deep)
{
	if (flag) return;
	if (deep == 10){
		// cout << "B : " << B.size() << " / ";
		// for (int i = 0; i < B.size(); i++){
		// 	cout << B[i] << " ";
		// }
		// cout << endl << "C : " << C.size() << " / ";
		// for (int i = 0; i < C.size(); i++){
		// 	cout << C[i] << " ";
		// }
		// cout << endl;
		bool bf = true, cf = true;
		for (int i = 0; i+1 < B.size(); i++){
			if (B[i] > B[i+1]) bf = false;
		}
		for (int i = 0; i+1 < C.size(); i++){
			if (C[i] > C[i+1]) cf = false;
		}
		flag |= (bf && cf);
		return;
	}

	B.push_back(ball[deep]);
	dfs(B, C, deep + 1);
	B.pop_back();

	C.push_back(ball[deep]);
	dfs(B, C, deep + 1);
	C.pop_back();
	return;
}

int main(void)
{
	int n;
	cin >> n;
	while (n--){
		for (int i = 0; i < 10; i++){
			cin >> ball[i];
		}

		flag = false;
		Deq B, C;
		dfs(B, C, 0);

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

	return 0;
}

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

int main() {
	int n, balls[10]; cin >> n;
    while(n--){
        for(int i = 0; i < 10; i++){
            cin >> balls[i];
        }
        
        bool sortable = false;
        stack<tuple<int, int, int> > states;
        
        states.push(make_tuple(0,0,0));
        while(!states.empty()){
        	tuple<int, int, int> now = states.top();
        	states.pop();
        	
        	int idx = get<0>(now);
        	if(idx < 10){
        		if(get<1>(now) < balls[idx]){
        			if(idx == 9){
        				sortable = true; break;
        			}
        			states.push(make_tuple(idx+1,balls[idx],get<2>(now)));
        		}
        		if(get<2>(now) < balls[idx]){
        			if(idx == 9){
        				sortable = true; break;
        			}
        			states.push(make_tuple(idx+1,get<1>(now),balls[idx]));
        		}
        	}        	
        }
         
        if(sortable) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n;
    cin >> n;
    while(n-- > 0){
        int b = 0, c = 0;
        bool ok = true;
        for(int i=0; i<10; ++i){
            int a;
            cin >> a;
            if(a > b && a > c){
                if(b > c)
                    b = a;
                else
                    c = a;
            }else if(a > b)
                b = a;
            else if(a > c)
                c = a;
            else
                ok = false;
        }
        if(ok)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}

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

int main(){
	int N,ball,B=0,C=0;
	cin>>N;
	for(int i=0;i<N;i++){
		for(int j=0;j<10;j++){
			cin>>ball;
			if(ball<B && ball<C){cout<<"NO"<<endl;goto x;}
			if(B<ball && C<B){B=ball;}
			else if(C<ball && B<C){C=ball;}
			else if(C<B){C=ball;}
			else 		{B=ball;}
		}	
		cout<<"YES"<<endl;
x:		B=C=0;
	}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
#define INF 40
using namespace std;

int ball[12];
int flag ;
stack<int> A, B;


void dfs(int s)
{
	if (s >= 10)
	{
		flag = 1;
		return;
	}
	else if (ball[s] < A.top() && ball[s] < B.top())
	{
		return;
	}
	else {
		if (ball[s] > A.top())
		{
			A.pop();
			A.push(ball[s]);
			dfs(ball[s + 1]);
		}
		if (ball[s] > B.top())
		{
			B.pop();
			B.push(ball[s]);
			dfs(ball[s + 1]);
		}
	}
}


int main()
{
	int n;
	A.push(0);
	B.push(0);
	while (~scanf("%d",&n))
	{
		while (n--)
		{
			flag = 0;
			memset(ball, 0, sizeof(ball));
			for (int i = 0;i < 10;i++)
			{
				scanf("%d", &ball[i]);
			}
			dfs(0);
			if (flag) printf("YES\n");
			else printf("NO\n");
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string.h>

using namespace std;

int N;
int balls[10];
bool dfs(int n, int a, int b){
if(n==10)return true;
if(balls[n]>a) return dfs(n+1,balls[n],b);
if(balls[n]>b) return dfs(n+1,a,balls[n]);
return false;
}
int main(){
cin>>N;
for(int i=0;i<N;i++){
for(int j=0;j<10;j++){
cin>>balls[j];
}
if(dfs(0,0,0))cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}