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 <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;
                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");
        else
            printf("YES\n");
        while(!a.empty())
            a.pop();
        while(!b.empty())
            b.pop();
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

bool s( int ord[], int const i, int const bef = -1 )
{
    if ( i > 10 )
        return true;

    if ( bef != -1 && bef > ord[i] )
        return false;

    return s( ord, i+1, ord[i] ) || s( ord, i+2, ord[i] );
}

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

    for( int iii=0; iii<n; ++iii ) {
        int ord[10];
        for( int i=0; i<10; ++i )
            cin >> ord[i];

        cout << ( s( ord, 0 ) ? "YES" : "NO" ) << endl;
    }
}

C++: #include<stdio.h>
#include<string.h>

int main(){
	int ball[10];
	int cell[2][10]={0};
	int n,i,k,cell_1=1,cell_2=1,flag[1000]={0};
	
	scanf("%d",&n);
	
	for(k=0;k<n;k++){
		for(i=0;i<10;i++)scanf("%d",&ball[i]);
		
		cell[0][0]=cell[1][0]=0;
		
		for(i=0;i<10;i++){
			if(cell[0][cell_1-1] < ball[i]){
				cell[0][cell_1]=ball[i];
				cell_1++;
			}
			else if(cell[1][cell_2-1] < ball[i]){
				cell[1][cell_2]=ball[i];
				cell_2++;
			}
			else flag[k]=1;
		}	
	cell_1=1;
	cell_2=1;
	}
	
	for(i=0;i<n;i++){
		if(flag[i]==0)printf("YES\n");
		else printf("NO\n");
	}
	
	return 0;
}

C++: #include<stdio.h>
	int data[10];
int push(int right,int left,int i)
{
	if(i>=9)
		return 1;

	if(data[i]<right && data[i]<left)
		return 0;
	else
	{
		if(data[i]>=right)
			if(push(data[i],left,i+1))
				return 1;
		if(data[i]>=left)
			if(push(right,data[i],i+1))
				return 1;
	}
	return 0;
}

int main()
{
	int loop;
	scanf("%d",&loop);
	for(int j=0;j<loop;j++)
	{
		int right=0;int left=0;
		for(int i=0;i<10;i++)
			scanf("%d",&data[i]);

		if(push(right,left,0))
			printf("YES\n");
		else 
			printf("NO\n");
	}
}

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

int Data[10];

bool dfs(int a,int left,int right) {
	//cout << a << "/" << left << "/" << right << endl;
	if (a == 10) return true; 
	if (Data[a] > left) {
		//Add a to the left
		if(dfs(a+1,Data[a],right)) return true;
	}
	else if (Data[a] > right) {
		//Add a to the right
		if(dfs(a+1,left,Data[a])) return true;
	}
	return false;
}

int main() {
	int N;
	cin >> N;
	for (int i = 0;i < N;i++) {
		for (int j = 0;j < 10;j++) {
			cin >> Data[j];
		}
		if(dfs(0,0,0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

C++: #include <iostream>

#define MAX 10
using namespace std;

bool can_stack(int,int,int);

int main(){
  int count;
  int ball1,ball2,ball;
  cin >> count;
  for(int i=0;i<count;i++){
    ball1=0;ball2=0;
    for(int j=0;j<MAX;j++){
      cin >>ball;
      //      cout << ball << endl;
      if(!can_stack(ball1,ball2,ball)){
	cout << "NO";
	break;
      }
      else{
	if(ball2<ball){
	  ball2=ball;
	}
	else{
	  ball1 = ball;
	}
	if(j==MAX-1){
	  cout << "YES";
	}
      }
    }
    if(i!=count-1){
      cout << endl;
    }
  }
}

bool can_stack(int ball1,int ball2,int ball){
  return (ball1<ball || ball2 < ball);
}

C++: #include<stdio.h>
#include<string.h>
#include<iostream>
#include<ctype.h>
#include<queue>
//#include<bits/stdc++.h>
#include<algorithm>
using namespace std; 
int arr[1000];  
int flash; 
int leftt,rightt;   
void dfs(int n){ 
//	printf("%d %d %d\n",n,leftt,rightt);
//	getchar();
	if(n>10){
		flash=1;
		return;
	}
	if(flash==1||flash==2) return;
	if((arr[n]<leftt)&&(arr[n]<rightt)){
		flash=2;
		return;
	}
	int a,b,c;
	a=leftt;
	b=rightt;
	c=n;
	if(arr[n]>leftt){
		leftt=arr[n];
		dfs(n+1);
		if(flash) return;
		leftt=a;
		rightt=b;
		n=c;
		if(arr[n]>rightt){
			rightt=arr[n];
			dfs(n+1);
			if(flash) return;
			flash=2;
			return;
		}else{
			flash=2;
			return;
		}
	}else if(arr[n]>rightt){
		rightt=arr[n];
		dfs(n+1);
		if(flash) return;
		flash=2;
		return;
	}else{
		flash=2;
		return;
	}
}          
                                                                                                                                                                                                                                                                                                                                             
int main(){
	int t;
	while(scanf("%d",&t)!=EOF){
	while(t--){
	flash=0;
	for(int i=1;i<=10;i++){
	   scanf("%d",&arr[i]);
	}
	leftt=-1;
	rightt=-1;
	dfs(1);
	if(flash==1) printf("YES\n");
	 else printf("NO\n");
	}	
	}
	
    return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int data[10];
    while (n--) {
        for (int i = 0; i < 10; ++i) {
            cin >> data[i];
        }
        bool ans = true;
        int l, r;
        l = r = 0;
        for (int j = 0; j < 10; ++j) {
            if (data[j] > l)
                l = data[j];
            else if (data[j] > r)
                r = data[j];
            else {
                ans = false;
                break;
            }
        }
        if (ans)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <climits>
#define CAPACITY 9
using namespace std;
int b, c;

bool dfs(int pos, int ary[], bool flag) {
    if(pos < 0) {
        return(false);
    }
    
    flag = dfs(pos - 1, ary, flag);
    
    if(pos == CAPACITY) {
        flag = true;
    }
    if(ary[pos] > b) {
        b = ary[pos];
    } else if(ary[pos] > c) {
        c = ary[pos];
    } else {
        return(false);
    }
    
    return(flag);
}

int main(void) {
    int num;
    
    cin >> num;
    int ary[10];
    
    for(int r = 0; r < num; r++) {
        for(int c = 0; c < 10; c++) {
            cin >> ary[c];
        }
        b = ary[0];
        c = INT_MIN;
        if(dfs(CAPACITY, ary, true)) {
            cout << "YES";
        } else {
            cout << "NO";
        }
        cout << endl;
    }
    
    return(0);
}