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++: /*************************************************************************
    > File Name: aoj0033.cpp
    > Author:    WArobot 
    > Blog:      http://www.cnblogs.com/WArobot/ 
    > Created Time: 2017??´06???21??\ ????????? 19??¶29???08?§?
 ************************************************************************/

#include<bits/stdc++.h>
using namespace std;

int n , ball[10] , left_back , last_lb , right_back , last_rb ;
bool ok;

void DFS(int num){
	if( ok || num > 10 )	return;
	if( num == 10 ){
		ok = true;	return;
	}
	if( ball[num] >= left_back ){
		last_lb = left_back;
		left_back = ball[num];
		DFS(num+1);	
		left_back = last_lb;
	}
	if( ball[num] >= right_back ){
		last_rb = right_back;
		right_back = ball[num];
		DFS(num+1);	
		right_back = last_rb;
	}
}
int main(){
	scanf("%d",&n);
	while(n--){
		for(int i = 0 ; i < 10 ; i++){
			scanf("%d",&ball[i]);
		}
		ok = false;	left_back = right_back = last_lb = last_rb = 0;
		DFS(0);
		if(ok)	printf("YES\n");
		else	printf("NO\n");
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;
int a[10];
int main(){
  IOS;
  int n; cin >> n;
  // rep(k,n){
  //   rep(i, 10)scanf("%d", &a[i]);
  //   rep(i,1<<10){
  //     stack<int>s[2];
  //     rep(j, 10){if(s[(i>>j)&1].empty() || a[j] > s[(i>>j)&1].top())s[(i>>j) & 1].push(a[j]);cout<<s[0]<<" "<<s[1]<<endl;}
  //     if(s[0].size()+s[1].size()==10){cout << "YES";break;}
  //     if(i==(1<<10)-1){cout<<"NO"<<endl;break;}
  //   }
  //
  // }
  int b[10];
  rep(j,n){
    int flag=0;
    rep(i,10){
      cin>>b[i];
    }
    stack<int>ta, tb;
    ta.push(b[0]);
    tb.push(0);
    repn(k,9){
      if(b[k]>ta.top()){ta.push(b[k]);}
      else if(b[k]>tb.top()){tb.push(b[k]);}
      else{ flag++;break;}
    }
    if(flag==0)cout<<"YES"<<endl;
    else{cout<<"NO"<<endl;}
  }
  return 0;
}

C++: #include <stdio.h>

int main(void)
{
    int a[10];
    int n;

    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        bool ans = false;
        for (int i = 0; i < 10; i++){
            scanf("%d", a + i);
        }
        for (int i = 0; i < (1 << 10); i++){
            int stack[2];
            int j;
            stack[0] = stack[1] = 0;
            for (j = 0; j < 10; j++){
                int k = ((i >> j) & 1);
                if (stack[k] < a[j]){
                    stack[k] = a[j];
                }
                else {
                    break;
                }
            }
            if (j == 10){
                ans = true;
                break;
            }
        }
        puts(ans ? "YES" : "NO");
    }

    return (0);
}

C++: #include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
int a[13],b[13],c[13],flag;
void dfs(int step,int bn,int cn)
{
    if(step==10){
        flag=1;
        return ;
    }
    if(flag) return ;
    if(a[step]>b[bn-1]){
    	b[bn]=a[step];
    	dfs(step+1,bn+1,cn);
	}
    if(a[step]>c[cn-1]){
    	c[cn]=a[step];
    	dfs(step+1,bn,cn+1);
	}
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        flag=0;
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        for(int i=0;i<10;i++)
            scanf("%d",&a[i]);
        dfs(0,1,1);
        if(flag) printf("YES\n");
        else printf("NO\n");
    }
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

	int n;
	cin >> n;
	bool test = false;
	
	while( n-- ) {
		
		int A[10] = {0};
		int B[10] = {0};
	
		int j = 0, k = 0;
		int a;
		
		for(int i=0;i<10;i++) {
			
			cin >> a;
			
			if( a > A[j] ) {
				
				A[j+1] = a;
				j++;
				
			}
			else {
				if( a > B[k]) {
					
					B[k+1] = a;
					k++;
					
				}
			}
		}
		if ( j + k == 10)
			cout << "YES\n";
		else
			cout << "NO\n"; 
		
	}
	
    return 0;
}

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

using namespace std;

int main() {
	vector<int> left;
	vector<int> right;
	vector<int> all;

	bool flag = true;

	int n;
	cin >> n;
	if (n == 0) return -1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else
							flag = false;
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}

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

	return 0;
}

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

const int max_v = 10;
vector<int> l;
vector<int> r;

void solve(int N) {
	int k = 0, a = 0, flag = 0;
	while (k < N) {
		for (int i = 0; i < 10; i++) {
			cin >> a;
			if (l.empty() && r.empty())
				l.push_back(a);
			else if (a > l.back())
				l.push_back(a);
			else {
				if (r.empty())
					r.push_back(a);
				else if (a > r.back())
					r.push_back(a);
				else {
					cout << "NO" << endl;
					l.clear();
					r.clear();
					flag = 1;
					break;
				}
			}
		}
		if (flag == 1)
			k++;
		else {
			cout << "YES" << endl;
			l.clear();
			r.clear();
			k++;
		}
	}
}
int main() {
	int n;
	cin>>n;
	solve(n);
	return 0;
}

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

int main(){

  int n,z;
  queue < int > a;

  cin >> n;

  for(int i=0;i<n;i++){
    int x = 0,y = 0;

    for(int j=0;j<10;j++){
      cin >> z;
      a.push(z);
    }

    for(int j=0;j<10;j++){

      if(a.front() > x && a.front() > y){
	if(x < y){
	  y = a.front();
	  a.pop();
	}
	else{
	  x = a.front();
	  a.pop();
	}
      }

      else if(a.front() > x){
	x = a.front();
	a.pop();
      }

      else if(a.front() > y){
	y = a.front();
	a.pop();
      }
    }

    if(a.empty() == true) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

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


int a[10];
int n;

bool dfs(int i,int left, int right){
    if(i==10) return true;
    if(a[i]>left){
        return dfs(i+1,a[i],right);
    }
    if(a[i]>right){
        return dfs(i+1,left,a[i]);
    }
    return false;
}

void solve(){
    for(int i=0;i<10;i++){
        cin>>a[i];
    }
    if(dfs(0,0,0)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return;
}

int main(){
    cin>>n;
    for(int i=0;i<2;i++){
        solve();
    }
    return 0;
}