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 <stdio.h>

int a[10];
int flag;

void dfs(int b_top,int c_top,int num) {

  if(num==10) {

    flag=1;
    return;

  }

  if(b_top<a[num]) dfs(a[num],c_top,num+1);

  if(c_top<a[num]) dfs(b_top,a[num],num+1);

  return;

}

int main(void) {

  int n;

  int i;


  scanf("%d",&n);

  for(i=0;i<n;i++) {

    scanf("%d %d %d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);

    flag=0;

    dfs(0,0,0);

    if(flag==1) printf("YES\n");
    else printf("NO\n");

  }

  return 0;

}

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

int main() {
	int n, x, z;
	cin >> n;

	for (int i = 0; i < n; i++) {
		vector< vector<int> > v{ {0} };
		for (int j = 0; j < 10; j++) {
			cin >> x;
			z = v.size();
			for (int k = 0; k < z; k++) {
				if (v[k].back() < x) {
					v[k].push_back(x);
					break;
				}

				if (k == z - 1) {
					v.push_back({ x });
					break;
				}
			}

			if (v.size() == 3) {
				x = -1;
				break;
			}
		}

		if (x == -1) {
			cout << "NO";
		}
		else {
			cout << "YES";
		}
		cout << endl;
	}
	return 0;
}

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

bool f(void){
	int x[10], a=0, b=0;
	for (int i=0; i<10;i++)
		cin>>x[i];
	for (int i=0; i<10; i++){
		int e=x[i];
		if (e>a) a=e;
		else if (e>b) b=e;
		else return false;
	}
	return true;
}

int main(void){

	int n;
	cin>>n;
	while (n--){
		if (f()) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include<cstdio>

#define INF 0x7fffffff
int T;
int A[12];

int main()
{
	scanf("%d",&T);
	while(T--)
	{
		for(int i=1;i<=10;i++)
			scanf("%d",&A[i]);
		int x=INF,y=INF;
		bool f=1;
		for(int i=10;i>=1;i--)
		{
			if(A[i]>x&&A[i]>y)
			{
				f=0;
				break;
			}
			if(A[i]<x)
				x=A[i];
			else
				y=A[i];
		}
		if(f) printf("YES\n");
		else printf("NO\n");
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int kuru[10];
bool solve(int l,int r,int co,int now);
int main(){
  int n;
  cin>>n;
  while(n--){
    for(int i=0;i<10;i++){
      cin>>kuru[i];
    }
    if(solve(0,0,0,0))cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}
bool solve(int l,int r,int co,int now){
  if(co==10)return true;
  if(l<kuru[now]){
    if(solve(kuru[now],r,co+1,now+1))return true;
    else return false;
  }
  if(r<kuru[now]){
    if(solve(l,kuru[now],co+1,now+1))return true;
    else return false;
  }
  else if(r>kuru[now] && l>kuru[now])return false;
}

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


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 res=0;
	int n;
	scanf("%d",&n);
	for(a=0;a<n;a++){
		memset(ball,0,sizeof(ball));
		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<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],cnt,book[12];
bool flag;
void dfs(int k)
{
	if(k == 11)
	{
		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+1;i<=10;i++)
	{
		if(a[i] > b[cnt - 1])
		{
			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++)
		{
			cnt = 1;
			dfs(i);
			if(flag)
			{
				cout << "YES\n";
				break;
			}
		}
		if(!flag)
		cout << "NO\n";
		flag = 0;
	}
 	return 0;
}

C++: #include <cstdio>

const int N_BALL = 10;

int balls[N_BALL];

bool solve(int l_top, int r_top, int n) {
  if (n == N_BALL) return true;

  int l_top_ = balls[n];
  if (l_top > l_top_) return false;
  if (solve(l_top_, r_top, n+1)) return true;

  int r_top_ = balls[n];
  if (r_top > r_top_) return false;
  if (solve(l_top, r_top_, n+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]);

    if (solve(-1, -1, 0)) printf("YES\n");
    else printf("NO\n");
  }

  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
#include <functional>
const int INF =1e5;
const int MOD = 1e9 + 7;
using namespace std;
typedef pair<int,int> P;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define pb push_back
vector<int> a;
vector<int> b;
int v[10];
bool dfs(int,int,int);

int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;++i){
        rep(i,10) cin>>v[i];
        if(dfs(0,0,0)) cout<<"YES"<<endl;
        else  cout<<"NO"<<endl;
    }
    return 0;
}
bool dfs(int i,int a,int b){
    if(i==10)return true;
    if(a<v[i]) return dfs(i+1,v[i],b);
    if(b<v[i]) return dfs(i+1,a,v[i]);
    if(a>=v[i] && b>=v[i])return false;
    return false;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

using namespace std;

int main(){
	int n;

	cin >> n;

	while(n--){
		int tmp = 0;
		vector<int> b, c;
		bool limitB = false, limitC = false;

		for(int i = 0; i < 10; i++){
			limitB = false;
			limitC = false;
			cin >> tmp;

			if(b.size() == 0){
				b.push_back(tmp);
				continue;
			}
			else if(b.size() != 0 && c.size() == 0){
				if(b[b.size() - 1] < tmp){
					b.push_back(tmp);
					continue;
				}
				else{
					limitB = true;
				}
			}
			
			if(c.size() == 0){
				c.push_back(tmp);
				continue;
			}
			
			if(b[b.size() - 1] < tmp){
				b.push_back(tmp);
				continue;
			}
			else{
				limitB = true;
			}
		
			if(c[c.size() - 1] < tmp){
				c.push_back(tmp);
				continue;
			}
			else{
				limitC = true;
			}

			if(limitB && limitC){
				cout << "NO" << endl;
				break;
			}

		}
		if(!limitB || !limitC){
			cout << "YES" << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int a[10];

bool dfs(int i, int left, int right){
	cout << left << " " << right << " " << i << endl;
	if(i == 10) return true;
	bool answer = false;
	if(left < a[i]){
		answer = dfs(i+1, a[i], right);
	}
	if(right < a[i]){
		answer = dfs(i+1, left, a[i]);
	}

	return answer;
}


int main(){
	int N;
	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;
	}
	return 0;
}