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<vector>
#include<string>
#include<cstdlib>
#include<sstream>
#include<queue>
#include<deque>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

bool dfs(int depth,vi ball,stack<int> B,stack<int> C){
	if (depth == 10){
		return true;
	}
	bool ret,retB,retC;
	int A = ball[depth];
	
	if (B.top() < A){
		B.push(A);
		retB = dfs(depth + 1,ball,B,C);
		B.pop();
	}else{
		retB = false;
	}
	if (C.top() < A){
		C.push(A);
		retC = dfs(depth + 1,ball,B,C);
		C.pop();
	}else{
		retC = false;
	}

	if (retB or retC){
		ret = true;
	}else{
		ret = false;
	}

	return ret;

}

int main() {
	
	int n; cin >> n;

	for (int i = 0; i < n; i++){
		vi ball(10);
		stack<int> B,C;
		B.push(-1);
		C.push(-1);
		int num;
		for (int j = 0; j < 10; j++){
			cin >> ball[j];
		}

		if (dfs(0,ball,B,C)){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}

C++: #include <stdio.h>

int main(void) {

  int n;

  int A[10],B[10],C[10];
  int a;
  int b_idx,c_idx;

  int flag;
  int i,j;


  scanf("%d",&n);

  for(i=0;i<n;i++) {

    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]);

    for(j=0;j<10;j++) B[j]=C[j]=0;

    flag=1;

    b_idx=c_idx=0;

    for(j=0;j<10;j++) {

      a=A[j];

      if(b_idx==0) {

	B[b_idx]=a;
	b_idx++;

      } else {

	if(B[b_idx-1]>a) {

	  if(C[c_idx-1]>a) {

	    printf("NO\n");
	    flag=0;

	    break;

	  } else {

	    C[c_idx]=a;
	    c_idx++;

	  }

	} else {

	  if(C[c_idx-1]>a) {

	    B[b_idx]=a;
	    b_idx++;

	  } else {

	    if((a-B[b_idx-1])<(a-C[c_idx-1])) {

	      B[b_idx]=a;
	      b_idx++;

	    } else {

	      C[c_idx]=a;
	      c_idx++;

	    }

	  }

	}

      }

    }

    if(flag==1) printf("YES\n");

  }
  
  return 0;

}

C++: #include <iostream>

using namespace std;

int main(void) {
    int N, a, b, c;
    cin >> N;
    for (; N--; ) {
        b = c = 0;
        bool ok = true;
        for (int i = 0; i < 10; i++) {
            cin >> a;
            if (a > b) {
                b = a;
            } else if (a > c) {
                c = a;
            } else {
                ok = false;
                break;
            }
        }
        if (ok) cout << "YES" << endl;
        else cout << "NO" endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
using namespace std;
 
 
int res=0;
 
bool saiki(int ball[],int ttB,int ttC,int res){
    if(res==10)return true;
    if(ball[res]>ttB){
        return saiki(ball,ball[res],ttC,res+1);
    }
    if(ball[res]>ttC){
        return saiki(ball,ttB,ball[res],res+1);
    }
    return false;
}
 
int main(void){
    int a,b;
    int ball[11];
    int ttB=0,ttC=0;
    int n;
    scanf("%d",&n);
    for(a=0;a<n;a++){
        for(b=0;b<10;b++){
            ball[b]=0;
        }
        ttB=0;
        ttC=0;
        res=0;
        for(b=0;b<10;b++){
            scanf("%d",&ball[b]);
        }
        if(saiki(ball,ttB,ttC,res)==true)printf("YES\n");else printf("NO\n");
    }
    return 0;
}

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

int b[10],c[10],bi,ci,flag;

int main()
{
    int n,ball;
    scanf("%d", &n);
    for(int I=0;I<n;++I) {
        for(int i=0;i<10;++i) {
            scanf("%d", &ball);
            if (!bi) { b[bi] = ball; bi++; continue; }
            else if (!ci) { c[ci] = ball; ci++; continue; }
            else if (b[bi] < ball) {
                ++bi;
                b[bi] = ball;
            } else if (c[ci] < ball) {
                ++ci;
                c[ci] = ball;
            } else {
                ++flag;
                break;
            }
        }
        (flag) ? puts("NO") : puts("YES");
    }

    return 0;
}

C++: #include <iostream>
using namespace std;
int a[10];
bool dfs(int cur,int l,int r){
	if(cur==10){
		return true;
	}
	return (a[cur]>l && dfs(cur+1,a[cur],r)) || (a[cur]>r && dfs(cur+1,l,a[cur]));
}
int main(){
	ios::sync_with_stdio(false);
	int T;
	cin>>T;
	while(T--){
		for(int i=0;i<10;i++)
			cin>>a[i];
		puts(dfs(0,0,0)?"YES":"NO");
	}
	return 0;
}

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

int n,count=0;
int input[10];
bool res;

bool dfs(int x,int ltop,int rtop){
//  cout<<x<<","<<ltop<<","<<rtop<<endl;
    if(x==10) return true;
    if(ltop<input[x]){
        if(dfs(x+1,input[x],rtop)) return true;}
    if(rtop<input[x]){
        if(dfs(x+1,ltop,input[x])) return true;}

    return false;
}

int main(){ 
    cin>>n; 
    while(count<n){
        res=false;
        for(int i=0;i<10;i++){
            cin>>input[i];
        }       
        if(dfs(0,0,0)) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        count++;
    }
    return 0;
}

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;i<10;i++){
  std::cin>>A;
  if(B<A)B=A;else C<A?C=A:f=1;
 }
}

C++: #include <iostream>
#include <string.h>

using namespace std;

int ball_list[10];
int right_val;      
int left_val;

bool flag;

void dfs(int right, int left){
  int count = right + left;
  int num = ball_list[count];

  if(flag) return;

  if(count == 10){
    flag = true;
  }else{
    if(right_val < ball_list[count]){
      right_val = num;
      dfs(right+1, left);
    }
    if(left_val < ball_list[count]){
      left_val = num;
      dfs(right, left+1);
    }
  }
}

int main(){
  int n;

  cin >> n;

  for(int i = 0; i < n; i++){
    flag = false;
    right_val = 0;
    left_val = 0;

    for(int j = 0; j < 10; j++){
      cin >> ball_list[j];
    }
    
    dfs(0, 0);

    cout << ((flag)? "YES" : "NO") << endl;
  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){

  int a,b,n,m,flag;
  
  cin >> m;
  for(int j=0;j<m;j++){
    a = b = flag = 0;
    for(int i=0;i<10;i++){
      
      cin >> n;
      
      if(a<n&&b>n) a=n;
      else if(a>n&&b<n) b=n;
      
      else if(a<n&&b<n){
	if( (a>b)? a=n:b=n);
      }
      else flag++;
      
    }
    printf("%s\n",(flag==0)? "YES":"NO");
  }

  return (0);
}

C++: #include<iostream>
int T[10];
int ans;

void method(int num,int A,int B){
  if(num==10){
    ++ans;
    return;
  }
  if(T[num]>A){
    method(num+1,T[num],B);
  }
  if(T[num]>B){
    method(num+1,A,T[num]);
  }
}
int main(){
  int n;

  std::cin >> n;

  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      std::cin >> T[j];
    }
    ans = 0;
    method(0,0,0);
    std::cout << ((!ans)? "NO" : "YES") << std::endl;
  }
}