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++: #define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<string>
using namespace std;

static int N;
static vector<int> balls;
static vector<int> A, B;
static bool flag;

void dfs(int id)
{
	if (flag) return;
	if (id >= 10)
	{
		flag = true;
		return;
	}
	//printf("%d\n", id);
	if ((A.size() > 0 && balls[id] > A.back()) || A.size() == 0)
	{
		A.push_back(balls[id]);
		dfs(id + 1);
	}
	else if ((B.size() > 0 && balls[id] > B.back()) || B.size() == 0)
	{
		B.push_back(balls[id]);
		dfs(id + 1);
	}
	
}




int main()
{
	while (scanf("%d", &N) != EOF)
	{
		while (N--)
		{
			balls.clear();
			balls.resize(10);
			for (int i = 0; i < 10; i++) scanf("%d", &balls[i]);
			A.clear();
			B.clear();
			flag = false;
			dfs(0);
			printf(flag ? "YES\n" : "NO\n");
		}
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
int a[10];
bool ans;
void dfs(int i,int r,int l){
	if(i==10)return;
	if(ans==0)return;
	if(r<a[i])dfs(i+1,a[i],l);
	else if(l<a[i])dfs(i+1,r,a[i]);
	else ans=0;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		for(int i=0;i<10;i++)cin>>a[i];
		dfs(0,0,0);
	if(ans)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;
#define FOR(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
int num[10];
int B[10];
int C[10];
int flag = false;
void solve(int, int, int);

int main(void){
	int N;
	cin >> N;
	for(int k = 0; k < N; k++){
		fill_n(B , 10, -1);
		fill_n(C , 10, -1);
		for(int i = 0; i < 10; i++){
			cin >> num[i];
		}
		solve(0, 0, 0);
		if(flag){cout << "YES" << endl; continue;}
		cout << "NO" << endl;
	}

	return 0;
}

void solve(int cnt,int right, int left){
	if(cnt == 10){
		flag = true;
		return;
	}
	if(num[cnt] > right) solve(cnt+1, num[cnt], left);
	if(num[cnt] > left) solve(cnt+1, right, num[cnt]);
}

C++: //aoj 0033
 
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int ball[10];
bool can = false;
 
void search(int r,int l,int n){
  //  cout << n << endl;
  if(n>=10) {
	can = true;
	return;
  }
  if(r<ball[n]) search(ball[n],l,n+1);
  if(l<ball[n]) search(r,ball[n],n+1);
}
 
int main(){
  int n;
  cin >> n;
  REP(i,n){
    REP(i,10) cin >> ball[i];
  	int right=0;
  	int left=0;
  	can = false;
  	search(right,left,0);
  	if(can) cout << "Yes" << endl;
  	else cout << "No" << endl;
  }
 
}

C++: #include <iostream>

using namespace std;

int main()
{
    int n,a[10],b[10],c[10];
    cin>>n;
    while(n>0)
    {
        for(int i=0;i<10;i++)
        {
            cin>>a[i];
        }
        b[0]=a[0];
        c[0]=0;

        int k=1,t=1;
        bool ei=true,el=true;
        for(int j=1;j<10;j++)
        {
            if(a[j]>b[k-1])
            {
                b[k]=a[j];
                k++;
            }
            else if(a[j]>c[t-1])
            {
                if(ei)
                {
                    c[0]=a[j];
                    ei=false;
                }
                else
                {
                    c[t]=a[j];
                    t++;
                }
            }
            else
            {
                el=false;
                break;
            }
        }
        if(el)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
        n=n-1;

    }
    return 0;
}

C++: #include <iostream>
using namespace std;
const int N = 10;
int main(){
    int n;
    cin >> n;
    while(n--) {
        bool ans = true;
        int a, b=-1, c=-1;
        for(int i=1; i<=N; i++) {
            cin >> a;
            if(ans) {
                if(a > b)
                    b = a;
                else if(a > c)
                    c = a;
                else
                    ans = false;
       }
    }
    if(ans) puts("YES");
    else puts("NO");
}
}

C++: //-*-coding:utf-8-*-
//----------------------------------------------------------
// module: main
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0033
//----------------------------------------------------------
#include <algorithm>
#include <vector>
#include <deque>
#include <map>

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

const int MAXL = 10;

int numbers[MAXL];

void solve(){
    for (int i = 0; i < 4; ++i)
        {
            if (numbers[i*2] > numbers[i*2 + 2] ||
                numbers[i*2 + 1] > numbers[i*2 + 3]
                ) {
                printf("NO\n");
                return;
            }
        }
    printf("YES\n");
};

int main(int argc, char *argv[])
{
    int c;
    scanf("%d", &c);
    for (int i = 0; i < c; ++i)
        {
            scanf("%d %d %d %d %d %d %d %d %d %d", &numbers[0], &numbers[1], &numbers[2], &numbers[3], &numbers[4], &numbers[5], &numbers[6], &numbers[7], &numbers[8], &numbers[9]);
            solve();
        }
    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 <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <ctype.h>

using namespace std;

int main () {
    int b[10];
    

    int x;
    cin>>x;
    
    while(cin>>b[0]>>b[1]>>b[2]>>b[3]>>b[4]>>b[5]>>b[6]>>b[7]>>b[8]>>b[9]){
        int flag=0;
        int l=0,r=0;
        for(int i=0; i<10; i++){
            if(l<b[i]&&r<b[i]){
                if(l<r){
                    r=b[i];
                }else{
                    l=b[i];
                }
            }else if(l>b[i]&&r<b[i]){
                r=b[i];
            }else if(l<b[i]&&r>b[i]){
                l=b[i];
            }else{
                flag++;;
                break;
            }
        }
        
        if(flag==1){
            cout<<"NO"<<endl;
        }else{
            cout<<"YES"<<endl;
        }

    }
    return 0;
}