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<vector>

int main(){
    int x;
    std::cin>>x;
    for(int i=0;i<x;++i){
        std::vector<int> vec(10);
        for(int l=0;l<10;++l){
            std::cin>>vec[l];
        }
        std::vector<std::vector<int> > vec2(2);
        vec2[0].push_back(vec[0]);
        for(int l=1;l<vec.size();++l){
            if(l==1){
                if(vec2[0][0]<vec[1]){
                    vec2[0].push_back(vec[1]);
                }else vec2[1].push_back(vec[1]);
            }else{
                if(vec[l]>vec2[0][vec2[0].size()-1]){
                    vec2[0].push_back(vec[l]);
                }else{
                    if(vec2[1].size()==0)vec2[1].push_back(vec[l]);
                    else if(vec2[1][vec2[1].size()-1]<vec[l]){
                        vec2[1].push_back(vec[0]);
                    }else{
                        std::cout<<"NO"<<std::endl;
                        goto cont;
                    }
                }
            }
        }
        std::cout<<"YES"<<std::endl;
    cont:;
    }
    return 0;
}

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

int n;
int a[10];


bool dfs(int i, int r, int l) {
    if (i == 9) return a[i] > r || a[i] > l;
    if (dfs(i+1, max(a[i], r), l)) return true;
    if (dfs(i+1, r, max(a[i], l))) return true;
    return false;
}

void solve() {
    if (dfs(0,a[0],a[0])) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> a[j];
        }
        solve();
    }
}

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


int ip[13];
int c[13];


int main(){
	
	int ds = 0;
	scanf(" %d",&ds);
	
	for(int i=0;i<ds;i++){
		for(int j=1;j<13;j++){
			c[j] = 100;
		}
		c[0] = -1;
		
		for(int j=0;j<10;j++){
			scanf(" %d",&ip[j]);
		}
		
		for(int j=9;j>-1;j--){
			
			for(int k=0;k<11;k++){
				if(c[k]<ip[j]){
					c[k+1] = min(c[k+1],ip[j]);
				}
			}
		}
		int ans = 1;
		while(c[ans]< 50) ans++;
		if(ans<4) printf("YES\n");
		else printf("NO\n");
	
	}
	
	
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[20];
int b[20],c[20];
int n;
bool flag;
void dfs(int i,int j,int k)
{
    if(i == 10)
    {
        flag = true;
        return ;
    }
    if(flag == true)
        return ;
    if(a[i] > c[j - 1]){
       /* printf("游街、?\n");
        printf("a[i] = %d\n",a[i]);
        printf("c[j - 1] = %d\n",c[j - 1]);*/
        c[j] = a[i];
       /* printf("c[j] = %d\n",c[j]);
        printf("j = %d\n",j);
        printf("i = %d\n",i);*/
        dfs(i + 1,j + 1,k);
        memset(c,0,sizeof(c));
    }
    printf("\n\n\n\n");
    if(a[i] > b[k - 1]){
        //printf("a[i] = %d\n",a[i]);
       // printf("b[k - 1] = %d\n",b[k - 1]);
        b[k] = a[i];
       /* printf("b[k] = %d\n",b[k]);
        printf("k = %d\n",k);
        printf("i = %d\n",i);*/
        dfs(i + 1,j,k + 1);
    }
   // printf("OKOKOK\n\n\n\n");
    return ;
}
int main()
{
    scanf("%d",&n);
    while(n --)
    {
        for(int i = 0; i < 10; i++)
            scanf("%d",&a[i]);
        flag = false;
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));

        dfs(0 , 1, 1);
        //printf("b[1] = %d\n",b[1]);

        if(flag == true)
            printf("YES\n");
        else
            printf("NO\n");
       /* for(int i = 0; i <= 10; i++)
            printf("%d ",c[i]);
        printf("\n");
        for(int i = 0; i <= 10; i++)
            printf("%d ",b[i]);
        printf("b[1] = %d\n",b[1]);*/
    }
    return 0;
}
/*
100
1 2 3 4 8 5 6 7 9 10
*/

C++: #include <cstdio>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#define min(a,b)    (((a) < (b)) ? (a) : (b))
#define max(a,b)    (((a) > (b)) ? (a) : (b))
#define abs(x)    ((x) < 0 ? -(x) : (x))
#define INF 0x3f3f3f3f
#define delta 0.85
#define eps 1e-3
#define PI 3.14159265358979323846
using namespace std;
int A[10], B[10], C[10];

bool dfs(int p, int p1, int p2){
	if(p == 10) return 1;
	if(p1 == 0 || (p1 > 0 && A[p] > B[p1 - 1])){
		B[p1] = A[p];
		if(dfs(p + 1, p1 + 1, p2)) return 1;
	}
	if(p2 == 0 || (p2 > 0 && A[p] > C[p2 - 1])){
		C[p2] = A[p];
		if(dfs(p + 1, p1, p2 + 1)) return 1;
	}
	return 0;
}

int main(){
	int t;
	scanf("%d", &t);
	while(t--){
		for(int i = 0; i < 10; i++) scanf("%d", A + i);
		printf(dfs(0, 0, 0) ? "YES\n" : "NO\n");
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
#include <functional>
const int INF =1e5;
const int MOD = 1e9 + 7;
using namespace std;
typedef pair<int,int> P;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define pb push_back
vector<int> a;
vector<int> b;
int v[10];
bool dfs(int);

int main(){
    int n;
    cin>>n;
    while(n>0){
        rep(i,10){
            cin>>v[i];
        }
        if(dfs(0)){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
        n--;
    }
    return 0;
}

bool dfs(int i){
    if(i==10) return true;
    vector<int>::iterator itr;
    if(a.size()>0){
        itr= a.end();
        if(v[i]>*itr){
            a.pb(v[i]);
            if(dfs(i+1)) return true;
            a.pop_back();
        }
    }else{
        a.pb(v[i]);
        if(dfs(i+1)) return true;
        a.pop_back();
    }
    if(b.size()>0){
        itr= b.end();
        if(v[i]>*itr){
            b.pb(v[i]);
            if(dfs(i+1)) return true;
            b.pop_back();
        }
    }else{
        b.pb(v[i]);
        if(dfs(i+1)) return true;
        b.pop_back();
    }
    if(i>0){
        vector<int>::iterator itr2;
        itr= a.end();
        itr2= b.end();
        if(v[i]<=*itr && v[i]<=*itr2)return false;
    }
    return false;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	while(n--){
		int B=-1,C=-1;
		bool ok=true;
		for(int i=0;i<10;i++){
			int m;
			cin>>m;
			if(B<m){
				if(B<C && C<m)C=m;
				else B=m;
			}
			else if(C<m){
				C=m;
			}
			else ok=false;
		}
		cout<<(ok?"YES":"NO")<<endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
   // Your code here!
   int n,i,j,m,q,r;
   int a[10];
   int b[10];
   int c[10];
   cin >> n;
   for(m=0;m<n;m++){
       for(i=0;i<10;i++){
            cin >> a[i];
        }
        for(i=0;i<10;i++){
            b[i]=0; 
           }
        for(i=0;i<10;i++){
            c[i]=0; 
        }
   
        q=0;
        r=0;
        for(j=0;j<10;j++){
            if(q==0 || a[j]>b[q-1]){
                b[q]=a[j];
                q=q+1;
            }else if(r==0 || a[j]>c[r-1]){
              c[r]=a[j];  
              r=r+1;
            }else{
                cout << "NO\n";
                break;
            }
            
          }
          if(j==10){
          cout << "YES\n";
          }
        for(i=0;i<10;i++){
            a[i]=0; 
   }
   
   }
   


}