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++: /*
 * AOJ 0033: Ball
 * ?¢????????????????1-10???10???????????????????????????????????\2????????????????????????????????\??????????????????????¢????????????????????????¨???
 * ?±????????´????
 * ?????????????????????????????\??§???????????¶???????´????????????\??°?????\????????¶??§????????????????¬????????????\???????????????????????????????????¶???????´???§????????????
 */

#include <cstdio>
#include <iostream>

using namespace std;

int a[10];


int main() {
  int T;
  cin >> T;
  while (T--) {
    bool ans = true;
    for (int i = 0; i < 10; ++i) {
      scanf("%d", &a[i]);
    }
    int l, r;
    l = r = 0;
    for (int i = 0; i < 10; ++i) {
      if (a[i] > l) {
        l = a[i];
      } else if (a[i] > r) {
        r = a[i];
      } else {
        ans = false;
        break;
      }
    }
    cout << (ans ? "YES" : "NO") << endl;
  }
  return 1;
}

C++: 
#include<stdio.h>

//探索再帰関数
bool tansaku(int count,int ans[],int a_max,int b_max,bool flg)
{
	//カウントが１０なら終了
	if (count == 10)
	{
		return true;
	}
	//trueじゃないなら探索を続ける
	if (flg == false)
	{
		//aの最大より新しいやつの方が大きいとき
		if (a_max < ans[count])
		{
			//aの上に格納
			a_max = ans[count];
			//答え配列のカウント変数をインクリメント
			count++;
			//再帰関数からの戻り値を格納
			bool hozon = tansaku(count,ans,a_max,b_max,flg);
			//trueを消さないように
			if (hozon == true)
			{
				flg = true;
			}
		}
		//bの最大より大きいとき
		if (b_max < ans[count])
		{
			//bに入力配列[count]を格納
			b_max = ans[count];
			count++;
			bool hozon = tansaku(count,ans,a_max,b_max,flg);
			if (hozon == true)
			{
				flg = true;
			}
		}
	}
	return flg;
}
int main(void)
{
	//回数を指定する変数
	int N = 0;
	//入力配列
	int a[10] = {0};
	//まとめて解答するflg
	bool ans_flg[100] = {false};
	scanf("%d",&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]);
		//count = 0、入力配列、a_max = 0,b_max = 0,flg = falseを送る
		if (tansaku(0,a,0,0,false) == true)
		{
			ans_flg[i] = true;
		}
	}
	//N回文の解答を出力
	for (int i = 0;i < N;i++)
	{
		if (ans_flg[i] == true)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	return 0;
}

C++: #include <iostream>

int main(void)
{
	int n;
	std::cin >> n;
	for(int j=0; j<n; j++)
	{
		int top[2]={0,0};
		for(int i=0; ; i++)
		{
			//std::cout << top[0] << top[1] << std::endl;
			int next;
			std::cin >> next;
			if((top[0] < next)&&(top[1] < next))
			{
				if(top[0] < top[1])
					top[1]=next;
				else
					top[0]=next;
			}
			else if(top[0] < next)
				top[0]=next;
			else if(top[1] < next)
				top[1]=next;
			else
			{
				std::cout << "NO" << std::endl;
				for(int k=1; k+i < 10; k++)
					std::cin >>next;
				break;
			}

			if(i==9)
			{
				std::cout << "YES" << std::endl;
				break;
			}
		}
	}
	return 0;
}

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

using namespace std;

int main(void){
	int n = 0;
	int a[10];
	stack<int> b, c;
	bool r = true;

	scanf("%d", &n);
	for(int i=0;i<n;++i){
		for(int j=0;j<10;++j){
			scanf("%d", a+j);
		}
		b = stack<int>();
		c = stack<int>();
		r = true;

		for(int j=0;j<10;++j){
			if(b.empty()){
				b.push(a[j]);
			}else if(c.empty()){
				c.push(a[j]);
			}else if(b.top() < a[j] && c.top() < a[j]){
				if(b.top() > c.top()){
					b.push(a[j]);
				}else{
					c.push(a[j]);
				}
			}else if(b.top() < a[j]){
				b.push(a[j]);
			}else if(c.top() <a[j]){
				c.push(a[j]);
			}else{
				r = false;
				break;
			}
		}
		puts(r ? "YES": "NO");
	}
	return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#define rep(i, n) for (int i=0; i<n; ++i)
#define FOR(i, a, b) for (int i=a; i<b; ++i)
#define pb(x) push_back(x)
#define ll long long
#define ul unsigned long long
#define dbg(x) cout  << #x << " : " << (x) << endl
#define out(x) cout << (x)
#define outl(x) cout << (x) << endl
#define int(n); int n; cin >> n;
#define long(n); long long n; cin >> n;
#define dbl(f); double f; cin >> f;
#define s(s); string s; cin >> s;
#define into(a, n) for (int i = 0; i < n; ++i) cin >> a[i]
using namespace std;

const int inf =1500000000;

int a[11],b[11],c[11];

bool dfs(int l,char x) {
  if (l>=10) return true;
  if (x=='b') {
    b[l]=a[l];
    rep(i, l) if(b[l]<b[i]) {b[l]=-1; return false;}
  }
  if (x=='c') {
    c[l]=a[l];
    rep(i, l) if(c[l]<c[i]) {c[l]=-1; return false;}
  }
  return  dfs(l+1,'b')||dfs(l+1,'c');
}

int main () {
  int(n);
  bool flg;
  rep(i, n) {
    flg=false;
    FOR(i, 1, 11) {
      cin>>a[i];
      b[i]=-1; c[i]=-1;
    }
    flg=dfs(0,'b')||dfs(0,'c');
    outl(flg?"YES":"NO");
  }
  return 0;
}

C++: #include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;
int main()
{
	//freopen("3.txt","r",stdin);
	int n;
	cin >> n;
	while(n--)
	{
		int a[11];
		int flag=1;
		int b=0,c=0;
		for(int i=0;i<10;i++)
			{
				cin >> a[i];
				if(a[i]>b)
				{
					b=a[i];
				}
				else if(a[i]>c)
				{
					c=a[i];
				}
				else
				{
					flag=0;
				}
			}
		if(flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
 }
}

C++: #include <stdio.h>
#include <vector>
#include <iostream>

using namespace std;

int main() {
	vector<int> left;
	vector<int> right;
	vector<int> all;

	bool flag = true;

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.data != NULL) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.data != NULL) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else
							flag = false;
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}

		if (flag)
			cout << "YES";
		else
			cout << "NO";
		flag = true;
	}
}

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

using namespace std;

bool solve(int bl, int cl,vector<int>& a, int i) {
    if( i == 9 ) return true;
    else {
        int t = a[i];
        return ( t > bl && solve(t,cl,a,i+1) ) ||
               ( t > cl && solve(bl,t,a,i+1) );
    }
}

int main(){
    int n;
    cin >> n;
    while(n--){
        vector<int> a(9);
        int fst;
        cin >> fst;
        for(int i=0;i<9;++i){
            cin >> a[i];
        }

        if( solve(fst, 0, a, 0) ) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}