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 <bits/stdc++.h>
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n][10];
    vector<int> b,c;
    rep(i,n)rep(j,10){
        cin >> a[i][j];
    }
    b.pb(0);
    c.pb(0);
    rep(i,n){
        bool flag = true;
        rep(j,10){
            int p1 = b[b.size()-1];
            int p2 = c[c.size()-1];
            int p = a[i][j];
            if(p < p1 && p < p2){
                cout << "NO" << endl;
                flag = false;
                break;
            }else if(p < p1 && p > p2){
                c.pb(p);
            }else if(p > p1 && p < p2){
                b.pb(p);
            }else{
                if(p1 < p2){
                    c.pb(p);
                }else{
                    b.pb(p);
                }
            }
        }
        if(flag){
            cout << "YES" << endl;
        }
        b.clear();
        c.clear();
        b.pb(0);
        c.pb(0);
    }
}

C++: #include<cstdio>

using namespace std;


//引数はそれぞれ、入力配列のカウント変数、a[]のカウント変数,b[]のカウント変数,答え配列,筒を意味するaとb配列,成功判定flg変数
bool tansaku(int count,int n1,int n2,int ans[],int a[],int b[],bool flg)
{
	//カウントが１０になったときは成功したとき
	if (count == 10)
	{
		return true;
	}
	//既にflgがtrueならさっさと返す
	if (flg == false)
	{
		//最初はn1は１である
		if (a[n1] < ans[count])		//１つ前の要素と比べている
		{
			//a[n1]にans[count]を格納
			//最初に足しておくと動作が正しくなる
			n1++;					
			//答えを格納
			a[n1] = ans[count];
			//入力された配列に使うカウント変数
			count++;
			//再帰関数
			bool hozon = tansaku(count,n1,n2,ans,a,b,flg);
			//trueだった場合falseで上書きしないように調整
			if (hozon == true)
			{
				flg = true;
			}
		}
		//ひとつ前の要素と比べている
		if (b[n2] < ans[count])
		{
			//先に足す
			n2++;
			//b[n2](最初はn2 = 1)に小さい順に入れていく
			b[n2] = ans[count];
			//関数の前でインクリメント
			count++;
			//再帰関数
			bool hozon = tansaku(count,n1,n2,ans,a,b,flg);
			//trueだった場合上書きしないようにする
			if (hozon == true)
			{
				flg = true;
			}
		}
	}

	return flg;
}


int main(void)
{
	//何回回すか
	int n = 0;
	//10個のボール
	int a[10] = {0};
	//関数で送るためのいらない変数
	int damy[20] = {0};
	bool ans_flg[100] = {false};

	scanf("%d",&n);
	//n回文の入力
	for (int i = 0;i < n;i++)
	{
		scanf("%d %d %d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);
		if (tansaku(0,0,0,a,damy,damy,false) == true)
		{
			ans_flg[i] = true;
		}
	}

	for (int i = 0;i < n;i++)
	{
		if (ans_flg[i] == true)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}

	return 0;
}

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

using namespace std;

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


  for(int q=0; q<n;q++) {
    
    vector <int> ball;
    
    ball.resize(10);
    for(int i=0;i<10;i++) cin >> ball[i];
    reverse(ball.begin(),ball.end());
    
    int a[10] = {0},b[11] = {0};
    a[0] = ball.back();
    ball.pop_back();
   int ac = 1;
   int bc = 1;
   int t,flg = 0;
   
   //    cout << "t:a:b" << endl;
   for(int i=0;i<9;i++) {
     
     t = ball.back();
     ball.pop_back();
     // cout << t <<":"<< a[ac-1]<<":" << b[bc-1]<<endl;
     
     if(t > a[ac-1] && a[ac-1] >= b[bc-1]) {
       a[ac] = t;
       ac++;
     }
     else if(t > b[bc-1]) {
       b[bc] = t;
       bc++;
     } else {
       flg = 1;
	break;
     }
    }
   
   if(flg == 0) cout << "YES" <<  endl;
   else cout << "NO" << endl;
   
   ball.clear();
   
  }

  return 0;

}
l.clear();

  }

  return 0;

}

C++: #include <iostream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
using namespace std;
#define XINF INT_MAX
#define INF 0x3FFFFFFF
#define MAXN 0x7fffffff
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define PF(X) push_front(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
#define PI  3.14159265358979
typedef long long ll;
typedef pair<int,int> PII;
typedef priority_queue<int,vector<int>,greater<int> > PQI;
typedef vector<PII> VII;
typedef vector<int> VI;
#define X first
#define Y second

queue<int> *st;
stack<int> *LQ;
stack<int> *RQ;
VI v; 

void dfs(int x)
{
	int flag=0;
	if(LQ->empty() || (!LQ->empty() && x>LQ->top()))
	{
		LQ->push(x);
		flag=1;
	}
	if((RQ->empty() || (!RQ->empty() && x>RQ->top())) && !flag)
	{
		RQ->push(x);
		flag=1;
	}
	if(!flag)
		return ;
	st->pop();
	dfs(st->front());
}
	

int main()
{
	ios::sync_with_stdio(false);
	int T;
	cin>>T;
	while(T--)
	{
		queue<int> stemp;  st=&stemp;
		stack<int> LQtemp; LQ=&LQtemp;
		stack<int> RQtemp; RQ=&RQtemp;
		REP(i,10)
		{
			int x;
			cin>>x;
			st->push(x);
		}
		dfs(st->front());
		/*cout<<endl;
		while(!LQ->empty())
		{
			int x=LQ->top();
			cout<<x<<endl;
			LQ->pop();
		}
		cout<<endl;
		while(!RQ->empty())
		{
			int x=RQ->top();
			cout<<x<<endl;
			RQ->pop();
		}*/
		if(st->empty())
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
#define rep(x,y) for(x=0;x<(y);++x)
void in();
void solve();
int bod[14];
int main()
{
	int t;
	cin>>t;
	int ti;
	rep(ti,t)
	{
		in();
		solve();
	} 
	return 0;
}
void in()
{
	int i;
	rep(i,10)
	{
		cin>>bod[i];
	}
}
void solve()
{
	int l=0,r=0,u;
	int le[11],ri[11];
	for(u=0;u<10;++u)
	{
		if(0==l)
		{
			le[0]=bod[u];
			++l;
		}
		else if(bod[u]>le[l-1])
		{
			if(0==r||le[l-1]>ri[r-1])
			{
				le[l]=bod[u];
				++l;
			}
			else if(bod[u]>ri[r-1])
			{
				ri[r]=bod[u];
				++r;
			}
		}
		else if(0==r||bod[u]>ri[r-1])
		{
			ri[r]=bod[u];
			++r;
		}
		else
		{
			cout<<"NO\n";
			return;
		}
	}
	cout<<"YES\n";
}

C++: // 2012/03/02 Tazoe

#include <iostream>
using namespace std;

bool DFS(int A[10], int i, int B, int C){
	if(i==10)
		return true;

	if(A[i]>B&&DFS(A, i+1, A[i], C))
		return true;

	if(A[i]>C&&DFS(A, i+1, B, A[i]))
		return true;

	return false;
}

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

	for(int i=0; i<N; i++){
		int A[10];
		for(int j=0; j<10; j++){
			cin >> A[j];
		}

		if(DFS(A, 0, 0, 0)){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<vector>
#include<queue>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>

using namespace std;

int x[10];

bool check( int i, int l, int r )
{
  bool retl = false, retr = false;
  
  if ( i == 10 )
    return true;

  if ( x[i] > l )
    retl = check( i+1, x[i], r );
  
  if ( x[i] > r )
    retr =  check( i+1, l, x[i] );

  return ( retl || retr );
}

int main()
{
  int n;
  cin >> n;
  
  for ( int i = 0; i < n; ++i )
    {
      for ( int j = 0; j < 10; ++j )
        {
          cin >> x[j];
        }
      if ( check( 1, x[0], -1 ) )
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    }
  
  return 0;
}