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.h>
#include<vector>
#include<list>
#include<stdio.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
	int a,b;
	int n;
	int g;
	bool check;

	while(cin >> n){
		vector<int> ball;
		a = b = 0;
		check = true;
		rep(i,10){
			cin >> g;
			ball.insert( ball.begin(), g);
		}
		rep(i,10){
			if(a < ball.back()){
				a = ball.back();
				ball.pop_back();
			}else if(b < ball.back()){
				b = ball.back();
				ball.pop_back();
			}else{
				check = false;
			}
		}
		if(check) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main(){
  stack<int>a;
  stack<int>b;
  int n,m,s;
  cin>>n;
  for(int i=0;i<n;i++){
    s=0;
    a.push(0);
    b.push(0);
    for(int i=0;i<10;i++){
      cin>>m;
      if(m>a.top()){
	a.push(m);
      }
      else if(m>b.top()){
	b.push(m);
      }
      else s=1;
    }
    if(s==0)cout<<"YES"<<endl;
    else    cout<<"NO"<<endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<stack>
using namespace std;
stack<int>ss;
stack<int>ss2;
int main()
{
	int t,n,a;
	scanf("%d",&t);
	while (t--)
	{
		n=10;
		int f=0;
		while(n--)
		{
			scanf("%d",&a);
			if (f==0)
			{
				if (ss.empty())
				{
					ss.push(a);
				}
				else if (ss.top()<a)
				{
					ss.push(a);
				}
				else if (ss2.empty())
				{
					ss2.push(a);
				}
				else if (ss2.top()<a)
				{
					ss2.push(a);
				}
				else
				{
					f=1; 
				}
			}
		}
		if (f==1)
		{
			printf("NO\n");
		}
		else
		{
			printf("YES\n");
		}
	}
	return 0;
}

C++: import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		int n=sc.nextInt();
		sc.nextLine();
		for(int k=0; k<n; k++){
			String[] ss=sc.nextLine().split(" ");
			int[] a=new int[10];
			for(int i=0; i<10; i++)
				a[i]=Integer.parseInt(ss[i]);
			int x=0;
			for(int i=0; i<10; i++){
				if(a[i]>x){
					x=a[i];
					a[i]=-1;
				}
			}
			x=0;
			for(int i=0; i<10; i++){
				if(a[i]>x){
					x=a[i];
					a[i]=-1;
				}
			}
			boolean f=true;
			for(int i=0; i<10; i++)
				if(a[i]!=-1){
					f=false;
					break;
				}
			println(f?"YES":"NO");
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int b = 0, c = 0;
		int flag = 1;
		for (int j = 0; j < 10; j++){
			int k;
			cin >> k;
			if (b < k && c < k) {
				if (b > c) {
					b = k;
				} else {
					c = k;
				}
			} else if (b < k && c >= k) {
				b = k;
			} else if (b >= k && c < k) {
				c = k;
			} else{
				flag = 0;
				break;
			}
		}
		if (flag) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>


int N;
int a[100];
int left[100], right[100], flag;
int main()
{
    scanf("%d", &N);

   while(N--){

        for(int j = 0; j < 10; j++) scanf("%d", &a[j]);

        for(int j = 0; j < 1<<10; j++)
        {
            int l = 0, r = 0;
            flag = 1;
            for(int k = 1, x = 0; k < 1<<10; k<<=1, x++)
            {
                if(j & k)  left[l++] = a[x];
                else   right[r++] = a[x];

                if((l >= 2 && left[l-1] <= left[l-2]) ||(r >= 2 && right[r-1] <= right[r-2]))
                {
                    flag = 0;
                    break;
                }
            }

            if(flag) break;

        }
        if(flag) printf("YES\n");
        else printf("NO\n");
    }

    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

vector<int> a;
stack<int> b, c;

bool dfs(int i)
{
	if (i == 10) return true;

	bool res1 = false, res2 = false;

	if (b.empty()) {
		b.push(a[i]);
		res1 = dfs(i + 1);
		b.pop();
    }
    
    if(c.empty()) {
		c.push(a[i]);
		res2 = dfs(i + 1);
		c.pop();
    } 

    if (b.size() && c.size()) {
        if (b.top() < a[i]) {
            b.push(a[i]);
            res1 = dfs(i + 1);
            b.pop();
        }
        if (c.top() < a[i]) {
            c.push(a[i]);
            res2 = dfs(i + 1);
            c.pop();
        }
    }

	return res1 || res2;
}

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

	while (n--) {
		a.clear();
		while (b.size()) b.pop();
		while (c.size()) c.pop();

		for (int i = 0; i < 10; ++i) { int v; cin >> v; a.push_back(v); }

		if (dfs(0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

C++: #include <iostream>

using namespace std;

int caseCnt, numbers[10], curNum;
bool used[10], result;

int main(){
    cin >> caseCnt;

    while(caseCnt--){
        result = true;

        for(int i=0; i<10; ++i){
            cin >> numbers[i];
            used[i] = false;
        }
        curNum = numbers[0];
        used[0] = true;
        for(int i=1; i<10; ++i){
            if(numbers[i] > curNum){
                curNum = numbers[i];
                used[i] = true;
                //cout << "fk\n";
            }
        }

        bool first_not_used = true;
        for(int i=1; i<10; ++i){
            if(used[i] == false){
                if(first_not_used){
                    first_not_used = false;
                    curNum = numbers[i];
                    //cout << "curNum : " << curNum << endl;
                }else{
                    if(numbers[i] > curNum){
                        curNum = numbers[i];
                    }else{
                        result = false;
                        break;
                    }
                }
            }
        }
        if(result) cout << "YES\n";
        else       cout << "NO\n";
    }
    return 0;
}

C++: #include <cstdio>
#include <cstring>
using namespace std;

const int maxn = 15;
int an[maxn], bm[maxn];
int arr[maxn];
bool cnt;

void dfs(int n, int m, int k);

int main(){
    int t;
    scanf("%d", &t);
    while(t--){
        for(int i = 0; i < 10; ++i){
            scanf("%d", &arr[i]);
        }
        cnt = false;
        an[0] = arr[0];
        bm[0] = -1;
        dfs(0, 0, 1);

        if(cnt){
            puts("YES");
        }
        else{
            puts("NO");
        }
    }
    return 0;
}

void dfs(int n, int m, int k){
    if(k == 10){
        cnt = true;
        return ;
    }

    if(arr[k] < an[n] && arr[k] < bm[m]){
        return ;
    }

    if(arr[k] > an[n]){
        an[n+1] = arr[k];
        dfs(n+1, m, k+1);
    }
    if(arr[k] > bm[m]){
        bm[m+1] = arr[k];
        dfs(n, m+1, k+1);
    }
}