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++: /*
* @Author: key
* @Date:   2016-03-04 11:52:34
* @Last Modified by:   key
* @Last Modified time: 2016-03-04 12:49:05
*/

#include <iostream>

using namespace std;

int c[10];

int a[10],b[10];

bool flag;

void dfs(int x,int y,int z){
    if(x > 9){
        flag = true;
        return;
    }

    if(flag)
        return;

    if(y < 0 || c[x] > a[y]){
        a[y+1] = c[x];
        dfs(x+1,y+1,z);
    }

    if(z < 0 || c[x] > b[z]){
        b[z+1] = c[x];
        dfs(x+1,y,z+1);
    }

}

int main(){

    int n;

    cin >> n;

    while(n--){
        flag = false;
        for(int i = 0; i < 10; i++){
            cin >> c[i];
            a[i] = 0;
            b[i] = 0;
        }
        dfs(0,-1,-1);
        if(flag)
            cout << "YES" <<endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}

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; break;
			}
		}
		printf("%s\n",valid?"YES":"NO");
	}
	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>
#include<cstdlib>
#include<cmath>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;

int N;

int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };

int ball[10];

//int B = 0, C = 0;

int bfs(int n, int B, int C) {
	
	if (n == 10) {
		return true;
	}

	if (B < ball[n]) {
		B = ball[n];
		return bfs(n + 1, B, C);
	}
	if (C < ball[n]) {
		C = ball[n];
		return bfs(n + 1, B , C);
	}
	
	return false;

}

void input(void) {
	for (int i = 0; i < 10; i++) {
		CI ball[i];
	}
	return;
}


int main(void) {
	CI N;

	for (int i = 0; i < N; i++) {
		input();
		if (bfs(0, 0, 0)) {
			CO "YES" E
		}
		else {
			CO "NO" E
		}
	}
	
	return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
  bool f;
  int n, i, a, b, c;
  cin >> n;
  while (n--) {
    for (i = b = c = f = 0; i < 10; i++) {
      cin >> a;
      if (a > b) {
        b = a;
      } else if (a > c) {
        c = a;
      } else {
        f = 1;
        break;
      }
    }
    if (f)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 25
using namespace std;
int n,m;
int tmax,tmin;
int a[Maxn];
int ans1[Maxn];
int ans2[Maxn];
int main()
{
    int f;
    cin>>n;
    while(n--)
    {
        f=1;
        MEM(a,0);
        MEM(ans1,0);
        MEM(ans2,0);
        for(int i=1; i<=10; i++)
            cin>>a[i];
        ans1[1]=a[1];
        ans2[0]=0;
        int p1=0,p2=0;
        int i;
        for(i=2; i<=10; i++)
        {
//            if(ans1[p1]>ans[p2])
//            {
//                tmax=ans1[p1];
//                tmin=ans2[p2];
//            }
//            else
//            {
//                tmax=ans2[p2];
//                tmin=ans1[p1];
//            }
            if(a[i]>ans1[p1])
            {
                ans1[++p1]=a[i];
            }
            else if(a[i]>ans2[p2])
            {
                ans2[++p2]=a[i];
            }
            else
            {
                cout<<"NO"<<endl;
                break;
            }
        }
        if(i>10)
            cout<<"YES"<<endl;
    }
}

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

int main()
{
	int n,a;

	std::cin >> n;

	std::vector<int> ball;

	for(int i=0; i<n; ++i)
	{
		for(int i=0; i<10; ++i)
		{
			std::cin >> a;

			ball.push_back(a);
		}
		
		int right=-1,left=-1;

		right = ball[0];

		bool flg1 = 1;

		bool rightOK;

		bool leftOK;

		for(int i=1; i<10; ++i)
		{
			rightOK = ball[i]>right;

			leftOK = (ball[i]>left || left==-1);

			if(rightOK && leftOK)
			{
				if(right>left)
				{
					right = ball[i];
				}
				else
				{
					left = ball[i];
				}
			}
			else if(rightOK)
			{
				right =  ball[i];
			}
			else if(leftOK)
			{
				left = ball[i];
			}
			else
			{
				flg1 = 0;

				break;
			}
		}

		std::cout << (flg1 ? "YES\n" : "NO\n");

		ball.clear();
	}
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

int main() {
	int n; cin >> n;
	int l = 0, r = 0;
	while (n--) {
		bool ok = true;
		rep(i, 10) {
			int b; cin >> b;
			if(l < b) l = b;
			else if (r < b) {
				r = b;
				if (l < r) swap(l, r);
			}
			else {
				ok = false;
			}
		}
		cout << (ok ? "YES" : "NO" ) << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string.h>
using namespace std;
int main(void)
{
  int n;
  cin>>n;
 
  for(int i=0;i<n;i++)
    {
      int num1[10];
      int count=0;
      for(int j=0;j<10;j++)
	{
	  cin>>num1[j];
	}
      for(int k=0;k<10-1;k++)
	{
	  int num2[10];
	  if(num1[k]>num1[k+1])
	    {
	      int l=0;
	      num2[l]=num1[k];
	      l++;
	    }
	  if(num1[k]>num1[k+1] && num2[k]>num2[k+1] && num2[k+1]!=0)count++;
	}
      if(count>0)cout<<"NO"<<endl;
      else cout<<"YES"<<endl;
      
    }
  return 0;
}