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>
using namespace std;

int main(){
    int i,j,k,fl;
    int a[10],b[10]={0};
    int ball[10];
    cin >> k;
    for(int g=0;g<k;g++){
        fl=0;
        for(int n=0;n<10;n++) cin >> ball[n];
        i=1;
        j=0;
        a[0] = ball[0];
        for(int n=1;n<10;n++){
            if(ball[n] < a[i] && ball[n] < b[j]){
                cout << "NO" << endl;
                fl = 0;
                break;
            }
            else if((ball[n] - a[i] > ball[i] - b[j]) && ball[n] > b[j]){
                b[j] = ball[n];
                j++;
                fl = 1;
            }
            else if((ball[n] - a[i] < ball[i] - b[j]) && ball[n] > a[i]){
                a[i] = ball[n];
                i++;
                fl = 1;
            }
        }
        if(fl == 1) cout << "YES" << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,a;
  int b = 11,c = 11;
  cin >> n;
  while(n--){
    for(int i = 0;i < 10;i++){
      cin >> a;
      if(b > a)b = a;
      else if(c > a)c = a;
      else {
	cout << "NO" << endl;
	return 0;
      }  
    }
    cout << "YES" << endl;
  }
  return 0;
}

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

int balls[20];
int R, L;

bool dfs(int n) {
  if (n == 10) {
    return true;
  }
  if (R < balls[n]) {
    R = balls[n];
    if (dfs(n+1)) {
      return true;
    }
  }
  if (L < balls[n]) {
    L = balls[n];
    if (dfs(n+1)) {
      return true;
    }
  }
  return false;
}

int main(void) {
  int N;
  cin >> N;
  while (N--) {
    for (int i = 0; i < 10; i++) {
      cin >> balls[i];
    }
    R = balls[0];

    if (dfs(1)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }

  return 0;
}

C++: #include <cstdio>
int T,a[10];
void solve(){
    for(int i=0;i<(1<<10);i++){
        int pre1=0,pre2=0,flag=1;
        for(int j=0;j<10;j++){
            if((1<<j)&i){
                if(a[j]<pre1){flag=0;break;}
                pre1=a[j];
            }else{
                if(a[j]<pre2){flag=0;break;}
                pre2=a[j];
            }
        }if(flag){puts("YES");return;}
    }puts("NO"); return;
}
int main(){
    scanf("%d",&T);
    while(T--){
        for(int i=0;i<10;i++)scanf("%d",a+i);
        solve();
    }return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

bool dfs(vector<int>::iterator iter, vector<int>::iterator end, int left, int right) {
  if(iter == end) return true;
  bool res = false;
  if(*iter > left) res |= dfs(iter + 1, end, *iter, right);
  if(*iter > right) res |= dfs(iter + 1, end, left, *iter);
  return res;
}

bool solve() {
  vector<int> a(10);
  for(int i = 0;i < 10;i++) cin >> a[i];
  return dfs(begin(a), end(a), 0, 0);
}

int main() {
  int t;
  cin >> t;
  for(int i = 0;i < t;i++) {
    if(solve()) {
      cout << "YES" << endl;
    }
    else {
      cout << "NO" << endl;
    }
  }
}

C++: int a[10];

bool dfs(int k, int B, int C){
    if(k == 10) return true;
    if(a[k] > B){
        if(dfs(k + 1, a[k], C))
            return true;
    }
    if(a[k] > C){
        if(dfs(k + 1, B, a[k]))
            return true;
    }
    return false;
}

void solve(){
    if(dfs(0, 0, 0))
        printf("YES\n");
    else
        printf("NO\n");
}

int main(int argc, char const *argv[]){

    int t;
    scanf("%d", &t);
    while(t --){
        for(int i = 0; i < 10; i ++)
            scanf("%d", &a[i]);
        solve();
    }

    return 0;
}

C++: #include<cstdio>
#include<cstring>
int t;
int a[15];

int main()
{
    scanf("%d",&t);
    while(t--)
    {
        int i;
        int z[15],y[15];
        memset(z,0,sizeof(z));
        memset(y,0,sizeof(y));
        for( i=0;i<10;i++)
            scanf("%d",&a[i]);

            z[0]=a[0];int f=1;
            int t=0;int tt=0;
            for(int i=1;i<10;i++)
            {
                if(a[i]>z[t])
                {
                    z[++t]=a[i];
                    f++;
                }
                else if(a[i]>y[tt-1])
                    {
                        y[tt++]=a[i];
                        f++;
                    }
            }
            printf("%d!",f);
        if(f==10)printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int func(int a,int b,int c);
int ball[10];

int main(){
  int n;
  cin >> n;
  while(n--){
    for(int i=0;i<10;i++) cin >> ball[i];
    if(func(0,0,0) != 0) cout << "YES\n";
    else cout << "NO\n";
  }
}
int func(int a,int b,int c){
  int ans=0;
  if(a == 10) return 1;
  if(ball[a]>b) ans += func(a+1,ball[a],c);
  if(ball[a]>c) ans += func(a+1,b,ball[a]);
  return ans;
}

C++: #include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
    int N,pre,current,second_pre;
    bool NO_FLG;

    scanf("%d",&N);
    for(int i=0;i<N;i++){
        pre = -1;
        second_pre = -1;
        NO_FLG = false;
        for(int k = 0; k < 10; k++){
            scanf("%d",&current);
            if(pre > current){
				if(second_pre == -1){
					second_pre = current;
				}else{
					if(second_pre > current){
						NO_FLG = true;
						//break;
					}else{
						second_pre = current;
					}
				}
			}else{
				pre = current;
			}
        }
        if(NO_FLG==false){
        	printf("YES\n");
        }else{
        	printf("NO\n");
        }
    }
    return 0;
}

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];
    int b = data[0],c = data[1];
    for ( int i = 2; i < 10; i++ ) {
      if ( b < data[i] ) b = data[i];
      else if ( c < data[i] ) c = data[i];
      else flag = 0;
    }
    if ( flag ) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <queue>
#define INF 10000000
using namespace std;
typedef pair<int,int> P;

int n;
int ba[10];

bool all(int,int,int);

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

bool all(int end,int l,int r){
  if(end==10){
    return true;
  }else if(ba[end]>l){
    return all(end+1,ba[end],r);
  }else if(ba[end]>r){
    return all(end+1,l,ba[end]);
  }
  return false;
}

C++: #include <iostream>
#include <vector>
using namespace std;
bool separate(int* A, int i, vector<int>& vB, vector<int>& vC)
{
	if (i == 10)
		return true;
	
	{
		vector<int> vTmpB(vB);
		if (vTmpB.empty() || (!vTmpB.empty() && (vTmpB.back() < A[i]))){
			vTmpB.push_back(A[i]);
			if (separate(A, i + 1, vTmpB, vC))
				return true;
		}
	}

	{
		vector<int> vTmpC(vC);
		if (vTmpC.empty() || (!vTmpC.empty() && (vTmpC.back() < A[i]))){
			vTmpC.push_back(A[i]);
			if (separate(A, i + 1, vB, vTmpC))
				return true;
		}
	}

	return false;
}
int main()
{
	int n;
	cin >> n;
	int A[10] = {};
	while(n--){
		for (int j = 0; j < 10; ++j)
			cin >> A[j];
		vector<int> vB, vC;
		if (separate(A, 0, vB, vC)) cout << "YES\n";
		else cout << "NO\n";
	}
	return 0;
}