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 <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;
  scanf("%d", &N);

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

    if (solve()) {
      printf("YES\n");
    }
    else {
      printf("NO\n");
    }
  }

  return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int ball[10];
int l,r;
bool flag;
void dfs(int num,int l,int r){
	if(num==10) return ;
	if(flag) return ;
	if(ball[num]>l) dfs(num+1,ball[num],r);
	else if(ball[num]>r) dfs(num+1,l,ball[num]);
	else{
		flag=true;
		return ;
	}
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int i=0;i<10;i++){
			cin>>ball[i];
		}
		l=0,r=0;
		flag=false;
	    dfs(i,l,r);
		if(flag){
			cout<<"NO"<<endl;
		}else{
			cout<<"YES"<<endl;
		} 
	}
}

C++: #include <stdio.h>

int main(void){
	int topB,topC;
	int n,tmp;
	int valid;
	
	for (scanf("%d", &n); n--;){
		topB=topC=0;
		valid=1;
		for (int i=0; i<10; i++){
			scanf("%d", &tmp);
			if (tmp > topB) topB=tmp;
			else if (tmp > topC)topC=tmp;
			else {
				valid=0;
				for (;i<10;i++) scanf("%d", &tmp);
				break;
			}
		}
		printf("%s\n",valid?"YES":"NO");
	}
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<vector>

using namespace std;

int main(){
    int n;
    bool flag = true;
    vector<int> b, c;
    b.push_back(0);
    c.push_back(0);
    vector<int> ::iterator b_it=b.begin(), c_it=c.begin();

    cin>> n;
    while(n--, n!=-1){
        for(int i=0; i<10; i++){
            if(flag){
                int num;
                cin>> num;
                if(num>*b_it){
                    b.push_back(num);
                    b_it = b.end()-1;
                }else if(num>*c_it){
                    c.push_back(num);
                    c_it = c.end()-1;
                }else{
                    flag = false;
                }
            }
        }
        if(flag){
            cout<< "YES"<< endl;
        }else{
            cout<< "NO"<< endl;
        }
    }
    return 0;
}

C++: #include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int n;
int array[10];

void solve() {
    int B=0;
    int C=0;
    rep(i,10) cin>>array[i];
    B = array[0];
    C = array[1];

    rep(i,10) {
        if(i==0 || i==1) continue;
        int t1 = array[i] - B;
        int t2 = array[i] - C;
        // cout<<t1<<","<<t2<<endl;
        if(t1<=0 && t2<=0) {
            cout<<"NO"<<endl;
            return;
        }
        else if(t1 > t2) {
            C = array[i];
        }
        else {
            B = array[i];
        }
    }

    cout<<"YES"<<endl;

}

int main() {
    cin>>n;
    rep(i,n) solve();
    return 0;
}

C++: #include <bits/stdc++.h>
 
using namespace std;
 
int n, ball[10];
 
bool solve(int idx, int l, int r) {
 
    if(idx >= 10) return true;
 
    bool ret = false;
    if(ball[idx] > l) ret = ret || solve(idx + 1, ball[idx], r);
    if(ball[idx] > r) ret = ret || solve(idx + 1, l, ball[idx]);
    return ret;
 
}
 
int main() {
 
    cin >> n;
 
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < 10; ++j) {
            cin >> ball[j];
        }
        cout << solve(0, 0, 0) ? "YES" : "NO" << endl;
    }
 
}

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 <algorithm>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>

using namespace std;

int main() {

	stack<int> B, C;
	int n,ball;

	cin >> n;

	for(int j=0;j<n;j++){
		for (int i = 0; i < 10; i++) {
			cin >> ball;

			if (i == 0)
				B.push(ball);

			else if (B.top() > ball)

				if (C.empty())
					C.push(ball);

				else if (C.top() < ball)
					C.push(ball);

				else {
					cout << "NO" << endl;
					break;
				}

			else {
				if (B.top() < ball)
					B.push(ball);
				else {
					cout << "NO" << endl;
					break;
				}
			}

			if (i == 9)
				cout << "YES" << endl;
		}
		while (1) {
			B.pop();
			if (B.empty())
				break;
		}
		while (1) {
			C.pop();
			if (C.empty())
				break;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
int main(){
	int N, i;
	int num[11];
	cin >> N;
	while( N-- > 0 ){
		for( i = 0; i < 10; i++ ){
			cin >> num[i];
		}
		stack<int> st1;
		stack<int> st2;
		for( i = 0; i < 10; i++ ){
			if( st1.empty() ){
				st1.push(num[i]);
				continue;
			}else if( st2.empty() ){
				if( st1.top() < num[i] ){
					st1.push(num[i]);
					continue;
				}else{
					st2.push(num[i]);
					continue;
				}
			}
			if( st1.top() > num[i] ){
				if( st2.top() > num[i] ){
					cout << "NO" << endl;
					break;
				}else{
					st2.push(num[i]);
				}
			}else{
				if( st2.top() < num[i] ){
					if( st1.top() > st2.top() ){
						st1.push(num[i]);
					}else{
						st2.push(num[i]);
					}
				}
			}
		}
		if( i == 10 ) cout << "YES" << endl;
	}
}