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 <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll; 
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;


ll n, a[100];
stack<int> vi1, vi2;

int main(){
	cin >> n;
	REP(i, n){
		REP(j, 10){
			cin >> a[j];
		}
		REP(j, 10){
			if (vi1.empty()){
				vi1.push(a[j]);
				continue;
			}
			if (vi2.empty()){
				if (vi1.top() > a[j]){
					vi2.push(vi1.top());
					vi1.pop();
					vi1.push(a[j]);
				}
				else{
					vi2.push(a[j]);
				}
				continue;
			}
			if (vi2.top() < a[j]){
				vi2.push(a[j]);
			}
			else{
				if (vi1.top() < a[j]){
					vi1.push(a[j]);
				}
				else{
					cout << "NO" << endl;
					break;
				}
			}
			if (j == 10 - 1){
				cout << "YES" << endl;
			}
		}
		while (!vi1.empty()){
			vi1.pop();
		}
		while (!vi2.empty()){
			vi2.pop();
		}
	}
}

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

using namespace std;



void solve(vector<int> left, vector<int> right, vector<int> all, int n) {
	bool flag = true;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						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)
			printf("YES\n");
		else
			printf("NO\n");
		flag = true;
	}
}

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


	int n;
	scanf("%d", &n);
	if (n <= 0) return -1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}	  

	solve(left, right, all, n);

	return 0;
}

C++: #include <iostream>
using namespace std;
int b, c, cnt, x[11];
void dfs(int i){
   if(x[i] > b){
       b = x[i];
       dfs(i+1);
       cnt++;
   }
   if(x[i] > c){
       c = x[i];
       dfs(i+1);
       cnt++;
   }
}

int main(void){
   int N;
   cin >> N;
   while(N != 0){
       b = 0;
       c = 0;
       cnt = 0;
       for(int i = 0; i < 10; i++){
           cin >> x[i];    
       }
       dfs(0);
       if(cnt == 11)   cout << "YES" << endl;
       else    cout << "NO" << endl;
       N--;
   }
   return 0;
}

C++: #include<stack>
#include<iostream>
#include<algorithm>
using namespace std;

stack<int> S1,S2;
int A[10];
bool flag;

int ball(int a){
	while (1){
		flag = false;
		cout << A[a] << endl;
		if (S1.top() < A[a]){
			S1.push(A[a]);
			a++; flag = true;
		}
		else if (S2.top() < A[a]){
			S2.push(A[a]);
			a++; flag = true;
		}
		if (flag == false) {
			return 0;
		}
		if (a == 10) {
			return 1;
		}
	}
}



int main(){
	int N;
	cin >> N;
	for (int i = 0; i < N; i++){
		for (int l = 0; l < 10; l++) cin >> A[l];
		S1.push(0);
		S2.push(0);
		int a = 0;
		if (ball(a)) cout << "YES" << endl;
		else cout << "NO" << endl;
		a = 0;
		while (!S1.empty()) S1.pop();
		while (!S2.empty()) S2.pop();
	}
	return 0;
}

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

using namespace std;

bool solve(stack<int> st1, stack<int> st2, int ball[10],int index){
	if(index == 10){
		return true;
	}
	if(st1.top() < ball[index]){
		st1.push(ball[index]);
		if(solve(st1,st2,ball,index+1)){
			return true;
		}else{
			st1.pop();
		}
	}
	if(st2.top() < ball[index]){
		st2.push(ball[index]);
		if(solve(st1,st2,ball,index+1)){
			return true;
		}else{
			st2.pop();
		}
	}
	return false;
}

int main(){
	stack<int> st1,st2;
	int ball[10];
	int n;
	cin >> n;
	for(int loop=0;loop<n;loop++){
		for(int i=0;i<10;i++){
			cin >> ball[i];
		}
		st1.push(0);
		st2.push(0);
		
		if(solve(st1,st2,ball,0)){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
}

C++: // https://onlinejudge.u-aizu.ac.jp/problems/0033
// 玉
// 1-10的序列，分成两组，让每一组都升序
// 虽然想让你用dfs，但是这个似乎直接贪心就可以了

#include <iostream>
#include <stack>

using namespace std;
int a[10];

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        for (int i = 0; i < 10; ++i)
            cin >> a[i];
        stack<int> q1;
        stack<int> q2;
        for (int i = 0; i < 10; ++i)
        {
            int t1, t2;
            if (q1.empty())
                t1 = 0;
            else
                t1 = q1.top();
            if (q2.empty())
                t2 = 0;
            else
                t2 = q2.top();
            if (t1 > a[i] && t2 > a[i])
            {
                cout << "NO" << endl;
                break;
            }
            else if (t1 < a[i] && t2 > a[i])
            {
                q1.push(a[i]);
            }
            else if (t1 > a[i] && t2 < a[i])
            {
                q2.push(a[i]);
            }
            else if (t1 < t2)
            {
                q2.push(a[i]);
            }
            else
            {
                q1.push(a[i]);
            }
            if (i == 9)
            {
                cout << "YES" << endl;
            }
        }
        
    }
    return 0;
}

C++: /*0ms,1008KB*/

#include<cstdio>
#include<cstring>

int a[15], l[15], r[15], t, i, j, lc, rc, cnt;
bool vis[15], flag;

bool solve()
{
	for (i = 0; i < 1024; ++i)
	{
		memset(l, 0, sizeof(l));
		memset(r, 0, sizeof(r));
		lc = rc = 0;
		for (cnt = 0, j = i; cnt < 10; ++cnt, j >>= 1)
		{
			if (j & 1) l[lc++] = a[cnt];
			else r[rc++] = a[cnt];
		}
		flag = true;
		for (j = 1; j < lc; ++j)
			if (l[j] < l[j - 1])
			{
				flag = false;
				break;
			}
		if (flag)
			for (j = 1; j < rc; ++j)
				if (r[j - 1] > r[j])
				{
					flag = false;
					break;
				}
		if (flag) return true;
	}
	return false;
}

int main()
{
	scanf("%d", &t);
	while (t--)
	{
		memset(vis, 0, sizeof(vis));
		for (i = 0; i < 10; ++i)
			scanf("%d", &a[i]);
		puts(solve() ? "YES" : "NO");
	}
	return 0;
}

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

int main() {
	int n;
	int d[10];
	int va[10];
	int vb[10];
	int trush;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> d[i];
		}

		int ca = 0, cb = 0;
		va[0] = d[0];
		ca++;
		if (d[1] > va[0]) {
			va[1] = d[1];
			ca++;
		}

		else {
			vb[0] = d[1];
			cb++;
		}

	for (int j = 2; j < 10; j++) {

			if (d[j] > va[ca-1]) {
				va[ca] = d[j];
				ca++;
			}

			else if (d[j] > vb[cb-1]) {
				vb[cb] = d[j];
				cb++;
			}

			else {
				trush = d[j];
			}

		}

	if (ca + cb == 10) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

		for (int i = 0; i < 10; i++) {
			va[i] = 0;
		}
		for (int i = 0; i < 10; i++) {
			vb[i] = 0;
		}
	}
	return 0;
}