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<cmath>
#include<queue>
#include<iostream>
#include<algorithm>
#define debug(ARGS) cout << #ARGS << ": " << ARGS << endl;
#define ll long long
using namespace std;

bool dfs(queue<int> &v, int l, int r){
  if(v.size() == 0) return true;
  
  int ball = v.front(); v.pop();
    
  if(ball > l) return dfs(v, ball, r);
  if(ball > r) return dfs(v, l, ball);
  
  return false;
}

int main(){
  int n;
  int size = 10;    
  
  while(cin >> n){
    queue<int> v;
    for(int i = 0; i < size; i++){
      int tmp; cin >> tmp;
      v.push(tmp);
    }

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

  return 0;
}

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

int main(void){
	int c;
	cin >> c;
	for(int j = 0; j < c; j++){
		int data[10];
		for(int i = 0; i < 10; i++){
			cin >> data[i];
		}

		int B, C = 0;
		B = data[0];
		bool flag = 0;

		for(int i = 1; i < 10; i++){
			if(B+1 != data[i]){
				if(C == 0){
					C = data[i];
				}else if(C+1 != data[i]){
					cout << "NO" << endl;
					break;
				}else{
					C = data[i];
				}
			}else{
				B = data[i];
			}
			if(i == 9){cout << "YES" << endl;}
		}
	}

}

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(all(v),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int l=0,r=0,a,N;
  cin >> N;
  rep(i,N){
    bool f = true;
    rep(i,10){
      cin >> a;
      if(l <= r && r < a){
        r = a;
      }
      else if(r > l && l < a){
        l = a;
      }
      else{
        f = false;
        break;
      }
    }
    Ans(f);
  }
  return 0;
}

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

int Balls[10];

bool fork(int balls[], int i, int b, int c) {
  if (i == 10) return true;
  if (b > balls[i] && c > balls[i]) return false;
  if (b < balls[i]) fork(balls, i + 1, balls[i], c);
  if (c < balls[i]) fork(balls, i + 1, b, balls[i]);
}

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

C++: #include<bits/stdc++.h>
using namespace std;
int box[10];
int l[10],r[10];
void func(int nn);
int flg;
int main(void){
	int n;
	int i,j;
	cin>>n;
	for(i=0;i<n;i++){
		for(j=0;j<10;j++){
			cin>>box[j];
			l[i]=r[i]=0;
		}
		flg=0;
		func(0);
		cout<<((flg)?"YES":"NO")<<endl;
	}
	return 0;
}
void func(int nn){
	int i;
	int x;
	int flg1,flg2;
	if(nn>=10){
		flg1=flg2=0;
		x=0;
		for(i=0;i<10;i++){
			if(l[i]==1){
				if(x<box[i])	x=box[i];
				else{
					flg1=1;
					break;
				}
			}
		}
		x=0;
		for(i=0;i<10;i++){
			if(r[i]==1){
				if(x<box[i])	x=box[i];
				else{
					flg2=1;
					break;
				}
			}
		}
		if(flg1==0&&flg2==0)	flg=1;
	}
	else{
		l[nn]=1;
		func(nn+1);
		l[nn]=0;
		r[nn]=1;
		func(nn+1);
		r[nn]=0;
	}
}

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

int num[10];
int B[10];
int C[10];
bool flag;
void solve(int, int, int);

int main(void){
	int N;
	cin >> N;
	for(int k = 0; k < N; k++){
		flag = false;
		fill_n(B , 10, -1);
		fill_n(C , 10, -1);
		for(int i = 0; i < 10; i++){
			cin >> num[i];
		}
		solve(0, 0, 0);
		if(flag){cout << "YES" << endl; continue;}
		cout << "NO" << endl;
	}

	return 0;
}

void solve(int cnt,int right, int left){
	if(cnt == 10){
		flag = true;
		return;
	}
	if(num[cnt] > right) solve(cnt+1, num[cnt], left);
	if(num[cnt] > left) solve(cnt+1, right, num[cnt]);
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<vector>
using namespace std;
vector<int> st[2];
main(){

  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    int b[10];
    for(int j=0;j<10;j++){
      scanf("%d",&b[j]);
    }
    bool f=false;
    st[0].push_back(b[0]);
    for(int j=1;j<10;j++){
      if(st[0].back() < b[j] )
	st[0].push_back(b[j]);
      else if( st[1].empty() )
	st[1].push_back(b[j]);
      else if( st[1].back() < b[j] )
	st[1].push_back(b[j]);
      else {
	f=true;
	break;
      }
      //  printf("%d : %d  <- %d\n",st[0].back(),st[1].back(),b[j]);
    }    
    
    st[0].clear();
    st[1].clear();
    
    if(!f) printf("YES\n");
    else printf("NO\n");
  }
}

C++: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

const int MAX_N = 10;
int a[MAX_N];

bool dfs(int idx, int end1, int end2) {
    if (idx == MAX_N) return true;
    if (a[idx] < end1 && a[idx] < end2) return false;
    if (a[idx] > end1 && a[idx] > end2) return dfs(idx+1, a[idx], end2) || dfs(idx+1, end1, a[idx]);
    if (a[idx] > end1) return dfs(idx+1, a[idx], end2);
    if (a[idx] > end2) return dfs(idx+1, end1, a[idx]);
    return false;
}

int main() {
    int T;
    cin >> T;
    while (T--) {
        for (int i = 0; i < MAX_N; i++)
            cin >> a[i];
        bool flag = dfs(0, 0, 0);
        if (flag) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #include <stdio.h>

int main(){
int a,b,x;
int f,n,i,j;

scanf("%d",&n);
for(i=0;i<n;i++){
a=0;
b=0;
f=0;
for(j=0;j<10;j++){
scanf("%d",&x);
if(a<x){
a=x;
}
else if(a>x&&b<x){
b=x;
}
else{
a=x;
}
if(0<a&&0<b&&a<=x&&b<=x){
f=1;
}
}
if(f==0){
printf("YES\n");
}
else if(f==1){
printf("NO\n");
}
}

return 0;
}

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

int n;
int A[10];
bool dfs(int a,int b,int i){
	if(i==9) return a<A[i] || b<A[i];
	if(a<=A[i] && !(b<=A[i])) return dfs(A[i],b,i+1);
	else if(b<=A[i]) return dfs(a,A[i],i+1);
	else return false;
}
int main(){
	cin >> n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			cin >> A[j];
		}
		if(dfs(0,0,0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}