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<string>  
#include<iostream>  
#include<cstring>  
#include<algorithm>  
using namespace std;  
typedef long long LL;  
const int INF = 0x7FFFFFFF;  
const int maxn = 1e5 + 10;  
   
int a[11],vis[11],flag;  
  
void dfs(int x,int l,int r)  
{  
    int i;  
    if(x==11)return;   
    if(flag)return;  
    if(a[x]>l)dfs(x+1,a[x],r);  
    else if(a[x]>r)dfs(x+1,l,a[x]);  
    else{flag=1;return;}  
}  
  
int main()  
{  
  int T,i,j,k;  
  scanf("%d",&T);  
  while(T--)  
  {  
    flag=0;  
    for(i=1;i<=10;i++)  
      scanf("%d",&a[i]);  
    memset(vis,0,sizeof(vis));  
    dfs(1,0,0);  
    if(flag)printf("NO\n");  
    else printf("YES\n");  
  }  
 return 0;  
}

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

using namespace std;


const int MAX_M = 15;
int N, H[10];

double dp[2][(1 << MAX_M) + 1];

int solve() {
	int big=0, small=0;
	for (int i = 0; i < 10; i++) {
		if (big < small) swap(big, small);
		if (H[i] < small) {
			printf("NO\n");
			goto JUMP;
		}

		if (H[i] > big) big = H[i];
		else if (H[i] > small) small = H[i];

	}
	printf("YES\n");
JUMP:
	return 0;
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> H[j];
		}
		solve();
	}

	
	return 0;
}

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

#define REP(i, n)       REPEAT(i, 0, n)
#define REPEAT(i, k, n) for (int i = (k); i < (n); ++i)

#ifdef _DEBUG
#define pf printf
#define pr(n) do { cout << #n " = " << (n) << endl; } while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#endif

int main(){
    int n;
    cin >> n;
    REP(i,n){
        int a, p1 = 0, p2 = 0;
        bool flag = true;
        REP(j,10){
            cin >> a;
            if(p1 < a){
                p1 = a;
            } else if(p2 < a){
                p2 = a;
            } else {
                flag = false;
            }
            pf("DEBUG: %d %d %d\n", a, p1, p2);
        }
        cout << (flag?"YES":"NO") << endl;
    }
    return 0;
}

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

int main()
{
    int n;
    int a[11];
    cin>>n;
    while(n--)
    {
        int p=0,q=0;
        int flag=1;
        for(int i=0; i<10; i++)
        {
            cin>>a[i];
        }
        for(int i=0; i<10; i++)
        {
            if(a[i]<p&&a[i]<q)
            {
                flag=0;
                break;
            }
            else if(a[i]>p&&a[i]<q)
            {
                p=a[i];
                continue;
            }
            else if(a[i]<p&&a[i]>q)
            {
                q=a[i];
                continue;
            }
            else
            {
                if(p>q)
                    p=a[i];
                if(p<q)
                    q=a[i];
                if(p==q)
                    p=a[i];
            }
        }
        if(flag==0)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
int main(){
    int p; cin>>p;
    rep(hogehoge,p){
        vi v(10,0);rep(i,10)cin>>v[i];
        vb flag(11,false);flag[v[0]]=true; flag[v[1]]=true;
        pii num=pii(v[0],v[1]);
        rep(i,10){
            if(i==0||i==1)continue;
            if(num.first<v[i]){flag[v[i]]=true; num.first=v[i];}
        }
        rep(i,10){
            if(flag[v[i]])continue;
            else if(num.second<v[i]){flag[v[i]]=true; num.second=v[i];}
        }
        bool judge=true;
        rep(i,10){
            if(!flag[i+1])judge=false;
        }
        if(judge)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}

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

vector<int> minvec(vector<int> v1, vector<int> v2){
  if(v1.back() < v2.back()){
	return v1;
  }else{
	return v2;
  }
}

vector<int> maxvec(vector<int> v1, vector<int> v2){
  if(v1.back() < v2.back()){
	return v2;
  }else{
	return v1;
  }
}

int main(void){
  int n;
  int i,j;
  vector<int> q;
  vector<int> out[2];
  int tmp;
  bool isok = true;;
  cin >> n;
  for(i=0;i<n;i++){
	for(j=0;j<10;j++){
	  cin >> tmp;
	  q.push_back(tmp);
	}

	for(j=0;j<10;j++){
	  if(out[0].empty()){
		out[0].push_back(q[j]);
	  }else if(out[1].empty()){
		out[1].push_back(q[j]);
	  }else if(q[j] > maxvec(out[0], out[1]).back()){
		maxvec(out[0],out[1]).push_back(q[j]);
	  }else if(q[j] < minvec(out[0], out[1]).back()){
		cout << "NO" << endl;
		isok = false;
		break;
	  }else{
		minvec(out[0], out[1]).push_back(q[j]);
	  }
	}
	if(isok) cout << "YES" << endl;
	isok = true;
	out[0].clear();
	out[1].clear();
	q.clear();
  }
  return 0;
}

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

int B, C, num[11], b, c;

string dfs(int x){
    if(x == 10)  return "YES";
    else if(B>num[x]){
        if(C<num[x]){
            C = num[x];
            return dfs(x+1);
        }
        else return "NO";
    }
    else if(B<num[x]){
        B = num[x];
        return dfs(x+1);
    }
}

int main(void){
    int N;
    while(cin >> N){
    B = 0;
    C = 0;
    for(int i=0; i<10; i++){
        cin >> num[i];
    }
    string str = dfs(0);
    cout << str << endl;
    }
    return 0;
}

C++: #define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#include <bits/stdc++.h>
using namespace std;

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

  int x;
  rep(i,n){
    bool bo=true;
    stack<int> a,b;
    rep(j,10){
      cin>>x;
      if(a.empty()) a.push(x);
      else if(x>a.top()) a.push(x);
      else if(b.empty()) b.push(x);
      else if(x>b.top()) b.push(x);
      else bo=false;
    }
    if(bo) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
      
  return 0;
}

C++: #include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		int a[9]={};
		int b[9]={};
		int dat,o=0,s=1;
		for(int j=0;j<=10;j++){
			cin>>dat;
		 	if(j==0){
				a[0]=dat;
			}
			else if(dat>a[s-1]){
				a[s]=dat;
				s++;
			}
			else if(dat>b[o]){
				b[o]=dat;
				o++;}
			else{
				cout<<"NO"<<endl;
			break;
			}
			if(j==10){
				cout<<"YES"<<endl;
				break;
						}

		}
	}
	return 0;
}