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 <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;

int n, k;
stack<int> sb, sc;
bool f = 1;

int main(){
	cin >> n;
	REP(i, n){
		REP(j, 10){
			cin >> k;
			if (sb.empty()){
				sb.push(k);
			}
			else if (sc.empty()){
				sc.push(k);
				if (sb.top() < sc.top()){
					k = sc.top();
					sc.push(sb.top());
					sb.push(k);
				}
			}
			else{
				if (sb.top() < k){
					sb.push(k);
				}
				else if (sc.top() < k){
					sc.push(k);
				}
				else{
					f = 0;
				}
			}
		}
		if (f){
			cout << "YES\n";
		}
		else{
			cout << "NO\n";
		}
		while (!sb.empty()){
			sb.pop();
		}
		while (!sc.empty()){
			sc.pop();
		}
		f = 1;
	}
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int a[10], b[10], c[10];
int N;
int top1 = -1, top2 = -1;

bool dfs(int i)
{
	if (i == 10)
		return true;
	if (a[i] > b[top1] || top1 == -1)
		b[++top1] = a[i];
	else if (a[i] > c[top2] || top2 == -1)
		c[++top2] = a[i];
	else return false;
	dfs(i + 1);
}

int main()
{
	scanf("%d", &N);
	while (N--)
	{
		for (int i = 0; i < 10; i++)
			scanf("%d", &a[i]);
		if (dfs(0))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
		memset(b, 0, sizeof(b));
		memset(c, 0, sizeof(c));
		top1 = top2 = -1;
	}
	return 0;
}

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


bool vis[15];
int a[15];

bool ok = false;


void dfs(int cnt, int last){
	if(ok){
		return;
	}
	if(cnt > 9)
		return;
	if(cnt <= 9){
		vector<int> ver;
		for (int i = 0; i < 10; i++){
			if(!vis[i]){
				ver.push_back(a[i]);
			}
		}
		bool flag = true;
		for (int i = 1; i < ver.size(); i++){
			if(ver[i] < ver[i - 1]){
				flag = false;
			}
		}
		if(flag){
			ok = true;
		}
		//return;
	}
	
	for (int i = cnt; i < 10; i++){
		if(a[i] > last){
			vis[i] = true;
			dfs(i + 1, a[i]);
			vis[i] = false;
		}
	}
	return;
}
 


int main(){
	int n;
	cin >> n;
	while(n--){
		ok = false;
		memset(a, 0, sizeof(a));
		memset(vis, false, sizeof(vis));
		for (int i = 0; i < 10; i++){
			cin >> a[i];
		}
		
		dfs(0, 0);
		if(ok){
			cout << "YES" << endl;
		}else cout << "NO" << endl; 
		
		
		
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
int arr[15];
int m,n;
vector<int> x;
vector<int> y;
void binary(int p)
{
    int i=0;
    int flag=1;
    while(i<10)
    {
        if(p&flag)
            x.push_back(arr[i]);
        else
            y.push_back(arr[i]);
        flag=flag<<1;
        i++;
    }
}
int panduan()
{
    for(int j=1;j<x.size();j++)
    {
        if(x[j]<x[j-1])
          return 0;
    }
    for(int i=1;i<y.size();i++)
    {
        if(y[i]<y[i-1])
          return 0;
    }
    return 1;
}
int solve()
{
    for(int i=0;i<1024;i++)
    {
        x.clear();
        y.clear();
        binary(i);
        if(panduan())
            return 1;
    }
    return 0;
}
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        for(int i=0;i<10;i++)
            scanf("%d",&arr[i]);
        if(solve())
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
    return 0;
}

C++: #include <iostream>
#include <bitset>
#include <algorithm>
using namespace std;
 
///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{
 
	int n;
	cin >> n;
	while (n--)
	{
		int ball[10];
		
		for (int i = 0; i < 10; ++i)
		{
			cin >> ball[i];
		}
 
		bitset<10> direction;
		int all = 1024;
		while (all-- > 0)
		{
			direction = static_cast<bitset<10> >(all);
			bool perfect = true;
			int left = 0;
			int right = 0;
			for (int i = 0; i < 10; ++i)
			{
				if (direction[i])
				{
					if (ball[i] > left)
					{
						left = ball[i];
					}
					else
					{
						perfect = false;
						break;
					}
				}
				else
				{
					if (ball[i] > right)
					{
						right = ball[i];
					}
					else
					{
						perfect = false;
						break;
					}
				}
			}
			if (perfect)
			{
				break;
			}
		}
	
		if (all >= 0)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
 
	return 0;
}

C++: //Ball

#include<iostream>
#include<stack>
using namespace std;

int main(void){
    int n;
    
    cin >> n;
    
    for(int i = 0; i < n; i++){
        
        int j;
        stack<int> Q1;
        stack<int> Q2;
        Q1.push(0);
        Q2.push(0);
        
        for( j = 0; j < 10; j++){
            int x;
            cin >> x;
            
            if(Q1.top() < x)        Q1.push(x);
            else if(Q2.top() < x)   Q2.push(x);
            else {
                cout << "NO" << endl;
                break;
            }
        }
        if(j == 10) cout << "YES" << 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\n");
	else printf("No\n");
}
			
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 <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#define rep(i, n) for (int i=0; i<n; ++i)
#define FOR(i, a, b) for (int i=a; i<b; ++i)
#define pb(x) push_back(x)
#define ll long long
#define ul unsigned long long
#define dbg(x) cout  << #x << " : " << (x) << endl
#define out(x) cout << (x)
#define outl(x) cout << (x) << endl
#define int(n); int n; cin >> n;
#define long(n); long long n; cin >> n;
#define dbl(f); double f; cin >> f;
#define s(s); string s; cin >> s;
#define into(a, n) for (int i = 0; i < n; ++i) cin >> a[i]
using namespace std;

const int inf =1500000000;

int a[11],b[11],c[11];

bool dfs(int l,char x) {
  if (l>=10) return true;
  if (x=='b') {
    b[l]=a[l];
    rep(i, l) if(b[l]<b[i]) {b[l]=-1; return false;}
  }
  if (x=='c') {
    c[l]=a[l];
    rep(i, l) if(c[l]<c[i]) {c[l]=-1; return false;}
  }
  bool p= dfs(l+1,'b')||dfs(l+1,'c');
  b[l]=-1;c[l]=-1;
  return p;
}

int main () {
  int(n);
  bool flg;
  rep(i, n) {
    flg=false;
    b[0]=-1;c[0]=-1;
    FOR(i, 1, 11) {
      cin>>a[i];
      b[i]=-1; c[i]=-1;
    }
    flg=dfs(1,'b')||dfs(1,'c');
    outl(flg?"YES":"NO");
  }
  return 0;
}