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>

using namespace std;

const int BALL_NUM = 10;

int ball[BALL_NUM];

bool dfs(int i, int left, int right) {
    if (i == BALL_NUM) { return true; }
    bool ans = false;
    if (left < ball[i]) {
        ans = dfs(i + 1, ball[i], right);
    }
    if (right < ball[i]) {
        ans = dfs(i + 1, left, ball[i]);
    }
    return ans;
}

int main() {
    long n;
    scanf("%ld", &n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < BALL_NUM; j++) {
            scanf("%d", &ball[j]);
        }
        if (dfs(0, 0, 0)) { printf("%s\n", "YES"); }
        else { printf("%s\n", "NO"); }
    }

    return 0;
}

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

int n;
int a[10];
int r, l;

// bool dfs(int i) {
//     if (i == 9) return a[i] > r || a[i] > l;
//     if (a[i] > r) {
//         r = a[i];
//     }
//     if (a[i] > l) {
//         l = a[i];
//     }
//     if (dfs(i+1)) return true;
//     return false;
// }

bool dfs(int i, int r, int l) {
	if (i == 9) return a[i] > r || a[i] > l;
	if (dfs(i + 1, max(a[i + 1], r), l)) return true;
	if (dfs(i + 1, r, max(a[i + 1], l))) return true;
	return false;
}

void solve() {
	if (dfs(0, a[0], a[0])) cout << "YES" << endl;
	else cout << "NO" << endl;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> a[j];
		}
		solve();
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;

int a[20];
bool vis[20];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T;cin>>T;
	while(T--){
		bool flag=false;
		for(int i=1;i<=10;i++){
			cin>>a[i];
		}
		int k[20];
		int len=1;
		k[1]=a[1];
		for(int i=2;i<=10;i++){
			if(a[i]<k[len]){
				k[++len]=a[i];
			}else{
				*upper_bound(k+1,k+1+len,a[i],greater<int>())=a[i];
			}
			if(len>2){
				flag=true;
				break;
			}
		}
		cout<<(flag?"NO\n":"YES\n");
	}
	return 0;
}

C++: #include<algorithm>
#include<vector>
#include<queue>

using namespace std;

int A[13] = { 0 };

bool solve(int a, int b,int c) {
	if (++c == 10)
		return true;
	else {
		bool r = false;
		if (a < A[c])
			r = solve(A[c], b, c);
		if (b < A[c] && r == false)
			r = solve(a,A[c], c);
		
		return r;
	}
}

int main(void) {
	A[10] = A[11] = A[12] = 100;
	int n = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++)
			scanf("%d", &A[j]);
		if (solve(A[0], 0, 0))
			printf("YES\n");
		else
			printf("NO\n");
	}
}

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


int main() {
  int n;
  int data[10];
  cin >> n;
  while ( n > 0 ) {
    n--;
    int flag = 1;
    for ( int i = 0; i < 10; i++ ) cin >> data[i];
    for ( int i = 0; i < 8; i++ ) {
      if ( data[i] > data[i+1] && 
	   data[i] > data[i+2] ) {
	flag = 0;
      }
    }
    if ( flag ) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

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

int ball[10];
bool dfs(int point, int right, int left){
	if(point == 10) return true;
	if(right < ball[point]) return dfs(point + 1, ball[point], left);
	if(left < ball[point]) return dfs(point + 1, right, ball[point]);
	return false;
}
int main(){
	int N;
	scanf("%d", &N);
	while(N){
		for(int i = 0; i < 10; i++){
			scanf("%d", &ball[i]);
		}
		if(dfs(0, 0, 0)) printf("YES\n");
		else printf("NO\n");
		N--;
	}
}

C++: #include <iostream>
int a[15];
bool dfs(int prev_b , int prev_c , int p){
    if(p == 10){
        return true;
    }
    bool tf = false;
    if(a[p] > prev_b){
        tf = dfs(a[p] , prev_c , p + 1);
    }
    if(tf){
        return true;
    }
    if(a[p] > prev_c){
        tf = dfs(prev_b , a[p] , p + 1);
    }
    return tf;
}
int main(){
    int n;
    std::cin >> n;
    while(n--){
        for(int i = 0;i < 10;i++){
            std::cin >> a[i];
        }
        if(dfs(-1 , -1 , 0)){
            std::cout << "YES\n";
        }else{
            std::cout << "NO\n";
        }
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;

int n, k, b = 0, c = 0;
stack<int> sb, sc;

int main(){
	sb.push(0);
	sc.push(0);
	cin >> n;
	REP(i, n){
		REP(j, 10){
			cin >> k;
			if (b == 0){
				sb.push(k);
				b++;
				/*cout << sb.top() << ":" << b << " "
					<< sc.top() << ":" << c << "\n";*/
			}
			else if (c == 0){
				sc.push(k);
				if (sb.top() < k){
					sc.push(sb.top());
					sb.push(k);
				}
				c++;
				/*cout << sb.top() << ":" << b << " "
					<< sc.top() << ":" << c << "\n";*/
			}
			else{
				if (sb.top() < k){
					sb.push(k);
					b++;
				}
				else if (sc.top() < k){
					sc.push(k);
					c++;
				}
				/*cout << sb.top() << ":" << b << " "
					<< sc.top() << ":" << c << "\n";*/
			}
		}
		if (b + c == 10){
			cout << "YES\n";
		}
		else{
			cout << "NO\n";
		}
		sb.push(0);
		sc.push(0);
		b = 0;
		c = 0;
	}
}

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

int main(){
	int n;
	std::cin >> n;
	while (n){
		std::vector<int> ball(10);
		for (int i = 0; i < 10; ++i)std::cin >> ball[i];
		int b = 0, c = 0;
		for (int i = 0; i < 10; ++i){
			if (b < c){
				std::swap(b, c);
			}
			else if (b < ball[i]){
				b = ball[i];
			}
			else if (c < ball[i]){
				c = ball[i];
			}
			else if (i != 9){
				std::cout << "NO" << std::endl;
				break;
			}
			else{
				std::cout << "YES" << std::endl;
				break;
			}
		}
		n--;
	}
	return 0;
}

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

int a[10];
int b[10],c[10],lb,lc;
int vis[10];
int n,m,t;

bool dfs(int s,int e)
{
    int cnt = 0;
    if(s==e) return true;

    if(!lb || b[lb-1] < a[s])
    {
        cnt++;
        b[lb++] = a[s];
        if(dfs(s+1,e)) return true;
        lb--;
        b[lb] = 0;
    }
    if(!lc || c[lc-1] < a[s])
    {
        cnt++;
        c[lc++] = a[s];
        if(dfs(s+1,e)) return true;
        lc--;
        c[lc] = 0;
    }
    return false;
}

int main()
{
    scanf("%d",&t);
    while(t--)
    {
        for(int i=0;i<10;i++)
            scanf("%d",&a[i]);
        lb = 0, lc = 0;
        if(dfs(0,10)) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

C++: #include<iostream>
#include<queue>
#include<stack>
using namespace std;
int main()
{
	int n;
	cin>>n;
	stack<int>q;
	stack<int>p;
	while(n--){
		
		q.push(0);
		p.push(0);
		int f=1;
		for(int i=1;i<=10;i++)
		{
			int t;
			cin>>t;
			if(p.top()<t)
			p.push(t);
			else if(q.top()<t)
			q.push(t);
			else{
				f=0;
			}
		}
		if(f==0)
		cout<<"NO"<<endl;
		else
		cout<<"YES"<<endl;
		while(!q.empty())
		q.pop();
		while(!p.empty())
		p.pop();
	
	}
 }