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<vector>
#include<iostream>
using namespace std;
const int maxn=15;
int sum[maxn];
bool check(int i,vector<int> &left,vector<int> &right)
{
	int a=left.size()-1,b=right.size()-1;
	if(i==10&&left[a-1]<left[a]&&right[b-1]<right[b])
		return true;
	if(a>=1)
	{
		if(left[a-1]<left[a])
		{
	left.push_back(sum[i]);
	if(check(i+1,left,right))
		return true;
		}
		else
			return false;
	}
	else
	{
		left.push_back(sum[i]);
	if(check(i+1,left,right))
		return true;
	}
	left.pop_back();
	if(b>=1)
	{
		if(right[b-1]<right[b])
		{
			right.push_back(sum[i]);
	if(check(i+1,left,right))
		return true;
		}
		else
			return false;
	}
	else
	{
	right.push_back(sum[i]);
	if(check(i+1,left,right))
		return true;
	}
	right.pop_back();
	return false;
}
int main()
{
	int N;
	cin>>N;
	while(N--)
	{
		vector<int> left,right;
		for(int i=0;i<10;i++)
			cin>>sum[i];
		if(check(0,left,right))
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

int main() {
	int n;
	cin>>n;
	while (n--){
	bool yes=true;
		stack<int> s1;
		stack<int> s2;
		s1.push(0);
		s2.push(0);
		REP(i, 10){
			int a;
			cin >> a;
			if (s1.top() <= s2.top()){
				if (s1.top() < a){
					s1.push(a);
					continue;
					}
			}
			if (s2.top() < a){
					s2.push(a);
					continue;
			}
			if (s1.top() < a){
				s1.push(a);
				continue;
			}
			yes=false;
		}
		if (yes)
			cout << "YES"<<endl;
			else
				cout << "NO" << endl;
	}
	return 0;
}

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

using namespace std;

constexpr int bn = 10;
int B[bn];
int main(){
  int testnum;
  cin >> testnum;
  for(int t = 0;t<testnum;++t){
    for(int i=0;i<bn;++i){
      cin >> B[i];
    }
    int i;
    for(i=0;i<(1<<bn);++i){
      vector<int> left,right;
      left.push_back(-1);
      left.push_back(0);
      right.push_back(-1);
      right.push_back(0);
      for(int j=0;j<bn;++j){
        if((1<<j)&i){
          left.push_back(B[j]);
        }else{
          right.push_back(B[j]);
        }
      }
      bool is_ordered=true;
      for(int j=0;j<left.size()-1;++j){
        if(left[j]>left[j+1]) is_ordered = false;
      }
      for(int j=0;j<right.size()-1;++j){
        if(right[j]>right[j+1]) is_ordered = false;
      }
      if(is_ordered){
        break;
      }
    }
    if(i==(1<<bn)){
      cout << "NO" << endl;
    }else{
      cout << "YES" << endl;
    }
  }

}

C++: #include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int ball[15], success, B[15], C[15];

void dfs(int lb, int lc, int qiu) {
	if (success)//找到一种可行方案 就可以了 不必再递归
		return ;
	//如果确定【11】 最多就【10】 说明已经确定了一种方案  现在看可不可行
	if (qiu > 10) {
		int flag = 1;
		for (int i = 0; i < lb - 1; ++i) {
			if (B[i] >= B[i + 1]) {
				flag = 0;
				break;
			}
		}
		for (int i = 0; i < lc - 1; ++i) {
			if (C[i] >= C[i + 1]) {
				flag = 0;
				break;
			}
		}
		if (flag) {
			success = 1;
		}
		return;
	}

	B[lb] = ball[qiu];
	dfs(lb + 1, lc, qiu + 1);
	C[lc] = ball[qiu];
	dfs(lb, lc + 1, qiu + 1);

}

int main() {
	int n;
	scanf("%d", &n);
	while (n--) {
		for (int i = 1; i <= 10; ++i) {
			scanf("%d", &ball[i]);
		}
		success = 0;
		dfs(0, 0, 1);//代表现在B C没球  现在看ball【1】去哪
		if (success)
			puts("YES");
		else
			puts("NO");
	}

	return 0;
}

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

int n;
int a[1000];
int a1[1000];
int a2[1000];
void dfs(int s,int s1, int s2){
    if(s==10){
        return ;
    }
    if(s1==0 && s2==0){
        a1[s1]=a[s];
        dfs(s+1,s1+1,s2);
    }else{
        if(s1==0){
            if(a2[s2-1]<a[s]){
                a2[s2] = a[s];
                dfs(s+1,s1,s2+1);
            }else{
                a1[s1] = a[s];
                dfs(s+1,s1+1,s2);
            }
        }else if(s2==0){
            if(a1[s1-1]<a[s]){
                a1[s1] = a[s];
                dfs(s+1,s1+1,s2);
            }else{
                a2[s2] = a[s];
                dfs(s+1,s1,s2+1);
            }
        }else{
            if(a1[s1-1]<a[s]){
                a1[s1] = a[s];
                dfs(s+1,s1+1,s2);
            }else if(a2[s2-1]<a[s]){
                a2[s2] = a[s];
                dfs(s+1,s1,s2+1);
            }else{
                return ;
            }
        }
    }
}
int main(){
    while(~scanf("%d",&n)){
        while(n--){
            for(int i=0;i<10;i++){
                scanf("%d",&a[i]);
            }
            memset(a1,-1,sizeof(a1));
            memset(a2,-1,sizeof(a2));
            dfs(0,0,0);
            int i=0,j=0;
            for(;;i++){
                if(a1[i]==-1){
                    break;
                }
            }
            for(;;j++){
                if(a2[j]==-1){
                    break;
                }
            }
            if(i+j==10){
                printf("YES\n");
            }else{
                printf("NO\n");
            }
        }
    }
}

C++: #include <stdio.h>

int main(void)
{
	int tubeM[10];
	int tube1[10], tube2[9];
	int i, j, k;
	int n;
	int ans;
	
	for (i = 0; i < 9; i++){
		tube2[i] = 0;
	}
	
	scanf("%d", &n);
	
	while(n){
		for (i = 0; i < 10; i++){
			scanf("%d", &tubeM[i]);
		}
		
		tube1[0] = tubeM[0];
		for (i = 1, j = 0, k = 0; i < 10; i++){
			if (tubeM[i] > tube1[j]){
				j++;
			}
			else {
				tube2[k] = tubeM[i];
				k++;
			}
		}
		
		ans = 0;
		for (i = 1; tube2[i] != 0; i++){
			if (tube2[i - 1] > tube2[i]){
				ans = 1;
				break;
			}
		}
		
		if (ans == 0){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
		
		n--;
	}
	
	return (0);
}

C++: //AC
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0033
//dfs
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int res = 0;
int num[11];
int T;
int B = 0, C = 0;
void d(int i) {
	if (i == 10) return;
	if (num[i] > B) {
		 B = num[i];
		res++;
	}else if(num[i] > C){
		C = num[i];
		res++;
	}
	d(i + 1);
}
int main() {
	
	while (scanf("%d", &T)!= EOF) {
		
		while (T--) {
			C=B=res = 0;
			for (int i = 0; i < 10; i++) {
				scanf("%d", &num[i]);
			}
			d(0);
			
			printf("%s\n", res==10?"YES":"NO");
		}
	}
	return 0;
}