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 <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  REP(i, n) {
    int a[10];
    REP(j, 10) cin >> a[j];
    bool ok = false;
    for (int mask = 0; mask < 1 << 10; ++mask) {
      int max1 = 0, max2 = 0;
      bool ok2 = true;
      REP(j, 10) {
        if (mask >> j & 1) {
          if (max1 < a[j])
            max1 = a[j];
          else
            ok2 = false;
        } else {
          if (max2 < a[j])
            max2 = a[j];
          else
            ok2 = false;
        }
      }
      if (ok2) {
        ok = true;
        break;
      }
    }
    cout << (ok ? "YES" : "NO") << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int n;
  int max1=0,max2=0;
  int i,j;
  int num;

  cin>>n;

  rep(i,n){
    rep(j,10){

      scanf("%d",&num);

      if(max1>num && max2>num){
	cout<<"NO"<<endl;
	break;
      }
      else if(max1>num)
	max2=num;
      else if(max2>num)
	max1=num;
      else
	max1>max2 ? max1=num : max2=num;

    }//repj
    if(j==10)
      cout<<"YES"<<endl;
  }//repi
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
using namespace std;

int a[15];
int b[15];
int n;

struct node {
	int cnt;
	int pos1,pos2;
	int an[15];
	int bn[15];
}ball,tmp,t;

bool bfs(){
	queue<node> q;
	ball.an[0]=a[0];
	ball.pos1=0;
	ball.pos2=0;
	ball.cnt=0;
	q.push(ball);
	while(!q.empty()){
		tmp=q.front();
		int f=1;
		if(tmp.an[tmp.pos1]<a[tmp.cnt+1]){
			tmp.an[tmp.pos1+1]=a[tmp.cnt+1];
			tmp.pos1++;
			tmp.cnt++;
			q.push(tmp);
			f=0;
		}
		tmp=q.front();
		if(tmp.pos2==0||tmp.bn[tmp.pos2]<a[tmp.cnt+1]){
			tmp.bn[tmp.pos2+1]=a[tmp.cnt+1];
			tmp.pos2++,tmp.cnt++;
			q.push(tmp);
			f=0;
		}
		/*
		for(int i=0;i<q.front().pos1;i++){
			cout<<q.front().an[i]<<"  ";
		}cout<<endl;
		for(int i=0;i<q.front().pos2;i++){
			cout<<q.front().bn[i]<<"  ";
		}cout<<endl;
		cout<<"   "<<tmp.cnt<<endl;
		q.pop();
	//	if(f) return 0;
	*/
	q.pop();
		if(tmp.cnt==9) return 1;
	}
	return 0;
} 

int main(){
	while(cin>>n){
		while(n--){
			ball.pos1=0,ball.pos2=0,ball.cnt=0,ball.bn[0]=0;
			for(int i=0;i<10;i++) cin>>a[i];
			if(bfs()) cout<<"YES\n";
			else cout<<"NO\n";
		}
	//	
	}
	return 0;
}

C++: #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int num1[12];
int num2[12];
int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        memset(num1,0,sizeof(num1));
        memset(num2,0,sizeof(num2));
        int num;
        int ans1=1,ans2=0;
        cin>>num;
        num1[0]=num;
        for(int i=1;i<=9;i++)
        {
            cin>>num;
            if(num>num1[ans1-1])
                num1[ans1++]=num;
            else
            {
                num2[ans2++]=num;
            }
        }
        /*for(int i=0;i<ans1;i++)
            cout<<num1[i]<<" ";
        cout<<endl;
        for(int i=0;i<ans2;i++)
            cout<<num2[i]<<" ";
        cout<<endl;*/
        int flag=0;
        for(int i=1;i<ans2;i++)
        {
            if(num2[i]<num2[i-1])
            {
                flag=1;
                break;
            }
        }
        if(flag)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int main( void )
{
	int n, input[10], stA[10], stB[10];
	cin >> n;
	while(n--) {
		for(int i=0; i < 10; ++i) {
			stA[i] = stB[i] = 0;
			cin >> input[i];
		}
		int idxI, idxA, idxB;
		idxI = 2; idxA = idxB = 0;
		stA[0] = input[0]; stB[0] = input[1];
		bool hit = true;
		while(10 > idxI && hit) {
			int tmp = input[idxI];
			if(stB[idxB] < stA[idxA]) { // A
				if(stA[idxA] < tmp) stA[++idxA] = tmp;
				else if(stB[idxB] < tmp) stB[++idxB] = tmp;
				else hit = false;
			}
			else {	// B
				if(stB[idxB] < tmp) stB[++idxB] = tmp;
				else if(stA[idxA] < tmp) stA[++idxA] = tmp;
				else hit = false;
			}
			++idxI;
		}
		if(idxI == 10 && hit)
			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()) sta[0].push(x);
        else sta[1].push(x);
      }
    }
    if(b) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

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

int main(){
	stack<int> b,c;
	int n;
	cin>>n;

	for(int i=0;i<n;i++){
		bool flag=true;
		b.push(-1);c.push(-1);
		for(int j=0;j<10;j++){
			int t;
			cin>>t;
			if(b.top()<t && c.top()<t){
				b.top()>c.top()?b.push(t):c.push(t);
			}
			else if(b.top()<t){
				b.push(t);
			}
			else if(c.top()<t){
				c.push(t);
			}
			else {
				flag=false;
				break;
			}
		}
		cout<<(flag?"YES":"NO")<<endl;

		while(!b.empty()) b.pop();
		while(!c.empty()) c.pop();
	}
	return 0;
}

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

using namespace std;

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

	bool flag = true;

	int n;
	cin >> 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);
		}
	}

	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  if (i == n - 1 && j == 9) {

						}
						else {
							flag = false;
						}
						
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}

		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
		flag = true;
	}

	return 0;
}