Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var num int
	fmt.Scan(&num)

	for i := 0; i < num; i++ {
		sc.Scan()
		line := sc.Text()

		insertCheck(line)
	}
}

func insertCheck(line string) {
	var B, C []int

	for _, v := range strings.Split(line, " ") {
		ball, _ := strconv.Atoi(v)
		switch {
		case len(B) == 0:
			B = append(B, ball)
		case B[len(B)-1] < ball:
			B = append(B, ball)
		case B[len(B)-1] >= ball:
			switch {
			case len(C) == 0:
				C = append(C, ball)
			case C[len(C)-1] < ball:
				C = append(C, ball)
			case C[len(C)-1] >= ball:
				fmt.Println("NO")
				return
			}
		}
	}
	fmt.Println("YES")
}

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

int balls[10];
bool drop(int pos, int left, int right) {
    if (pos == 10) return true;
    return balls[pos] > left && drop(pos+1, balls[pos], right) || balls[pos] > right && drop(pos+1, left, balls[pos]);
}

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

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		int a[9]={};
		int b[9]={};
		int dat[9],o=0,s=0,f;
		for(int k=0;k<10;k++){
			cin>>f;
			dat[k]=f;
		}
		for(int j=0;j<=10;j++){
			if(j==10){
				cout<<"YES"<<endl;
				break;
						}					if(s==0 || dat[j]>a[s-1]){
				a[s]=dat[j];
				s++;
			}
			else if(o==0 || dat[j]>b[o-1]){
				b[o]=dat[j];
				o++;}
			else{
				cout<<"NO"<<endl;
			break;
			}
					}
	}
	return 0;
}

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

using namespace std;

int a[10];
int l[10],r[10],bl[10],br[10];
int main()
{
	int T;cin >> T;
	while(T--)
	{
		for(int i = 0;i < 10;++i)
			cin >> a[i];
		int flag = 0;
		for(int op = 0;op < 1 << 10;++op)
		{
			int lcnt = 0,rcnt = 0;
			for(int i = 0;i < 10;++i)
			{
				if(op >> i & 1)
					l[lcnt++] = a[i];
				else
					r[rcnt++] = a[i];
			}
			bool ok = 1;
			for(int i = 1;i < lcnt && ok;++i)
			{
				if(l[i] < l[i-1])
					ok = 0;
			}
			for(int i = 1;i < rcnt && ok;++i)
				if(r[i] < r[i-1])
					ok = 0;
			if(ok)
			{
				flag = 1;
				cout << "YES\n";
				break;
			}
		}
		if(!flag)
			cout << "NO\n";
	}
	return 0;
}

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;
				goto FINLOOP;
			}

		}

	cout << "YES" << endl;
	FINLOOP:
		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, count;
  int ball_list[10];
  int max_val;

  cin >> n;

  for(int i = 0; i < n; i++){
    for(int j = 0; j < 10; j++){
      cin >> ball_list[j];
    }

    for(int j = 0; j < 10; j++){
      count = 0;
      max_val = ball_list[j];
      for(int k = j; k >= 0; k--){
        if(max_val < ball_list[k]){
          max_val = ball_list[k];
          count++;
        }
      }

      if(count >= 2){
        cout << "NO" << endl;
        break;
      }else if(j == 9){
        cout << "YES" << endl;
      }
    }
  }

  return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n,a[10],b,c;
	cin >> n;
	rep(kk, n){
		rep(i, 10)
			cin >> a[i];
			b = c = 0;
		rep(i, 10){
			if (a[i] > b && b >= c){ b = a[i];}
			else if (a[i] > c){ c = a[i]; }
			else { cout << "NO" << endl; break; }
			if (i == 9){ cout << "YES" << endl; break; }
		}
	}
}

C++: #include<stdio.h>
#include<stack>
using namespace std;
stack<int>ss;
stack<int>ss2;
int main()
{
	int t,n,a;
	scanf("%d",&t);
	while (t--)
	{
		n=10;
		int f=0;
		while(n--)
		{
			scanf("%d",&a);
			if (ss.empty())
			{
				ss.push(a);
			}
			else if (ss.top()<a)
			{
				ss.push(a);
			}
			else if (ss2.empty())
			{
				ss2.push(a);
			}
			else if (ss2.top()<a)
			{
				ss2.push(a);
			}
			else
			{
				f=1;
				break; 
			}
		}
		if (f==1)
		{
			printf("NO\n");
		}
		else
		{
			printf("YES\n");
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int N;
  cin >> N;
  for(int z=0; z<N; z++){
    vector<int> v(10);
    for(int i=0; i<10; i++) cin >> v[i];
    int m,n;
    if(v[0] < v[1]) m = v[0], n = v[1];
    else m = v[1], n = v[0];
    int i;
    for(i=2; i<10; i++){
      if(v[i] < m) break;
      else if(v[i] < n) m = v[i];
      else n = v[i];
    }
    if(i >= 10) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  int a[10];
  int b[11];
  int c[11];
  int k=0;
  int k2=0;
  int out=0;
  cin>>n;
  b[0]=0;
  c[0]=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>a[j];
      if(b[k]<a[j] ){
	b[k+1]=a[j];
	k++;
      }
      else if(c[k2]<a[j]){
	c[k2+1]=a[j];
	k2++;
      }
      else{
	out=1;
	break;
      }
    }
    if(out==0) cout << "YES" << endl;    
    else if(out==1) cout << "NO" <<endl;
  }
}

C++: #include <iostream>
#define _for(i,a,b) for(int i = (a); i < b; ++i)
#define _rep(i,a,b) for(int i = (a); i <= b; ++i)
using namespace std;
int a[10+2];
bool flag = 0;
void dfs(int i, int l, int r){
    if(flag) return;
    if(i == 10) {
        flag = 1;
        return;
    }
    if(a[i] > l) dfs(i+1, a[i], r);
    if(a[i] > r) dfs(i+1, l, a[i]);
}
int main(){
    int n;
    cin>>n;
    _for(len,0,n){
        _for(i,0,10) cin>>n;
        dfs(0,0,0);
        if(flag) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        flag = 0;
    }
    return 0;
}

C++: #include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
#include <math.h>
#include <sstream>
using namespace std;
int ball[10];
bool dfs(int i,int b,int c);
int main(void){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int s=0;s<10;s++){
            cin>>ball[s];
        }
        if(dfs(0,0,0))cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}
bool dfs(int i,int b,int c){
    if(i==9)return true;
    if(b<ball[i]){
        if(dfs(i+1,ball[i],c))return true;
    }
    if(c<ball[i]){
        if(dfs(i+1,b,ball[i]))return true;
    }
    return false;
}

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

using namespace std;

int N;
int l[15];
int b,c;
//int res[1000000000000];


void solve(int k){
  for(int i=0;i<10;i++){
    if(b<l[i] && c<l[i]){
      if(l[i]-b < l[i]-c) b=l[i];
      else c=l[i];
    }
    else if(b<l[i] && c>l[i]) b=l[i];
    else if(b>l[i] && c<l[i]) c=l[i];
    else{
  //    res[k]=0;
      printf("NO");
      return;
    }
  }
  printf("YES");
  return;
}


int main(){
  scanf("%d",&N);

  for(int i=0;i<N;i++){
    b=0;
    c=0;
    scanf("%d%d%d%d%d%d%d%d%d%d",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9]);
    solve(i);
  }

  /*for(int i=0;i<N;i++){
    if(res[i]==0) printf("NO\n");
    else printf("YES\n");
  }
*/

  return 0;
}