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>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

const int n = 10;
int t;
int a, b, c;

int main()
{
  cin >> t;

  while(t--){
    bool ok = true;
    b = c = 0;
    rep(i, n){
      cin >> a;
      if(b > c) swap(b, c);
      if(a > c){ c = a;  continue; }
      if(a > b){ b = a;  continue; }
      ok = false;
      //break;
    }
    puts(ok ? "YES" : "NO");
  }

  return 0;
}

C++: a[10];
int dfs(int l,int r,int i){
  if(i>9)return 1;
  if(a[i]>l&&dfs(a[i],r,i+1))return 1;
  if(a[i]>r&&dfs(l,a[i],i+1))return 1;
  return 0;
}
main(n){
  scanf("%d",&n);
  for(;n;n--)
    scanf("%d%d%d%d%d%d%d%d%d%d",a+0,a+1,a+2,a+3,a+4,a+5,a+6,a+7,a+8,a+9),dfs(0,0,0)?puts("YES"):puts("NO");
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(void)
{
int n;
cin>>n;

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 b=0,c=0,k;
		for(k=1;k<10;k++)
		{
			if(b<a[k])b=a[k];
			else if(c<a[k])c=a[k];
			else 
			{
			cout<<"NO"<<endl;
			break;
			}
		}
		if(k==10)cout<<"YES"<<endl;

}
return 0;
}

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

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;
int N;
vector<int>a;
int dfs(int n, int b, int c){
  if(n == 10) return 1;
  if(b < a[n] && dfs(n+1, a[n], c)) return 1;
  if(c < a[n] && dfs(n+1, b, a[n])) return 1;
}
int main(){
  scanf("%d", &N);
  rep(i, N){
    a.clear();
    int b;
    rep(i, 10){
      scanf("%d", &b);
      a.PB(b);
    }
    printf("%s\n", dfs(0, 0, 0)?"YES":"NO");
  }
}

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

int main(void)
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		queue <int> a;
		int tmp, b = 0, c = 0;
		for (int i = 0; i < 10; i++){
			scanf("%d", &tmp);
			a.push(tmp);
		}
		
		while (1){
			tmp = a.front();
			if (b < tmp) {
				b = tmp;
				a.pop();
			}
			else if (c < tmp) {
				c = tmp;
				a.pop();
			}
			else break;
		}
		
		if (a.empty()) puts("YES");
		else puts("NO");
	}
	
	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");
      return;
    }
    if (m == k - B.back())
      C.push_back(k);
    else
      B.push_back(k);
  }
  printf("YES");
}

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

C++: #include<iostream>
main(){int n,i,A,B,C,f;for(std::cin>>n;n-->0;puts(f?"NO":"YES"))for(B=C=f=i=0;std::cin>>A,i++<10;)if(B<A)B=A;else C<A?C=A:f=1;}

C++: using namespace std;

#include <cstdio>

int a[10];

bool dfs(int i, int l, int r){
	if (i == 10){
		return true;
	}
	if (l < a[i] && dfs(i + 1, a[i], r)){
		return true;
	}
	if (r < a[i] && dfs(i + 1, l, a[i])){
		return true;
	}
	return false;
}

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

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

using namespace std;



void solve(vector<int> left, vector<int> right, vector<int> all, int n) {
	bool flag = true;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else
							flag = false;
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}	 	
		if (flag)
			printf("YES\n");
		else
			printf("NO\n");
		flag = true;
	}
}

int main() {		
	vector<int> left;
	vector<int> right;
	vector<int> all;


	int n;
	scanf_s("%d", &n);
	if (n <= 0) return -1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}	  

	solve(left, right, all, n);

	return 0;
}

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

bool isSortable(int min_b, int min_c, int *l)
{
    int first;
    bool res1, res2;

    first  = l[0];
    if (first == 0) return true;
    l++;
    // case1 firstをBに入れた場合
    if(first < min_b) {  // firstがmin_bより小さいときはfalse
        res1 = false;
    } else {             // firstはmin_bより大きい
        res1 = isSortable(first, min_c, l);
    }
    // case2 firstをCに入れた場合
    if(first < min_c) {
        res2 = false;
    } else {
        res2 = isSortable(min_b, first, l);
    }

    return (res1 || res2);
}

int main(void)
{
    int n, i, a[11];

    cin >> n;

    for(; n > 0 ; n--) {
        for(i = 0 ; i < 10 ; i++) {
            cin >> a[i];
        }
        a[10] = 0;
        if (isSortable(0, 0, a)) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }

    return 0;
}