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 main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int a[20], b[20], c[20];
		for(int j = 0; j < 10; j++){
			cin >> a[j]; 
		}

		int ai = 0, bi = 0, ci = 0;
		b[0] = 0;
		c[0] = 0;
		while(ai < 9){
			if(b[bi] > c[ci]){
				if(a[ai] > b[bi]){
					bi++;
					b[bi] = a[ai];
					ai++;
				}else if(a[ai] > c[ci]){
					ci++;
					c[ci] = a[ai];
					ai++;
				}else{
					break;
				}
			}else{
				if(a[ai] > c[ci]){
					ci++;
					c[ci] = a[ai];
					ai++;
				}else if(a[ai] > b[bi]){
					bi++;
					b[bi] = a[ai];
					ai++;
				}else{
					break;
				}
			}
		}

		if(ai == 9){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}

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

using namespace std;

int N;
int A_bottle[10];

stack<int> B_bottle,C_bottle;

bool dfs(int i){
	//A????????????i???????????°?????????????????????
	if (i==10){
		//?????????????????????????????????????????????
		return true;
	}
	bool flg=false;

	if (B_bottle.empty() || B_bottle.top()<A_bottle[i]){
		//B????????????????????????
		B_bottle.push(A_bottle[i]);
		flg=dfs(i+1);
		B_bottle.pop();
		if (flg) return true;
	}
	if (C_bottle.empty() || C_bottle.top()<A_bottle[i]){
		//C????????????????????????
		C_bottle.push(A_bottle[i]);
		flg=dfs(i+1);
		C_bottle.pop();
		if (flg) return true;
	}
	return false;
}

int main(){
	vector<bool> out;
	cin>>N;
	for (int i=0;i<N;i++){
		for (int j=0;j<10;j++){
			cin>>A_bottle[j];
		}
		out.push_back(dfs(0));
	}
	for (vector<bool>::iterator ite=out.begin();ite!=out.end();ite++){
		cout<<(*ite ? "YES" : "NO")<<endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

bool judge(int num){
	int i, n, q[2]={0,0};

	for (i=0; i<num; i++) {
		cin >> n;
		if (q[0]<n)
			q[0] = n;
		else if (q[1]<n)
			q[1] = n;
		else
			break;
	}

	if (i==num)
		return true;
	else
		return false;
}

int main(){
	int i, lines;

	cin >> lines;
	for (i=0; i<lines; i++) {
		if (judge(10))
			cout << "NO\n";
		else
			cout << "YES\n";
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
using namespace std;

int ball[10];

stack<int> b;
stack<int> c;

bool routine(int dep){
	if(dep == 10){
		return true;
	}
	bool bcheck;
	//b?????\??????
	if(b.size() == 0){
		b.push(ball[dep]);
		bcheck = routine(dep+1);
	}else{
		if(b.top() < ball[dep]){
			b.push(ball[dep]);
			bcheck = routine(dep+1);
		}else{
			bcheck = false;
		}
	}
	bool ccheck;
	if(c.size() == 0){
		c.push(ball[dep]);
		ccheck = routine(dep+1);
	}else{
		if(c.top() < ball[dep]){
			c.push(ball[dep]);
			ccheck = routine(dep+1);
		}else{
			ccheck = false;
		}
	}
	return (bcheck || ccheck);
}

void solve(){
	for(int i = 0; i < 10; i++){
		scanf("%d", &ball[i]);
	}
	printf(routine(0) ? "YES\n" : "NO\n");
}

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		solve();
	}
	return 0;
}

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

int main(){
	int n;

	cin >> n;

	int* a = new int[ n * 10 ];

	for ( int i = 0; i < n; ++i ){
		cin >> a[ i*10 + 0 ] >> a[ i*10 + 1 ] >> a[ i*10 + 2 ] >> a[ i*10 + 3 ] >> a[ i*10 + 4 ]
			>> a[ i*10 + 5 ] >> a[ i*10 + 6 ] >> a[ i*10 + 7 ] >> a[ i*10 + 8 ] >> a[ i*10 + 9 ];
	}

	for ( int i = 0; i < n; ++i ){
		int right = 0, left = 0;
		for ( int j = 0; j < 10; ++j ){
			int pick = a[ i*10 + j ];
			if ( pick < right && pick < left ){
				cout << "NO" << endl;
				break;
			}else if ( pick > right && pick < left ){
				right = pick;
			}else if ( pick < right && pick > left ){
				left = pick;
			}else if ( right > left ){
				right = pick;
			}else{
				left = pick;
			}
			if ( j == 9 ){
				cout << "YES" << endl;
			}
		}
	}

	delete[] a;

	return 0;
}

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

using namespace std;

int main(){
  int f;
  int n;
  int in,b,c;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    f=b=c=0;
    for(int j=0;j<10;j++){
      scanf("%d",&in);
      if(in<=min(b,c)){
	f=1;
	break;
      }
      if((b>=c && b<in)||(c>=b && c>in))b=in;
      else c=in;
    }
    if(f)printf("NO\n");
    else printf("YES\n");
  }
}

C++: #include <iostream>
#include <algorithm>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); ++i)

int ball[10], lb[10], rb[10];

bool dfs(int n, int l, int r) {
    if(n==10) {
        rep(i, l-1) if(lb[i] > lb[i+1]) return false;
        rep(i, r-1) if(rb[i] > rb[i+1]) return false;
        return true;
    }
    lb[l] = ball[n];
    bool hoge = dfs(n+1, l+1, r);
    rb[r] = ball[n];
    bool fuga = dfs(n+1, l, r+1);
    if(hoge || fuga) return true;
    else return false;
}

int main(void){
    int N;
    cin >> N;
    rep(loop, N) {
        rep(i, 10) cin >> ball[i];
        if(dfs(0, 0, 0)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int n;
    cin>>n;
    while(n--){
        int ball[15]={0};
        int A=0,B=0;
        int x=0,y=0;
        bool flg=0;
        for(int i=0;i<10;i++){
            cin>>ball[i];
        }
        for(int i=0;i<10;i++){
            if(x<ball[i])x=ball[i];
            else if(y<ball[i])y=ball[i];
            else{
                cout<<"NO"<<endl;
                flg=1;
                break;
            }
        }
        if(flg==0)cout<<"YES"<<endl;
    }
    return 0;
}

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

C++: #include<iostream>
#include<stack>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;
int main(){
  int n;
  cin >> n;
  int a[n][10];
  REP(i,n){
    REP(j,10){
      int b;
      cin >> b;
      a[i][j] = b;
    }
  }
  int flag[n] = {0};
  REP(i,n){
    stack <int> b;
    stack <int> c;
    b.push(a[i][0]);
    for(int j = 1;j < 10;j++){
      if(b.top() < a[i][j]){
	b.push(a[i][j]);
      }
      else{
	if(c.empty()){
	  c.push(a[i][j]);
	}
	else if(c.top() < a[i][j]){
	  c.push(a[i][j]);
	}
	else{
	  flag[i] = 1;
	}
      }
    }
  }

  REP(i,n){
    if(flag[i] == 1){
      cout << "NO" << endl;
    }
    else{
      cout << "YES" << endl;
    }
  }

}