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;

bool flag;
int a[10];

void dfs(int ap, int b, int c){
 
  if(!ap){
    flag = true;
    return;
  }
  else{
    if(a[10 - ap] > b){
      return dfs(ap - 1, a[10 - ap], c); 
    }
    else if(a[10 - ap] > c){
      return dfs(ap - 1, b, a[10 - ap]); 
    }
    else{
      return;
    }
  }

}

int main(){

  int n;

  cin >> n;

  for(int i = 0; i < n; ++i){
    
    flag = false;
    
    for(int j = 0; j < 10; ++j){
      cin >> a[j];
    }
    
    dfs(10, 0, 0);

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

  }

}

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

vector<int> data;
vector<int> tube_B;
vector<int> tube_C;

const int MAX = 10;

int dfs(int count){

    if (count == MAX) return 1;

    int ret = 0;

    int b = tube_B.size() - 1;
    int c = tube_C.size() - 1;

    if (data[count] > tube_B[b]){
        tube_B.push_back(data[count]);
        ret = max(ret, dfs(count + 1));
        tube_B.pop_back();
    }

    if (data[count] > tube_C[c]){
        tube_C.push_back(data[count]);
        ret = max(ret, dfs(count + 1));
        tube_C.pop_back();
    }

    return ret;
}

int main(void){

    int n;
    cin >> n;
    tube_B.push_back(-1);
    tube_C.push_back(-1);

    for (int i = 0; i < n; i++){
        for (int j = 0; j < 10; j++){
            int s;
            cin >> s;
            data.push_back(s);
        }

        if (dfs(0)){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }

        data.erase(data.begin(), data.end());
        tube_B.erase(tube_B.begin(), tube_B.end());
        tube_C.erase(tube_C.begin(), tube_C.end());
    }


}

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++: //C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#define rp(i,a,b) for(int (i)=(int)(a);i<(int)(b);++i)

typedef long long ll;


using namespace std;
int main(){
    int N;
    cin>>N;
    
    for(int i=0;i<N;i++){
        stack<int> a,b;
        a.push(0);
        b.push(0);
        bool flag=true;
        for(int j=0;j<10;j++){
            int tm;
            cin>>tm;
            if(tm>a.top()) a.push(tm);
            else if(tm>b.top()) b.push(tm);
            else {flag=false;}
        }
        if(flag)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }

    return 0;
};

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <cmath>
#include <algorithm>
using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main() {
  int n; cin >> n;
  while(n--) {
    stack<int> sta[2];
    vi a(10); rep(i, 10) cin >> a[i];
    bool b = true;
    rep(i, 10) {
      int x = a[i];
      if(i == 0) sta[0].push(x);
      else if(sta[1].empty()) {
        if(sta[0].top() < x) sta[0].push(x);
        else sta[1].push(x);
      } else {
        if(sta[0].top() > x && sta[1].top() > x) {
         b = false;
         break;
        } else if(sta[0].top() > sta[1].top()) {
          if(sta[0].top() < x) sta[0].push(x);
          else sta[1].push(x);
        } else {
          if(sta[1].top() < x) sta[1].push(x);
          else sta[0].push(x);
        }
      }
    }
    if(b) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int f;
  int n;
  int in,b,c;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    f=b=c=0;
    for(int j=0;j<10;j++){
      scanf("%d",&in);
      if(in<=min(b,c)){
	f=1;
	break;
      }
      if((b>=c && b<in)||(b<c && c>in))b=in;
      else c=in;
    }
    if(f)printf("NO\n");
    else printf("YES\n");
  }
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
#define Vi vector<int>
#define Vl vector<long long>
#define pb(a) push_back(a)

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct edge{int to,cost;};
struct pos{
	int x,y;
};

int main() {

	int n;
	cin>>n;
	rep(i,n){
		ll a=0,b=0,f=0;
		rep(j,10){
			ll x;
			cin>>x;
			if(f==1)continue;
			if(x<a&&x<b)f=1;
			else if(x>max(a,b)){
				if(a>b)a=x;
				else b=x;
			}else{
				if(a>b)b=x;
				else a=x;
			}
		}
		if(f==0)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>

using namespace std;

int s[10]={0};

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        for(int i=0;i<10;i++)
            scanf("%d",&s[i]);
        int a=0;
        int b=0;
        bool flag=0;
        for(int i=0;i<10;i++)
        {
            if(s[i]<a&&s[i]<b)
            {
                flag=1;
                break;
            }
            else if(s[i]<a&&s[i]>b)b=s[i];
            else if(s[i]>a&&s[i]<b)a=s[i];
            else
            {
                a=a>b?s[i]:a;
                b=a<b?s[i]:b;
                if(a==b)a=s[i];
            }
        }
        if(flag)printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int check(int cc[10])
{
    int temp,z=0,x=0;
    for(int i=0;i<10;i++){
	if(cc[i]<x)return 10;
	else if(cc[i]>z)z=cc[i];
	else if(cc[i]<z&&cc[i]>x)x=cc[i];
    }
    return 1;
}

int main()
{
    int log,N,bb[10];
    cin>>N;    
    for(int i=0;i<N;i++){
    	for(int k=0;k<10;k++)cin>>bb[k];
    	log=check(bb);
	if(log==10)cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
    }
    return 0;
}

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

int a[10];

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

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