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 <algorithm>
#define HEIGHT 10

using namespace std;

int a[HEIGHT];

void solve(){
	bool f=true;
	int right,left;
	right = left = 0;
	for(int i=0;i<HEIGHT;i++){
		if(right<a[i] && left<a[i]){
			if(right<left){
				left = a[i];
			} else {
				right = a[i];
			}
		} else if(right<a[i]){
			right = a[i];
		} else if(left<a[i]){
			left = a[i];
		} else {
			f = false;
			break;	
		}
	}
	if(f){
		printf("YES\n");
	} else {
		printf("NO\n");
	}
}
			
int main(){
	
	int lp;
	scanf("%d",&lp);
	
	for(int i=0;i<lp;i++){
		for(int j=0;j<HEIGHT;j++){
			scanf(" %d",&a[j]);
		}
		solve();	
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main(){
    int n; cin >> n;
    while(n--){
        vector<int> v(10);
        rep(i,10) cin >> v[i];
        int a=0, b=0;
        bool is = true;
        for(int i=0; i< 10; i++){
            if(v[i] < a && v[i] < b){is = false; break;}
            if(a < b) (b<v[i]?b:a) = v[i];
            else (a<v[i]?a:b) = v[i];
        }
        cout << (is?"YES":"NO") << endl;
    }
}

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

int main(void)
{
    int n;
    scanf("%d", &n);
    
    for (int i = 0; i < n; i++){
        stack < int > b, c;
        int j;
        
        b.push(0);
        c.push(0);
        
        int ball[10];
        for (int i = 0; i < 10; i++){
            scanf("%d", &ball[i]);
        }
        
        for (j = 0; j < 10; j++){
            if (b.top() < ball[j]){
                if (c.top() < ball[j]){
                    if (c.top() < b.top()){
                        b.push(ball[j]);
                    }
                    else {
                        c.push(ball[j]);
                    }
                }
                else {
                    b.push(ball[j]);
                }
            }
            else if (c.top() < ball[j]){
                c.push(ball[j]);
            }
            else {
                break;
            }
        }
        
//        printf("%d\n", j);
        
        if (j == 10){
            printf("YES\n");
        }
        else {
            printf("NO\n");
        }
    }
    
    return (0);
}

C++: #include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
int a[10];
bool ans;
void dfs(int i,int r,int l){
	if(i==10)ans=1;
	if(a[i]<r&&a[i]<l)return;
	if(ans)return;
	if(r<a[i])dfs(i+1,a[i],l);
	if(l<a[i])dfs(i+1,r,a[i]);

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

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int a[10];
int n;

bool dfs(int i,int left,int right){
	if(i==10) return true;
	if(a[i]>left){
		return dfs(i+1,a[i],right);
	}
	if(a[i]>right){
		return dfs(i+1,left,a[i]);
	}
	return false;
}

void solve(){
	rep(i,10) cin >> a[i];
	if(dfs(0,0,0)) cout << "YES" << endl;
	else cout << "NO" << endl;
	return;
}

int main(){
	cin >> n;
	rep(i,n){
		solve();
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
#define N 10
int flag;
int shunxu[N+5];
void dfs(int x1,int y1,int x2,int y2,int ans) {
	if (x2 < x1 || y2 < y1)
		return;
	if (ans == 10) {
		flag = 1;
		return;
	}
	dfs(x2, y1, shunxu[ans], y2, ans + 1);
	dfs(x1, y2, x2, shunxu[ans], ans + 1);
}
int main()
{
	int n;
	cin >> n;
	while (n--) {
		for (int i = 0; i < N; i++) {
			cin >> shunxu[i];
		}
		flag = 0;
		dfs(0, 0, 0, 0, 0);
		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

int b[10];

bool dfs(int idx, int left, int right)
{
	if (idx == 10) return true;

	if (b[idx] > left && dfs(idx + 1, b[idx], right)) return true;
	if (b[idx] > right && dfs(idx + 1, left, b[idx])) return true;

	return false;
}

int main()
{
	int n; cin >> n;
	while (n--) {
		for (int i = 0; i < 10; ++i) cin >> b[i];

		cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

bool ans;
int a[10];

void dfs(int idx, int l, int r) {
   if (idx == 10) {
      ans = true;
      return;
   }

   int val = a[idx];
   if (l < val) dfs(idx+1, val, r);
   if (r < val) dfs(idx+1, l, val);
}

int main() {
   int N;
   cin >> N;
   while (N--) {
      for (int i = 0; i < 10; i++) cin >> a[i];
      ans = false;
      dfs(0, -1, -1);
      puts(ans ? "YES" : "NO");
   }

   return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int a[10];
bool dfs(int d, int l, int r){
    if(d == 10) return true;
    if(a[d] > l && dfs(d + 1, a[d], r))
      return true;
    if(a[d] > r && dfs(d + 1, l, a[d]))
       return true;
    return false;
}
int main(){
    int n;
    cin >> n;
    for(int k = 0; k < n; k++){
        for(int i = 0; i < 10; i++)
          cin >> a[i];
        if(dfs(0, 0, 0))
          puts("YES");
        else
          puts("NO");
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std ;
int a[50] ,flag , l , r  ;
void dfs(int x , int l , int r)
{
    if(x==11) return ;
    if(a[x]>l) dfs(x+1,a[x],r);
    else if(a[x]>r) dfs(x+1,l,a[x]);
    else
    {
        flag = 1 ;
        return;
    }
}
int main()
{
    int t ;
    cin>>t;
    while(t--)
    {
        flag = 0 ;
        for(int i = 1 ; i<=10;i++)
        {
            cin>>a[i];
        }
        dfs(1,0,0);
        if(flag) printf("NO\n");
        else printf("YES\n");
    }
    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;

	while(cin >> n){
		a = b = 0;
		check = true;
		rep(i,10){
			cin >> g;
			ball.insert( ball.begin(), g);
		}
		rep(i,10){
			if(a < ball.back()){
				a = ball.back();
				ball.pop_back();
			}else if(b < ball.back()){
				b = ball.back();
				ball.pop_back();
			}else{
				check = false;
			}
		}
		if(check) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}