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<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl

int main() {
	lint N;
	cin >> N;
	rep(t, N) {
		bool yes = true;
		vector<lint>A(10);
		rep(i, 10) {
			cin >> A[i];
		}
		deque<lint>B;
		deque<lint>C;
		B.push_front(0);
		C.push_front(0);
		rep(i, 10) {
			if (i == 0) {
				B.push_front(A[i]);
			}
			else {
				if (B.front() < A[i] && A[i] < C.front()) {
					B.push_front(A[i]);
				}
				else if (C.front() < A[i] && A[i] < B.front()) {
					C.push_front(A[i]);
				}
				else if (B.front() < A[i] && C.front() < A[i]) {
					if (B.front() > C.front()) {
						B.push_front(A[i]);
					}
					else {
						C.push_front(A[i]);
					}
				}
				else {
					cout << "NO" << endl;
					yes = false;
					break;
				}
			}
		}
		if (yes == true) {
			cout << "YES" << endl;
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to) 
void dfs(stack<int> s, stack<int> r, stack<int> l, bool &f) {
	if(s.empty()) {
		f = 1;
		return;
	}
	int x = s.top();
	if(r.empty() || r.top() < x) {
		s.pop();
		r.push(x);
		dfs(s,r,l,f);
		r.pop();
		s.push(x);
	}
	if(l.empty() || l.top() < x) {
		s.pop();
		l.push(x);
		dfs(s,r,l,f);
		l.pop();
		s.push(x);
	}
}
int main() {
	int n;
	cin >> n;
	while(n--) {
		int a[10];
		stack<int> s;
		rep(i,10) {
			cin >> a[i];
		}
		rep(i,10) {
			s.push(a[10-i-1]);
		}
		stack<int> r;
		stack<int> l;
		bool f = 0;
		dfs(s,r,l,f);
		if(f) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

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

C++: #include <stdio.h>
#include <algorithm>
using namespace std;

int pow(int a,int n){
	if(n <= 0){
		return 1;
	}
	return a * pow(a,n - 1);
}

int main(){
	int n;
	int a[10];
	int ans1 = 0;
	int ans2 = 0;
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			scanf("%d",&a[j]);
		}
		for(int j = 0; j < 10; j++){
			if(ans1 >= ans2 && ans1 < a[j]){
				ans1 = a[j];
			}else if(ans2 > ans1 && ans2 < a[j]){
				ans2 = a[j];
			}else if(ans1 < a[j]){
				ans1 = a[j];
			}else if(ans2 < a[j]){
				ans2 = a[j];
			}else{
				printf("NO\n");
				break;
			}
			if(j == 9){
				printf("YES\n");
			}
		}
	}
	///////////////////////////////////
	//Sleep(200000);///////////////////// 提出するときは必ず外す！
	///////////////////////////////////
	return 0;

}

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

int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    int a, b = 0, c = 0;
    bool f = true;
    for (int i = 0; i < 10; ++i) {
      scanf("%d", &a);
      if (b < a) b = a;
      else if (c < a) c = a;
      else {
        puts("NO");
        f = false;
        break;
      }
    }
    if (f) puts("YES");
  }
}

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

using namespace std;

int main(){

	int n;
	cin>>n;

	int B=0,C=0;
	for(int i = 0; i < n; i++){
		bool f=false;
		for(int j = 0; j < 10; j++){
			int num;
			cin>>num;
			if(num>B&&num>C){
				if(num-B>num-C){
					C=num;
				}
				else
					B=num;
			}
			else if(num>B){
				B=num;
			}
			else if(num>C)
				C=num;
			else if(!f){
				f=true;
				cout<<"NO"<<endl;
//				break;
			}
		}
		if(!f)
			cout<<"YES"<<endl;
	}

	return 0;
}

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

int ball[10];

bool solve(int i, int a, int b){
	if (i == 10) return true;
	bool ans = false;
	if (a < ball[i]) ans = solve(i + i, ball[i], b);
	if (b < ball[i])ans = solve(i + i, a, ball[i]);
	return ans;
}

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

	for (int i = 0; i < n; i++){
		for (int j = 0; j < 10; j++){
			cin >> ball[j];
		}
		if (solve(0, 0, 0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;
}
//beatmaniaIIDX 23th copula

C++: #include <iostream>

using namespace std;

int main()
{
    int m;
    cin>>m;
    for(int l = 1; l <= m; ++l)
    {
        int llast = 0;
        int rlast = 0;
        int tmp;
        bool flag = true;
        for(int i = 0; i < 10; ++i)
        {
            cin>>tmp;
            if(tmp > llast)
            {
                if(tmp > rlast)
                {
                    if(tmp - llast < tmp - rlast)
                        llast = tmp;
                    else
                        rlast = tmp;
                }
                else
                    llast = tmp;
            }
            else if(tmp > rlast)
                rlast = tmp;
            else
                flag = false;
        }
        if(flag)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}

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

int main()
{
    int N;
    scanf("%d",&N);
    for(int i=0;i<N;++N) {
        int ball[10],index=0;
        bool flag=true;
        for(int i=0;i<10;++i) {
            scanf("%d",&ball[i]);
        }
        while(index+2 <= 9) {
            if(ball[index] < ball[index+1]) {
                ++index;
                continue;
            } else if (ball[index] < ball[index+2]) {
                ++index;
                continue;
            } else {
                flag=false;
                break;
            }
        }
        if (flag) {
            puts("YES");
        } else {
            puts("NO");
        }
    }
    return 0;
}

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

int main(){
	int n;
	scanf("%d",&n);
	for(;n>0;n--){
		int a=0,b=0,c;
		bool t=true;
		for(int i=0;i<10;i++){
			scanf("%d",&c);
			if(c>b){ b=c; }
			else if(c>a){ a=c; }
			else { t=false; break; }
			if(a>b)swap(a,b);
		}
		if(t)printf("YES\n");
		else printf("NO\n");
	}
}