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 <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int n;

bool dfs(queue<int> S,int l,int r){
  if(S.empty())
    return true;
  int x = S.front();
  S.pop();

  if(x < l&& x <r)
    return false;
  else if(x < l)
    return dfs(S,l,x);
  else if(x <r)
    return dfs(S,x,r);
  else 
    return dfs(S,x,r)||dfs(S,l,x);
}

int main()
{
  cin>>n;
  for(int i = 0;i < n;i++){
    queue<int> S1;
    for(int j = 0;j < 10;j++){
      int ball;
      cin >>ball;
      S1.push(ball);
    }
    if(dfs(S1,0,0)){
      cout <<"YES"<<endl;
      }else
      cout <<"NO"<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
	int a,b;
	int n;
	int g;
	bool check;
	vector<int> ball(10);

	while(cin >> n){
		a = b = 11;
		check = true;
		rep(i,10){
			cin >> g;
			ball.push_back(g);
		}
		rep(i,10){
			if(a > ball.back()){
				a = ball.back();
				ball.erase( --ball.end() );
			}else if(b > ball.back()){
				b = ball.back();
				ball.erase( --ball.end() );
			}else{
				check = false;
			}
		}
		if(check) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

C++: #include <iostream>
#define MAX(a,b) ((a>b)?(a):(b))
using namespace std;

int main(void){
	int a,b;
	int n;
	int k[10];
	int i;
	cin>>n;
	while(n--){
		a=b=-1;
		for(i=0;i<10;i++) cin>>k[i];
		for(i=0;i<10;i++){
			if(a>k[i]&&b>k[i])break;
			if(k[i]>a&&k[i]>b){
				if(a>b)a=k[i];
				else b=k[i];
			}else if(k[i]>a)a=k[i];
			else if(k[i]>b)b=k[i];
		}
		if(i==10)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include<stdio.h>

int main(){

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


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

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

	if(M==0){m[M]=n[i];M++;}
	else if(m[M-1]<n[i]&&M>0){M++;m[M]=n[i];}

	else if(P==0){p[P]=n[i];P++;}
	else if(p[P-1]<n[i]&&P>0){P++;p[P]=n[i];}
	
	
else f=false;
}


if(f==true)printf("YES\n");
else if(f==false)printf("NO\n");
//for(int i=0;i<10;i++)
//	printf("%d %d\n",m[i],p[i]);

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

bool f=true;
P=0,M=0;


}
return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
  int n, num, right, left;
  bool flag;

  cin >> n;

  for(int i = 0; i < n; i++){
    right = 0;
    left = 0;
    flag = true;
    for(int j = 0; j < 10; j++){
      cin >> num;

      if(right < num){
        right = num;
      }else{
        left = num;
      }

      if(20 - (right + left) < 10 - (j + 1)) flag = false;
    }

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

  return 0;
}

C++: #include <cstdio>

int n;

bool solve(int *balls, int i, int depth, int left, int right) {
    if (i == depth)
        return true;
    if (left < balls[i] 
            && solve(balls, i+1, depth, balls[i], right))
        return true;
    if (right < balls[i]
            && solve(balls, i+1, depth, left, balls[i]))
        return true;
    return false;
}

int main() {
    scanf(" %d", &n);
    for (int i = 0; i < n; i++) {
        int balls[10];
        for (int j = 0; j < 10; j++) {
            scanf(" %d", &balls[j]);
        }
        puts(solve(balls, 0, 10, 0, 0) ? "YES" : "NO");
    }
}

C++: #include<cstdio>
int n, a[10];
int b[11] = { }, c[11] =

{
};

bool
dfs (int l, int r)
{
  if (l + r == 9)
    return true;
  if (b[l] < a[l + r])
    {
      b[l + 1] = a[l + r];
      return dfs (l + 1, r);
    }
  else if (c[r] < a[l + r])
    {
      c[r + 1] = a[l + r];
      return dfs (l, r + 1);
    }
  return false;
}

int
main (void)
{
  scanf ("%d", &n);
  for (int i = 0; i < n; i++)
    {
      for (int j = 0; j < 10; j++) {
	scanf ("%d", &a[j]);
        b[j+1] = 0;
        c[j+1] = 0;
      }
      if (dfs (0, 0))
	puts ("YES");
      else
	puts ("NO");
    }
  return 0;
}

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

bool dfs(vector<int>& balls,int i, int left, int right){
    if(i >= balls.size()) return true;

    bool l = true, r = true;
    if(left > balls[i]) l = false;
    if(right > balls[i]) r = false;

    if(!l && !r) return false;

    bool ok = false;

    if(l) ok |= dfs(balls, i+1, balls[i], right);
    if(r) ok |= dfs(balls, i+1, left, balls[i]);

    return ok;
}
int main(){
    int N;
    cin >> N;
    
    for(int i=0;i<N;i++){
        vector<int> balls(10);
        for(int j=0;j<10;j++) cin >> balls[j];

        bool ans = dfs(balls, 0, 0, 0);

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

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

int Balls[10];

bool fork(int balls[], int i, int b, int c) {
    if (i == 10) return true;
    if (b > balls[i] && c > balls[i]) return false;
    if (b < balls[i]) fork(balls, i + 1, balls[i], c);
    if (c < balls[i]) fork(balls, i + 1, b, balls[i]);
}


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

    }
        return 0;
}

C++: #include<iostream>
using namespace std;
int x[10];
int func(int n,int r,int l){
    if(n == 10)return 1;
    if(x[n]>r){
        if(func(n+1,x[n],l))return 1;
    }
    if(x[n]>l){
        if(func(n+1,r,x[n]))return 1;
    }
    return 0;
}
int main(){
	int k;
	cin>>k;
	while(k-->0){
		for(int i=0;i<10;i++)
			cin>>x[i];
		if(func(0,0,0))
			cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
	int n;
	int data[10];
	int a[11],b[11];
	int ai,bi;
	int k;
	int flag;
	cin>>n;
	while(n--){
		for(int i=0;i<10;i++) cin>>data[i];
		a[0]=b[0]=0;
		ai=bi=0;
		flag=0;
		for(k=0;k<10;k++){
			if(a[ai]<data[k]){
				a[ai+1]=data[k];
				ai++;
			}
			else if(b[bi]<data[k]){
				b[bi+1]=data[k];
				bi++;
			}
			if(data[k]<a[ai] && b[bi]>data[k])
				flag=1;
		}
		if(flag==1) cout<<"NO"<<endl;
		else cout<<"YES"<<endl;
	}
	return 0;
}