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>

using namespace std;

int main( void )
{
	int n, input[10], stA[11], stB[11];
	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];
		if(stA[0] < input[1]) {
			stA[1] = input[1];
			idxA = 1;
		}
		else {
			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++: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    input.readLine();
    while (input.ready())
    {
      String[] INPUT_STR = input.readLine().split(" ");

      System.out.println(solver(INPUT_STR));
    }

  }

  private static String solver(String[] array)
  {
    int currentA = 0;
    int currentB = 0;
    int currentC = 0;

    for (int i = 0; i < array.length; i++)
    {
      currentA = Integer.parseInt(array[i]);
      if (i % 2 == 0)
      {
        if (currentB > currentA)
        {
          return "NO";
        }
        currentB = currentA;
      }
      else
      {
        if (currentC > currentA)
        {
          return "NO";
        }
        currentC = currentA;
      }
    }
    return "YES";
  }

}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<map>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

bool memo[11][11];
int data[10];

bool ans(int p, int b, int c){
  if(memo[b][c]) return false;
  if(p == 10) return true;
  int d = data[p];
  if(b < d && ans(p+1, d, c)) return true;
  if(c < d && ans(p+1, b, d)) return true;
  memo[b][c] = true;
  return false;
}

int main(){
  int n;
  scanf("%d",&n);
  while(n --> 0){
    memset(memo,0,sizeof(memo));
    REP(i,10) scanf("%d",&data[i]);
    puts(ans(0,0,0)?"YES":"NO");
  }
  return 0;
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define range(i,b) rep(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
	int a,b;
	int n;
	int input;
	bool check;

	while(cin >> n){
		range(i,n){
			a = b = 0;
			range(i,10){
				check = true;
				cin >> input;
				if(input > a){
					a = input;
				}else if(input > b){
					b = input;
				}else{
					check = false;
				}
			}
			if(check) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.ball", "r", stdin);
	string str = "";
	int n;

	getline (cin, str );
	stringstream ssn(str);
	ssn >> n;

	int i,j;
	for (i = 0; i < n; ++i){
		vector <int> ball;
		getline (cin, str );
		stringstream ss(str);
		int b;
		while (ss >> b){
			ball.push_back(b);
		} // end while
		stack <int> A;
		stack <int> B;

		A.push (0);
		B.push (0);

		int size = ball.size();

		A.push (ball[0]);
		for (j = 1; j < size; ++j){
//			cout << "ball[" << j << "]: " << ball[j] << endl;
//			cout << "A:" << A.top() << " B: " << B.top() << endl;
			if (ball[j] < A.top() && ball[j] > B.top() ){
//				cout << "B in" << endl;
				B.push (ball[j]);
			}else if (ball[j] > A.top() && ball[j] < B.top() ){
//				cout << "A in" << endl;
				A.push (ball[j]);
			}else if (ball[j] > A.top() && ball[j] > B.top() ){
				if (ball[j] - A.top() < ball[j] - B.top() ){
//					cout << "A in" << endl;
					A.push (ball[j]);
				}else{
//					cout << "B in" << endl;
					B.push (ball[j]);
				} // end if 
			}else{
				cout << "NO" << endl;
				break;
			} // end if
		} // end for
		if (j == size ){
			cout << "YES" << endl;
		} // end if
	} // end for
		
	return 0;
}

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

int main(){
	int a;
	int b[10];
	cin>>a;
	
	for(int j=0;j<a;j++){
		
			int flg=0;
			
	for(int i=0;i<10;i++){
		cin>>b[i];
		}
		
		stack<int>ta,tb;
		ta.push(b[0]);
		tb.push(0);
		
		for(int k=1;k<10;k++){
			if(b[k]>ta.top()){ta.push(b[k]);}
			else if(b[k]>tb.top()){tb.push(b[k]);}
			else{
				flg++;
				break;
				}
			}
			if(flg==0){cout<<"YES"<<endl;}
			else{cout<<"NO"<<endl;}
		}
		return 0;
	}

C++: #include <cstdio>
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
using namespace std;
const int manx = 500;
stack <int> a;
stack <int> b;
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int input;
        int flag = true;
        scanf("%d",&input);
        a.push(input);
        b.push(0);
        for(int i = 1 ; i < 10 ; i++)
        {
            scanf("%d",&input);
            int ai = input - a.top();
            int bi = input - b.top();
            if(ai <= 0 && bi <= 0)
            {
                flag = false;
                //printf("NO\n");
                break;
            }
            if(ai > 0 && bi <= 0)
                a.push(input);
            if(bi > 0 && ai <= 0)
                b.push(input);
            if(ai > 0 && bi > 0)
            {
                if(ai > bi )
                    b.push(input);
                if(ai <= bi)
                    a.push(input);
            }
        }
        if(flag == false)
            printf("NO\n");
        if(a.size() + b.size() == 11)
            printf("YES\n");
        while(!a.empty())
            a.pop();
        while(!b.empty())
            b.pop();
    }
    return 0;
}