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 <vector>

using namespace std;

int ball_db[10];

void solve()
{
    vector<int> left;
    vector<int> right;

    left.push_back(0);
    right.push_back(0);

    for (int i = 0; i < 10; ++i) {
        if (ball_db[i] > left.back()) {
            left.push_back(ball_db[i]);
        } else if (ball_db[i] > right.back()) {
            right.push_back(ball_db[i]);
        } else {
            cout << "NO" << endl;
            return;
        }
    }

    if (left.size() + right.size() == 10 + 2) {
        cout << "YES" << endl;
    }
}

int main()
{
    int data_num;

    cin >> data_num;

    for (int i = 0; i < data_num; ++i) {
        for (int j = 0; j < 10; ++j) {
            cin >> ball_db[j];
        }
        solve();
    }


    return 0;
}

C++: #include<iostream>
using namespace std;
int r[10],l[10];
int data[10];

bool solve(int n,int rt,int lt)
{
	if(n==10)
	{
		for(int i = 1; i <= rt ; ++i)
		{
			if(r[i-1]>r[i]) return false;
		}
		for(int i = 1; i <= lt ; ++i)
		{
			if(l[i-1]>l[i]) return false;
		}
		return true;
	}

	r[rt]=data[n];
	if(solve(n+1,rt+1,lt)) return true;
	l[lt]=data[n];
	if(solve(n+1,rt,lt+1)) return true;

	return false;
}

int main()
{
	int n;
	cin>>n;
	while(n--)
	{
		for(int i = 0; i < 10; ++i)
		{
			cin>>data[i];
		}
		cout<<(solve(0,0,0)?"YES":"NO")<<endl;
	}
  return 0;
}

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

const int N = 10;
int a[N];
      
int main() {
  int Tc;
  cin >> Tc;
  while(Tc--) {
    for(int i = 0; i < N; ++i) cin >> a[i];
    string res = "NO";
    for(int b = 0; b < (1<<N); ++b) {
      int pre[2] = {-1,-1};
      for(int i = 0; i < N; ++i) {
	int t = ((b>>i)&1);
	if(pre[t] != -1 && pre[t] > a[i]) {
	  break;
	}
	pre[t] = a[i];
	if(i+1 == N) res = "YES";
      }
    }
    cout << res << endl;
  }
  return 0;
}

C++: include<cstdio>
include<iostream>
sing namespace std;
nt main()

   int T;
   scanf("%d",&T);
   while(T--)
   {
       int n1=0,n2=0,x,jd;
       for(int i=1;i<=10;++i)
       {
           scanf("%d",&x);
           if(x>n1){n1=x;continue;}
           if(x>n2){n2=x;continue;}
           jd=1;
       }
       if(jd) puts("NO");
       else   puts("YES");
   }

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

const int N = 15;
int arr[N];
bool flag;


void dfs(int left, int right, int cur){
    if (flag) return;

    if (cur == 10){
        flag = true;
        return;
    }

    if (left < arr[cur]){
        dfs(arr[cur], right, cur + 1);
    }
    if (right < arr[cur]){
        dfs(left, arr[cur], cur + 1);
    }
}

int main(){
    int t; cin >> t;
    while (t--){
        for (int i = 0; i < 10; ++ i) cin >> arr[i];
        flag = false;

        int left(0), right(0);

        dfs(left, right, 0);
        if (flag) cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}

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

using namespace std;

int ball_list[10];
int right_list[10];
int left_list[10];

bool flag;

void dfs(int right, int left){
  int count = right + left;

  if(count == 10){
    flag = true;
  }else{
    if(right == 0 || right_list[right-1] < ball_list[count]){
      if(right == 0){
        right_list[0] = ball_list[count];
      }else{
        right_list[right-1] = ball_list[count];
      }
      dfs(right+1, left);
    }
    if(left == 0 || left_list[left-1] < left_list[left]){
      if(left == 0){
        left_list[0] = ball_list[count];
      }else{
        left_list[left-1] = ball_list[count];
      }
      dfs(right, left+1);
    }
  }
}

int main(){
  int n;

  cin >> n;

  for(int i = 0; i < n; i++){
    flag = false;
    memset(right_list, 0, sizeof(right_list));
    memset(left_list, 0, sizeof(left_list));

    for(int j = 0; j < 10; j++){
      cin >> ball_list[j];
    }
    
    dfs(0, 0);

    if(flag){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }

  return 0;
}

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

bool decide(int *b){
	int first = 10000;
	int i;
	for( i = 0; i < 9; i++){
		if(b[i+1] < b[i])first = b[i+1];
		break;
	}
	for(i = i+1; i < 9; i++)
		if(b[i+1] < first)return false;

	return true;
}

int main(){
	int N;
	scanf("%d",&N);
	int (*a)[10];
	a = (int (*)[10])malloc(N*10*sizeof(int));
	for(int i = 0; i < N; i++)
		for(int j = 0; j < 10; j++)
			scanf("%d",&a[i][j]);

	for(int k = 0; k < N; k++){
		int *b = a[k];
		if(decide(b) == false)printf("NO\n");
		else printf("YES\n");
		}

	return 0;
}

C++: /*
 * AOJ 0033: Ball
 * ?¢????????????????1-10???10???????????????????????????????????\2????????????????????????????????\??????????????????????¢????????????????????????¨???
 * ?±???????DFS
 * ?????????????????????????????\??§???????????¶???????´????????????\??°?????\????????¶??§????????????
 */

#include <cstdio>
#include <iostream>

using namespace std;

int a[100], b[20][100];
int len[20];
bool ans;


void dfs(int step) {
  if (ans) return;
  if (step == 10) {
    ans = true;
    return;
  }
  for (int i = 0; i < 2; ++i) {
    if (len[i] == 0 || a[step] > b[i][len[i] - 1]) {
      b[i][len[i]++] = a[step];
      dfs(step + 1);
      --len[i];
    }
  }
}

void solve() {
  ans = false;
  for (int i = 0; i < 10; ++i) {
    cin >> a[i];
  }
  len[0] = len[1] = 0;
  dfs(0);
}

int main() {
  int T;
  cin >> T;
  while (T--) {
    solve();
    cout << (ans ? "YES" : "NO") << endl;
  }
  return 1;
}

C++: #include<iostream>
int main() {
	int n;
	std::cin >> n;
	for (int i = 0; i < n; i += 1) {
		int N[10];
		for (int i = 0; i < 10; i += 1) 
			std::cin >> N[i];
		if ((N[0] == 1 || N[1] == 1)&&(N[8]==10||N[9]==10))
			std::cout << "YES" << std::endl;
		else
			std::cout << "NO" << std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <stack>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int a[15];

int main()
{
	int n;
	cin >> n;
	while (n--) {
		for (int i = 0; i < 10; i++)	cin >> a[i];
		stack<int> s1, s2;
		s1.push(a[0]);
		
		bool flag = true;
		
		for (int i = 1; i < 10; i++) {
			if (s2.empty()) {
				if (s1.top() < a[i])	s1.push(a[i]);
				else	s2.push(a[i]);
			}
			else {
				if (s1.top() > a[i]) {
					if (s2.top() > a[i])	{
					   flag = false; break;
					}
					else	s2.push(a[i]);
				}
				else {
					if (s2.top() > a[i])	s1.push(a[i]);
					else {
						if (s1.top() > s2.top())	s1.push(a[i]);
						else	s2.push(a[i]);
					}
				}
			}
		}
		if (flag)	cout << "YES\n";
		else	cout << "NO\n";
	}
	return 0;
}