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++: //38
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int N;
  cin>>N;
  while(N--){
    int h=0,l=0;
    int i;
    for(i=0;i<10;i++){
      int n;
      cin>>n;
      if(h<n){
	h=n;
      }else if(l<n){
	l=n;
	if(h<l){
	  swap(h,l);
	}
      }else{
	break;
      }
    }
    cout<<((i<10)?"NO":"YES")<<endl;
  }
  return 0;
}

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

int main(){
int a;
int n,b=0,c=0;
cin>>n;
for(int i=0;i<n;i++){
for(int j=0;j<10;j++){
cin>>a;
if(a>b){b=a;}
if(a<b&&a>c){c=a;}
if(a<b&&a<c){
cout<<"NO"<<endl;
break;}
if(j==9){
cout<<"YES"<<endl;
break;}
}
}}

C++: #include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD
 
int main(){
  int n;
  cin>>n;
  while(n--){
    int left=-1,right=-1;
    bool flag = true;
    REP(i,10){
      int x;
      cin>>x;
      --x;
      if(left>right)swap(left,right);
      if(x>right){
        right = x;
      }else if(x>left){
        left = x;
      }else{
        flag = false;
        break;
      }
    }
    if(flag){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
  }
  return 0;
}

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

int main() {
    int n; 
    cin >> n;  // データセットの数
    while(n--){
        int balls[10] = {0};
        for(int i = 0; i < 10; i++) cin >> balls[i]; // 各データセットの入力

        bool isYES = true;  // 玉10個を振り分けられるかどうか
        int topB = 0, topC = 0;  // 筒B及び筒Cの最上部の玉の値
        for(int i = 0; i < 10; i++){
            if (topB < balls[i]){
                topB = balls[i];
            } else if (topC < balls[i]) {
                topC = balls[i];
            } else {
                isYES = false;
                break;
            }
        }
        cout << (isYES ? "YES" : "NO") << endl;
    }
}

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

int main() {
	int n;
	int d[10];
	int va[10];
	int vb[10];
	int trush;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> d[i];
		}

		int ca = 0, cb = 0;
		va[0] = d[0];
		ca++;
		if (d[1] > va[0]) {
			va[1] = d[1];
			ca++;
		}

		else {
			vb[0] = d[1];
			cb++;
		}

	for (int j = 2; j < 10; j++) {

			if (d[j] > va[ca-1]) {
				va[ca] = d[j];
				ca++;
			}

			else if (d[j] > vb[cb-1]) {
				vb[cb] = d[j];
				cb++;
			}

			else {
				cout << "NO" << endl;
				break;
			}

		}

	if(ca+cb==10)
		cout << "YES" << endl;

		for (int i = 0; i < 10; i++) {
			va[i] = 0;
		}
		for (int i = 0; i < 10; i++) {
			vb[i] = 0;
		}
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    while (n--) {
        int left = 0, right = 0;
        int i;
        for (i = 0; i < 10; i++) {
            int ball;
            cin >> ball;
            if (left > ball && right > ball) {
                cout << "NO" << endl;
                break;
            }
            if (left > ball)
                right = ball;
            else if (right > ball)
                left = ball;
            else if (left > right)
                left = ball;
            else
                right = ball;
        }
        if (i == 10)
            cout << "YES" << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
using namespace std;
int a[11];
int a1[11];
int pn=0;
int Flag;
void dfs(int i)
{
    if(Flag==1)
        return;

    if(a[i]>a[a1[pn]])
    {
        a1[++pn]=i;
        for(int m=i+1;m<=10;m++)
        {
            dfs(m);
        }
    }
    else
        return;
    int flag=0;
    for(int m=i+1;m<=10;m++)
    {
        if(a[m]>a[i])
            flag=1;
    }
    int flag2;
    if(flag==0||i==10)
    {
        int a2[11];
        int pm=0;
        for(int n=1;n<=10;n++)
        {
            flag2=0;
            for(int m=1;m<=pn;m++)
            {
                if(n==a1[m])
                   flag2=1;
            }
            if(!flag2)
            {
               a2[++pm]=n;
            }
        }
        int flag3=0;
        for(int m=1;m<pm;m++)
        {
            if(a[a2[m]]>a[a2[m+1]])
                flag3=1;
        }
        if(flag3==0)
        {
            Flag=1;
            return;
        }
        else
        {
            pn--;
            return;
        }
    }

}
int main()
{
    int n;
    //freopen("C:\\Users\\ibm\\Desktop\\456.txt","r",stdin);
    scanf("%d",&n);
    getchar();
    a[0]=-1;
    a1[0]=0;
    for(int i=1;i<=n;i++)
    {
        Flag=0;
        for(int j=1;j<=10;j++)
        {
            scanf("%d ",&a[j]);
        }
        dfs(1);
        if(Flag==0)
        {
            printf("NO\n");
        }
        else
            printf("YES\n");
    }
    return 0;
}

C++: #include "stdio.h"
#include "stdlib.h"
#include "iostream"
#include "math.h"
#include <string.h>


using namespace std;
#define fori0(G) for(int i=0;i<G;i++)
#define fori1(G) for(int i=1;i<=G;i++)
#define forj0(G) for(int j=0;j<G;j++)
#define forj1(G) for(int j=1;j<=G;j++)
#define fork0(G) for(int k=0;k<G;k++)
#define fork1(G) for(int k=1;k<=G;k++)



int main() {
	int n, ba[13],p=11,q=11,r=0;
	cin >> n;
	fork0(n) {
		p = 11;q = 11;r = 0;
		ba[11] = -1;

		fori0(10) { cin >> ba[i]; }
		fori0(1023) {
			p = 11;q = 11;
			forj0(10) {
				//printf("%d,%d", p, q);
				if (i&(int)pow(2, j)) { if (ba[p] > ba[j]) { break; } else { p = j; } }
				else { if (ba[q] > ba[j]) { break; } else { q = j; } }
				if (j == 9) { r = 1; }

			}
		}
		if (r) { printf("YES\n"); }
		else { printf("NO\n"); }
	}
	//system("pause");
	return 0;
}

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

int main() {
	int n;
	int a;
	vector<int>d;
	vector<int>va;
	vector<int>vb;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> a;
			d.push_back(a);
		}
		va.push_back(d[0]);		

		for (int j = 1; j < 10; j++) {
			int b = va.size();
			int c = vb.size();

			if (d[j] > va[b-1]) {
				va.push_back(d[j]);
			}
			else if (d[j] > vb[c-1]) {
				vb.push_back(d[j]);
			}
			else {
				cout << "NO" << endl; 
				goto FINLOOP;
			}
		}
		cout << "YES" << endl;
			FINLOOP:
		;
	}
	return 0;
}

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

using namespace std;

int ball[10];

bool dfs(int B, int C, int cnt){
    if(cnt == 10){
        return true;
    }
    if(B < ball[cnt]){
        return dfs(ball[cnt], C, cnt + 1);
    }
    if(C < ball[cnt]){
        return dfs(B, ball[cnt], cnt + 1);
    }
    if(B > ball[cnt] && C > ball[cnt]){
        return false;
    }
}

int main()
{
    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 10; j++)
            cin >> ball[i];

        if(dfs(0, 0, 0)) 
            cout << "YES" << endl;
        else 
            cout << "NO" << endl;
    }
}