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<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pi acos(-1)
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define rep(i,x,n) for(int i=x;i<n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
using namespace std;
typedef pair<int,int>P;
const int MAXN=100010;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int a[12],b[12],book[12];
bool flag = 0;
void dfs(int k)
{
	if(k == 10)
	{
		int last = 0;
		for(int i=1;i<=10;i++)
		{
			if(!book[i])
			{
				if(a[i] < last)
				return ;
				last = a[i];
			}
		}
		flag = 1;
		return ;
	}
	for(int i=k;i<=10;i++)
	{
		if(a[i] > a[k])
		{
			book[i] = 1;
			dfs(i+1);
			book[i] = 0;
		}
	}
}
int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		for(int i=1;i<=10;i++)
		cin >> a[i];
		for(int i=1;i<=10;i++)
		{
			memset(book, 0, sizeof(book));
			book[i] = 1;
			dfs(i);
			if(flag)
			{
				cout << "YES\n";
				break;
			}
		}
		if(!flag)
		cout << "NO\n";
		flag = 0;
	}
 	return 0;
}

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

using namespace std;

#define MAX_N 11

int T;
int num[MAX_N];
int BStack[MAX_N];
int BTop;
int CStack[MAX_N];
int CTop;

bool dfs(int cur)
{
	bool b1=false,b2=false;

	if(cur==10)
		return true;
	if(BTop==-1 || BStack[BTop]<num[cur])
	{
		BStack[++BTop]=num[cur];
		b1=dfs(cur+1);
		--BTop;
	}
	if(CTop==-1 || CStack[CTop]<num[cur])
	{
		CStack[++CTop]=num[cur];
		b2=dfs(cur+1);
		++CTop;
	}

	return b1|b2;
}

int main()
{
	scanf("%d",&T);

	while(T--)
	{
		for(int i=0;i<10;i++)
			scanf("%d",&num[i]);
		BTop=CTop=-1;

		if(dfs(0))
			printf("YES\n");
		else
			printf("NO\n");
	}
}

C++: #include <iostream>
using namespace std;
int main(void){
  int n;
  cin>>n;
  while(n--){
    int ans=1;
    for(int i=0,a,p=0,q=0;i<10;++i){
      cin>>a;
      if(ans){
          if(p>=a&&q>=a) ans=0;
          else{
            if(p>q) (p<a)?p=a:q=a;
            else (q<a)?q=a:p=a;
          }
      }
    }
    cout<<(ans?"YES":"NO")<<endl;
  }
  return 0;
}

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

bool solve(const int* values, int count, int top1, int top2)
{
	return (count == 0)
		|| (*values > top1 && solve(values + 1, count - 1, *values, top2))
		|| (*values > top2 && solve(values + 1, count - 1, top1, *values));
}


int main()
{
	int count = 0;
	std::cin >> count;

	for (int i = 0; i < count; ++i) {
		int values[10] = {};
		for (int j = 0; j < 10; ++j) {
			std::cin >> values[j];
		}
		if (solve(values, 10, 0, 0)) {
			std::cout << "YES\n";
		} else {
			std::cout << "NO\n";
		}
	}

	return 0;
}

C++: #define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
	int n;
	for (cin >> n; n--;)
	{
		vector<int> a(10);
		for (int i = 0; i < 10; i++)
		{
			cin >> a.at(i);
		}
		
		int id = 1;
		bool b = true;
		for (int i = 0; i < a.size(); i++)
		{
			for (int j = 1; j < a.size(); j++)
			{
				if (a.at(j) > a.at(j - 1))
				{
					continue;
				}
				else
				{
					if (id == a.at(j))
					{
						id++;
						a.erase(a.begin() + j);
						break;
					}
					else
					{
						b = false;
						break;
					}
				}
			}

			if (!b)
			{
				break;
			}
		}


		cout << (b ? "YES" : "NO") << endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;
#define FOR(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
int num[10];
int B[10];
int C[10];
bool flag;
void solve(int, int, int);

int main(void){
	int N;
	cin >> N;
	for(int k = 0; k < N; k++){
		flag = false;
		fill_n(B , 10, -1);
		fill_n(C , 10, -1);
		for(int i = 0; i < 10; i++){
			cin >> num[i];
		}
		solve(0, 0, 0);
		if(flag){cout << "YES" << endl; continue;}
		cout << "NO" << endl;
	}

	return 0;
}

void solve(int cnt,int right, int left){
	if(cnt == 10){
		flag = true;
		return;
	}
	if(num[cnt] > right) solve(cnt+1, num[cnt], left);
	if(num[cnt] > left) solve(cnt+1, right, num[cnt]);
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;

int T;
int mapp[15];

bool dfs(int index,int L,int R){


    if(index==10)return true;

    bool flag=false;

    if(L<mapp[index])   flag=(flag||dfs(index+1,mapp[index],R));
    if(R<mapp[index])   flag=(flag||dfs(index+1,L,mapp[index]));
    return flag;
}


int main(){
    cin>>T;
    while(T--){
        for(int i=0;i<10;i++){
            scanf("%d",&mapp[i]);
        }

        if(dfs(0,0,0)){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
        memset(mapp,0,sizeof(mapp));
    }
    return 0;
}

C++: #include <cstdio>

const int N_BALL = 10;

int balls[N_BALL];

bool solve(int l[], int l_top, int r[], int r_top) {
  int bi = (l_top + 1) + (r_top + 1);

  if (bi == N_BALL) return true;

  l[l_top+1] = balls[bi];
  if (l_top >= 0 && l[l_top] > l[l_top+1]) return false;
  if (solve(l, l_top+1, r, r_top)) return true;

  r[r_top+1] = balls[bi];
  if (r_top >= 0 && r[r_top] > r[r_top+1]) return false;
  if (solve(l, l_top, r, r_top+1)) return true;

  return false;
}

int main() {
  int N;
  scanf("%d", &N);

  for (int i = 0; i < N; i++) {
    for (int bi = 0; bi < N_BALL; bi++) scanf("%d", &balls[bi]);

    int left[N_BALL] = {}, right[N_BALL] = {};
    if (solve(left, -1, right, -1)) printf("YES\n");
    else printf("NO\n");
  }

  return 0;
}

C++: #include<stack>   //????????????
#include<iostream>
 
using namespace std;
 
int main(void){
    int n,i,data[10],ans=1;
    stack<int> right;
    stack<int> left;
 
    cin>>n;
    while(n>0){
        n--;
        cin>>data[0]>>data[1]>>data[2]>>data[3]>>data[4]>>data[5]>>data[6]>>data[7]>>data[8]>>data[9];
        right.push(data[0]);
        for(i=1;i<10;i++){
            if(right.top()<data[i])
                right.push(data[i]);
            else{
                if(left.empty())
                    left.push(data[i]);
                else{
                    if(left.top()<data[i])
                        left.push(data[i]);
                    else
                        ans=0;
                }
            }
        }
        if(ans==0) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
        while(!left.empty())
            left.pop();
        while(!right.empty())
            right.pop();
    }
 
    return 0;
}