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>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int const MOD = 1000000007;

int main() {
    int n; cin >> n;
    int x;
    rep(k,0,n) {
        int a = 0, b = 0;
        bool can = true;
        rep(i,0,10) {
            cin >> x;
            if(a < x && b < x){
                if(x - a > x - b) b = x;
                else a = x;
            }
            else if(a < x) a = x;
            else if(b < x) b = x;
            else {can = false;}
        }
        if(can) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

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){	//1?????????????????????????????§????????´???,current?????????1????????????????§????
				if(second_pre == -1){	//2?????????????????????????????¨?????????????????´???
					second_pre = current;
				}else{	//2???????????????????????¨??????????????´???
					if(second_pre > current){ //2????????????????????°??????current???????????§????????´???
						printf("NO\n");
						NO_FLG = true;
						break;
					}else{	//2????????????????????°??????current??????????°?????????´???
						second_pre = current;
					}
				}
			}else{ //pre < current
				pre = current;
			}
        }
        if(!NO_FLG)printf("YES\n");

    }
    return 0;
}

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

stack<int> B, C;
int A[10];

bool dfs(int index)
{
  bool ret = false;
  char s[11];

  if (index >= 10) {
    return true;
  }

  for (int i = 0; i < 11; i++) {
    if (i < index) s[i] = '>';
    else s[i] = 0;
  }

  if (B.empty() || B.top() < A[index]) {
    B.push(A[index]);
    // printf("%spush %d into B\n", s, A[index]);
    ret = dfs(index + 1);
    // printf("%s%s. pop %d from B\n", s, ret ? "succeeded" : "failed", A[index]);
    B.pop();
  }
  if (!ret && (C.empty() || C.top() < A[index])) {
    C.push(A[index]);
    // printf("%spush %d into C\n", s, A[index]);
    ret = dfs(index + 1);
    // printf("%s%s. pop %d from C\n", s, ret ? "succeeded" : "failed", A[index]);
    C.pop();
  }

  return ret;
}

bool solve()
{
  while (!B.empty()) B.pop();
  while (!C.empty()) C.pop();

  B.push(A[0]);
  bool ret = dfs(1);
  B.pop();

  return ret;
}

int main()
{
  int N;
  scor (int j = 0; j < 10; j++) {
      scanf("%d", A + j);
    }

    if (solve()) {
      printf("Yes\n");
    }
    else {
      printf("No\n");
    }
  }

  return 0;
}

C++: #include<iostream>
using namespace std;
int ball[10];
int flag;  //1??????YES???0??????NO
void dfs(int left,int right,int depth){
  if(depth==10){ //???????????????????????§??\???????????????
    flag=1;
    return;
  }
  if(left<ball[depth])
    dfs(ball[depth],right,depth+1);
  if(right<ball[depth])
    dfs(left,ball[depth],depth+1);
}

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    flag=0;//????????°????????????
    for(int j=0;j<10;j++)
      cin>>ball[j];
    dfs(ball[0],0,1);//????????????????????\??????????????????
                     //3??????????????°?????±???
                     //?????????????????\?????????????????\???????????????????????§
                     //????????\?????????????????????????????????
    if(flag)
      cout<<"YES"<<endl;
    else
      cout<<"NO"<<endl;
  }
  return 0;
}

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

int main() {
  int n; cin >> n;
  while (n--) {
    vector<int> a(10); for (int i = 0; i < 10; ++i) cin >> a[i];
    int sum = 0;
    for (int i = 1; i < 10; ++i) {
      sum += (a[i - 1] > a[i]);
    }
    cout << ( (sum < 3) ? "YES" : "NO" ) << endl;
  }
  return 0;
}

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

int main() {
	int a[10], n, j;
	vector<int> b, c;

	cin >> n;
	for (int i = 0; i < n; i++) {
		for (j = 0; j < 10; j++) {
			cin >> a[j];
		}
		for (j = 0; j < 11; j++) {
			if (j == 10) {
				break;
			}
			if (j == 0) {
				b.push_back(a[j]);
			}
			else if (a[j] - 1 != b[b.size() - 1] && c.size() == 0) {
				c.push_back(a[j]);
			}
			else if (a[j] - 1 == b[b.size() - 1]) {
				b.push_back(a[j]);
			}
			else if (a[j] - 1 == c[c.size() - 1]) {
				c.push_back(a[j]);
			}
			else {
				break;
			}
		}
		if (j == 10) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}

C++: /*
 * AOJ 0033: Ball
 * ?¢????????????????1-10???10???????????????????????????????????\2????????????????????????????????\??????????????????????¢????????????????????????¨???
 * ?±???????DFS
 * ?????????????????????????????\??§???????????¶???????´????????????\??°?????\????????¶??§????????????
 */

#include <cstdio>
#include <iostream>

using namespace std;

int a[10], b[2][10];
int len[2];
bool ans;


void dfs(int step) {
  if (ans) return;
  if (step == 10) {
    ans = true;
    return;
  }
  for (int i = 0; i < 2; ++i) {
    if (len[i] == 0 || a[step] > b[i][len[i] - 1]) {
      b[i][len[i]++] = a[step];
      dfs(step + 1);
      --len[i];
    }
  }
}

void solve() {
  ans = false;
  for (int i = 0; i < 10; ++i) {
    cin >> a[i];
  }
  dfs(0);
}

int main() {
  int T;
  cin >> T;
  while (T--) {
    solve();
    cout << (ans ? "YES" : "NO") << endl;
  }
  return 1;
}

C++: #include<iostream>
#include<cstring>
#include<stack>
using namespace std;
int a[15],t;
int map[2][15];
stack<int>s[2];
void dfs(int g){
	if(g==10){
		t=1;
		return;
	}
	if(t==1)
	return;
	for(int i=0;i<2;i++){
		if(s[i].size()==0||s[i].top()<a[g]){
			s[i].push(a[g]);
			dfs(g+1);
			s[i].pop();
		}
	}
}
int main(){
	int loop;
	cin>>loop;
	while(loop--){
		for(int i=0;i<10;i++)
		cin>>a[i];
		t=0;
		for(int i=0;i<2;i++)
		while(!s[i].empty())
		s[i].pop();
		dfs(0);
		for(int i=0;i<2;i++)
		while(!s[i].empty())
		s[i].pop();
		if(t==1)
		cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}