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>

using namespace std;

int a[10];

bool dfs(int i, int l, int r)
{
    if (i == 10) return true;

    if (l < a[i] && dfs(i + 1, a[i], r)) return true;
    if (r < a[i] && dfs(i + 1, l, a[i])) return true;

    return false;
}

int main()
{
    int n; cin >> n;

    while (n--) {
        for (int i = 0; i < 10; ++i) cin >> a[i];
        cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
    }
}

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

using namespace std;

bool solve(vector<int> balls, vector<int> &b,vector<int> &c, int index) {
    
    if (index >= 10) return true;
    if (b.back() < balls[index]) {
        b.push_back(balls[index]);
        index++;
        return solve(balls, b, c, index);
    }
    if (c.back() < balls[index]) {
        c.push_back(balls[index]);
        index++;
        return solve(balls, b, c, index);
    }
    return false;
}

int main(){
    int N;
    cin >> N;
    bool flag;
    vector<vector<int> > balls(N, vector<int>(10));
    
    for (int j = 0; j < N; j++) {
        for (int i = 0; i < 10; i++) {
            cin >> balls[j][i];
        }
    }
    for (int j = 0; j < N; j++) {
        vector<int> b, c;
        b.push_back(0);
        c.push_back(0);
        flag = solve(balls[j], b, c, 0);
        if (flag) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int t;
  cin >> t;
  int n[10];
  for(int i=0;i<t;i++){
    int h = 0,b = 0,c = 0;
    for(int j=0;j<10;j++) cin >> n[i]; 
    for(int j=0;j<10;j++){
      cin >> n[i];
      if(b==0) b = n[i];
      else if(b>c&&b<n) b = n[i];
      else if(c>b&&c<n) c = n[i];
      else if(b>c&&b>n&&c<n) c = n[i];
      else if(c>b&&c>n&&b<n) b = n[i];
      else if(b>n[i]&&c>n[i]){
	cout << "NO" << endl;
	h = 1;
	break;
      }
    }
    if(h==0) cout << "YES" << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;
int main()
{
	//freopen("3.txt","r",stdin);
	int n;
	cin >> n;
	int a[11];
	int b[2];
	int flag;
	b[0]=0;
	b[1]=0;
	while(n--)
	{
		flag=1;
		for(int i=0;i<10;i++)
			{
				cin >> a[i];
				sort(b,b+2);
				if(a[i]>b[1])
				{
					b[1]=a[i];
				}
				else if(a[i]<b[1]&&a[i]>b[0])
				{
					b[0]=a[i];
				}
				else if(a[i]<b[0])
					{
						flag=0;
					}
			}
		if(flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
 }
 return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int a=0,b=0;
  int c=0;
  cin>>c;
  for(int i=0;i<c;i++){
    a=0;
    b=0;
    for(int i=0;i<10;i++){
      int t;
      cin>>t;
      if(t<a&&t<b){
	cout<<"NO"<<endl;
	break;
      }
      if(a<t)a=t;
      else b=t;
      if(i==9)cout<<"YES"<<endl;
    }
  }
  return 0;
}

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

int n,len,ball[20],used[20];

int f()
{
	int t = -1;
	for (int i=1;i<=10;++i)
		if (!used[i])
		{
			if (ball[i] < t) return 0;
			t = ball[i];
		}
	t = -1;
	for (int i=1;i<=10;++i)
		if (used[i])
		{
			if (ball[i] < t) return 0;
			t = ball[i];	
		}
	return 1;
}

int dfs(int x,int l)
{
	if (l == len) return f();
	for (int i=x+1;i<=10;++i)
		if (!used[i])
		{
			used[i] = 1;
			if (dfs(i,l+1)) return 1;
			used[i] = 0;
		}
	return 0;
}

int main()
{
//	freopen("in.txt","r",stdin);
	cin>>n; 
	while (n--)
	{
		int flag = 0;
		for (int i=1;i<=10;++i) cin>>ball[i];
		for (int i=0;i<=5;++i)
		{
			memset(used,0,sizeof(used));
			len = i;
			if (dfs(0,0)) 
			{
				flag = 1;
				break;
			}
		}
		if (flag) cout<<"YES";
		else cout<<"NO";
		puts("");
	}
	return 0;
}

C++: #include <stdio.h>
#include <stdbool.h>
int balls[10];
int left[10],right[10],l=0,r=0,det;
void solve();
void dfs(int depth);
bool check();
int main(void){
	int times;
	scanf("%d",&times);
	for(int i=0;i<times;i++){
		for(int j=0;j<10;j++)
			scanf("%d",&balls[j]);
		solve();
	}
	return 0; 
}

void solve(){
	det=0;
	dfs(0);
	if(det)	puts("YES");
	else	puts("NO");
}

void dfs(int depth){
	if(det)	return;
	if(depth==9){
		if(check())	det=1;
		return;
	}
	left[l++]=balls[depth++];
	dfs(depth);
	l--;depth--;
	right[r++]=balls[depth++];
	dfs(depth);
	r--;depth--;
}

bool check(){
	bool m=1,n=1;
	for(int i=0;i<l-1;i++)
		if(left[i]>left[i+1]){
			m=0;
			break;
		}
	for(int i=0;i<r-1;i++)
		if(right[i]>right[i+1]){
			n=0;
			break;
		}
	return m&&n;
}

C++: #include <cstdio>
#include <iostream>
using namespace std;
int ans = 0;
void judge(int a[], int aa, int b,int  c) {
	if (aa == 10)ans = 1;
	if (a[aa] > b) {
		if (a[aa] > c)
		{
			judge(a, aa + 1, a[aa], c);
			judge(a, aa + 1, b, a[aa]);
		}
		judge(a, aa + 1, a[aa], c);
	}
	else if (a[aa] > c)judge(a, aa + 1, b, a[aa]);
}
int main() {
	int n;
	int a[10] = { 0 };
	cin >> n;
	for (int i = 0; i < n; i++) {
		ans = 0;
		for (int j = 0; j < 10; j++) {
			cin >> a[j];
		}
		judge(a, 0, 0, 0);
		if (ans == 1)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	}

C++: #include <iostream>

using namespace std;

int ball[11],f;

int hukasa(int cup1,int cup2,int no){
	//cout << "NOW no:" << no << endl;
	if(no>=10)return 1;
	else if((ball[no]<cup1)&&(ball[no]<cup2))return 0;
	
	if(cup1<ball[no])return hukasa(ball[no],cup2,no+1);
	if(cup2<ball[no])return hukasa(cup1,ball[no],no+1);
}
int main(){
	int n;
	cin>>n;
	while(n!=0){
		f = 0;
		for(int i=1;i<11;i++){
			cin>>ball[i];
			}
		f = hukasa(0,0,1);
		//cout << "f is " << f << endl;
		if(f==1)cout << "YES" << endl;
		else cout<<"NO"<<endl;
		n-=1;
}
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n; cin >> n;
	while (n--) {
		int a(0), b(0), x;
		bool f(true);
		rep(i, 0, 10) {
			cin >> x;
			if (a < x)a = x;
			else if (b < x)b = x;
			else f = false;
		}
		cout << (f ? "YES" : "NO") << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int a[11];
bool dfs(int i,int l,int r){
	if(i==10)return true;
	if(dfs(i+1,a[i],r)&&a[i]>l)return true;
	if(dfs(i+1,l,a[i])&&a[i]>r)return true;
	return false;
}
int main(){
	int T;
	cin>>T;
	while(T--){
	for(int i=0;i<10;i++)
		cin>>a[i];
	if(dfs(0,0,0))cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	}
	return 0;
}