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 <vector>
using namespace std;

int n;
int a[10];
vector<int> l, r;
vector<int> emp;

bool dfs(int p){
	printf("p=%d\n", p);
	/*
	printf("l ");
	for(int i=0; i<l.size(); i++){
		printf("%d ", l[i]);
	}
	printf("\nr ");
	for(int i=0; i<r.size(); i++){
		printf("%d ", r[i]);
	}
	printf("\n");
*/
	if(p == 10) return true;
	l.push_back(a[p]);
	if(l.size() == 1 || l[l.size() - 2] < l[l.size() - 1]){
		return dfs(p+1);
	}else{
		l.pop_back();
		r.push_back(a[p]);
		if(r.size() == 1 || r[r.size() - 2] < r[r.size() - 1]){
			return dfs(p+1);
		}else{
			r.pop_back();
			return false;
		}
	}
}

int main(){
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		l = emp;
		r = emp;
		for(int j=0; j<10; j++){
			scanf("%d", &a[j]);
		}
		if(dfs(0)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

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

int main(){
    stack <int> st1;
    stack <int> st2;
    int n,tmp,a,b;
    bool judge;
    cin >> n;
    while(n--){
        judge = true;
        for(int i=0;i<10;i++){
            cin >> tmp;
            if(i == 0){
                st1.push(tmp);
                continue;
            }
            if(st2.empty()){
                if(tmp < st1.top()) st2.push(tmp);
                else st1.push(tmp);
                continue;
            }
            if(tmp - st1.top() > 0 && tmp - st2.top() > 0){
                a = tmp - st1.top();
                b = tmp - st2.top();
                if(a < b) st1.push(tmp);
                else st2.push(tmp);
            }
            else if(tmp - st1.top() > 0) st1.push(tmp);
            else if(tmp - st2.top() > 0) st2.push(tmp);
            else judge = false;
        }
        if(judge) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

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


int res=0;

bool saiki(int ball[],int ttB,int ttC,int res){
	if(res==10)return true;
	if(ball[res]>ttB){
		return saiki(ball,ball[res],ttC,res+1);
	}
	if(ball[res]>ttC){
		return saiki(ball,ttB,ball[res],res+1);
	}
	return false;
}

int main(void){
	int a,b;
	int ball[11];
	int ttB=0,ttC=0;
	int n;
	scanf("%d",&n);
	for(a=0;a<n;a++){
		for(b=0;b<10;b++){
			ball[b]=0;
		}
		ttB=0;
		ttC=0;
		res=0;
		for(b=0;b<10;b++){
			scanf("%d",&ball[b]);
		}
		if(saiki(ball,ttB,ttC,res)==true)printf("YES\n");else printf("NO\n");
	}
	return 0;
}

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

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>

using namespace std;

int n, a[10];

bool dfs(int depth, int b, int c) {
    if (depth == 10)
        return true;
    bool ret = false;
    if (a[depth] > b) {
        ret = ret || dfs(depth + 1, a[depth], c);
    }
    if (a[depth] > c) {
        ret = ret || dfs(depth + 1, b, a[depth]);
    }
    return ret;
}

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

C++: #include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD
 
int main(){
  int n;
  cin>>n;
  while(n--){
    bool used[10];
    REP(i,10)used[i]=false;
    int left=-1,right=-1;
    bool flag = true;
    REP(i,10){
      int x;
      cin>>x;
      --x;
      if(x<left && x<right){
        flag = false;
        break;
      }else if(x<left && x>right){
        right = x;
        used[x] = true;
      }else if(x>left && x<right){
        left = x;
        used[x] = true;
      }else{
        if(right>left){
          right = x;
          used[x] = true;
        }else{
          left = x;
          used[x] = true;
        }
      }
    }
    if(flag){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
  }
  return 0;
}

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

using namespace std;

int n;
vector<int> vec;
int lcount, rcount, l, r;

bool dfs(int i)
{
	if(i == 10) return true;
	if(lcount < 10 && l < vec[i]){ l = vec[i]; if(dfs(i + 1)) return true; }
	if(rcount < 10 && r < vec[i]){ r= vec[i]; if(dfs(i + 1)) return true; }
	return false;
}

int main()
{
	while (cin >> n && n)
	{
		lcount = 0; rcount = 0; l = 0; r = 0;
		vec.resize(10);
		for (int j = 0; j < n; j++)
		{

			for (int i = 0; i < 10; i++)
			{
				cin >> vec[i];
			}	
			cout << (dfs(0) ? "YES" : "NO") << endl;
		}
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

  int in;
  cin >> in;
  for(int i = 0; i < in; i++){
    int data[2];
    data[0] = data[1] = 0;
    int flg = 0;
    for(int i = 0; i < 10; i++){
      int num;
      cin >> num;
      if(data[0] < data[1]){
	int tmp = data[0];
	data[0] = data[1];
	data[1] = tmp;
      }
      if(num > data[0]) data[0] = num;
      else if(num > data[1]) data[1] = num;
      else flg = 1;
    }
    if(flg) cout << "NO"<< endl;
    else cout << "YES"<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
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<stdio.h>

int main(){

int n[11]={};
int m[11]={},p[11]={};
int N;
bool f=true;

while(1){
scanf("%d",&N);if(N==0)break;

for(int i=0;i<10;i++)
scanf("%d",&n[i]);

for(int i=0;i<10;i++)
if(m[M]<n[i]){M++;m[M]=n[i];}
else if(p[P]<n[i]){P++;p[P]=n[i];}
else f=false;
}

if(f=true)printf("YES\n");
else printf("NO\n");

for(int i=0;i<10;i++)
{p[i]=0;m[i]=0;}

bool f=true;


}
return 0;
}

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

int main(){
	int num;
	cin>>num;
	bool error=false;
	for(int x=0;x<num;x++){
		error=false;
		queue<int> A;
		vector<int> B;
		vector<int> C;
		for(int i=0;i<10;i++){
			int nn;
			cin>>nn;
			A.push(nn);
		}
		int nn=A.size();
		C.push_back(0);
		for(int i=0;i<nn;i++){
			if(i==0){
				B.push_back(A.front());
				A.pop();
				continue;
			} else if(A.front()>B.back()){
				B.push_back(A.front());
				A.pop();
			}else if(A.front()>C.back()){
				C.push_back(A.front());
				A.pop();
			}else{
				error=true;
			}
		}
		if(error==false)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}