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 <bits/stdc++.h>

#define SIZE 300005
#define MOD 1000000007LL
#define INF INT_MAX / 3
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef valarray<int> Array;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i];if(i==a.size()-1)cout<<endl;else cout<<" ";}}
int gcd(int a,int b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
int lcm(int a,int b){return a==0||b==0?0:a*b/gcd(a,b);}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  REP(v,n)
  {
    vector<int> a, b;
    int m = 0;
    REP(i,10)
    {
      int t; cin >> t;
      if(t > m)
      {
        m = t;
        a.push_back(t);
      }
      else b.push_back(t);
    }
    int i = 0;
    while(i<b.size()-1)
    {
      if(b[i] > b[++i])
      {
        printf("NO\n");
        break;
      }
    }
    if(i==b.size()-1) printf("YES\n");
  }
  return 0;
}

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

int ball[MAX_BALL];
int n;
int r = 0, l = 0;

bool dfs(int x,bool d)//1 is right, 0 is left
{
	if (x == MAX_BALL)
		return true;
	if (d)
		r = ball[x];
	else
		l = ball[x];
	if (ball[x + 1] >= r)
		return dfs(x + 1, 1);
	if (ball[x + 1] >= l)
		return dfs(x + 1, 0);
	return false;
}

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

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

const int M=15;
int s[M];
int f;
void dfs(int step,int na,int nb)
{
    if(f)
        return;
    if(step==11)
    {
        f=1;
        return;
    }
    if(na<s[step-1])
        dfs(step+1,s[step-1],nb);
    if(nb<s[step-1])
        dfs(step+1,na,s[step-1]);
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        for(int i=0;i<10;i++)
            scanf("%d",&s[i]);
        f=0;
        dfs(1,-1,-1);
        printf("%s\n",f?"YES":"NO");
    }
    return 0;
}

C++: // ?????¬???????????¬?????? (define int long long ?????????)

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#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 <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

bool ans;
int a[10];
void dfs(int idx, int l, int r) {
    if(idx == 10) {
        ans = true;
        return;
    }

    int val = a[idx];
    if(l < val) dfs(idx+1, val, r);
    if(r < val) dfs(idx+1, l, val);
}

int main() {
    int N; cin >> N;
    while(N--) {
        ans = false;
        rep(i,0,10) cin >> a[i];
        dfs(0, -1, -1);
        cout << (ans ? "YES" : "NO") << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <vector>
using namespace std;
int A[10];
vector<int> B, C;
int N;

void solve() {
  B.clear();
  C.clear();
  for (int i = 0; i < 10; i++) {
    int k = A[i];
    if (B.empty()) {
      B.push_back(k);
      continue;
    }
    if (C.empty()) {
      C.push_back(k);
      continue;
    }
    int m = max(k - B.back(), k - C.back());
    if (m < 0) {
      printf("NO\n");
      return;
    }
    if (m == k - B.back())
      C.push_back(k);
    else
      B.push_back(k);
  }
  printf("YES\n");
}

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

C++: #include<stdio.h>
#include<malloc.h>

bool decide(int *b){
	int first = 10000;
	int i;
	for( i = 0; i < 9; i++){
		if(b[i+1] < b[i])first = b[i+1];
		break;
	}
	for(i; i < 9; i++)
		if(b[i+1] < first)return false;

	return true;
}

int main(){
	int N;
	scanf("%d",&N);
	int (*a)[10];
	a = (int (*)[10])malloc(N*10*sizeof(int));
	for(int i = 0; i < N; i++)
		for(int j = 0; j < 10; j++)
			scanf("%d",&a[i][j]);

	for(int k = 0; k < N; k++){
		int *b = a[k];
		if(decide(b) == false)printf("NO\n");
		else printf("YES\n");
		}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
void check(int x);
bool ans=false;
int a[12]={0};
int b=0,c=0,sub;
int main(void){

	int n;
	cin>>n;
	for(int q=0;q<n;q++){
	    for(int i=0;i<12;i++){
        a[i]=0;
        }
        ans=false;

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


	check(0);
	if(ans==true)cout<<"YES"<<endl;
	else if(ans==false)cout<<"NO"<<endl;


	}
	return 0;
}
void check(int x){
    if(x==10){
        ans=true;
        return;
    }

    if(a[x]>b&&a[x]>c){
        sub=b;
        b=a[x];
        //cout<<x<<'('<<b<<'.'<<c<<')'<<endl;
        check(x+1);
        b=sub;

        sub=c;
        c=a[x];
        //cout<<x<<'('<<b<<'.'<<c<<')'<<endl;
        check(x+1);
        c=sub;
    }
    else if(a[x]>b){
        sub=b;
        b=a[x];
        //cout<<x<<'('<<b<<'.'<<c<<')'<<endl;
        check(x+1);
        b=sub;

    }
    else if(a[x]>c){
        sub=c;
        c=a[x];
        //cout<<x<<'('<<b<<'.'<<c<<')'<<endl;
        check(x+1);
        c=sub;

    }
    else {

        return;
    }

}

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

using namespace std;

int main() {
	int A[10];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++)
			cin >> A[j];
		stack<int> B, C;
		string ans = "YES";
		for (int j = 0; j < 10; j++) {
			if (j == 0)
				B.push(A[j]);
			else if (A[j] > B.top())
				B.push(A[j]);
			else if (A[j] < B.top()) {
				if (C.empty())
					C.push(A[j]);
				else if (A[j] < C.top())
					ans = "NO";
				else
					C.push(A[j]);
			}
		}
		cout << ans << endl;
	}
	return 0;
}