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 "bits/stdc++.h"
using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int long long
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct P
{
	int x, y;
	P(int x,int y):x(x),y(y){}
	P() :P(-1, -1) {}
};

int A[10];
int N;

bool solve()
{
	vector<int> va, vb;
	va.push_back(0), vb.push_back(0);
	rep(i, 0, 10)
	{
		if (va.back() < A[i])
		{
			va.push_back(A[i]);
		}
		else if (vb.back() < A[i])
		{
			vb.push_back(A[i]);
		}
		else
		{
			return false;
		}
	}
	return true;
}

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	rep(i, 0, N)
	{
		rep(j, 0, 10)
		{
			cin >> A[j];
		}
		cout << (solve() ? "YES" : "NO") << endl;
	}

	return 0;
}

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

std::string answer;
std::vector<int> input;

void dfs(int i, std::vector<int> L, std::vector<int> R){
	int L_flag, R_flag;
	std::vector<int> Add_L, Add_R;

	if(answer.compare("YES")==0 || i > 9) return;

	std::copy(L.begin(), L.end(), std::back_inserter(Add_L));
	std::copy(R.begin(), R.end(), std::back_inserter(Add_R));

	Add_L.insert(Add_L.end(), input[i]);
	Add_R.insert(Add_R.end(), input[i]);
	i++;

	L_flag = R_flag = 0;

	if(Add_L.size()>1){
		for(unsigned int j=0; j<Add_L.size()-1; j++){
			if(Add_L[j]>Add_L[j+1]){
				L_flag = 1;
				break;
			}
		}
	}
	if(Add_R.size()>1){
		for(unsigned int j=0; j<Add_R.size()-1; j++){
			if(Add_R[j]>Add_R[j+1]){
				R_flag = 1;
				break;
			}
		}
	}
	
	if(L_flag>0 && R_flag>0) { return; }
	if(L_flag==0) {
		if(i==10){
			answer = "YES";
			return;
		}
		else{
			dfs(i, Add_L, R);
		}
	}
	else if(R_flag==0){
		if(i==10){
			answer = "YES";
			return;
		}
		else{
			dfs(i, L, Add_R);
		}
	}
}

int main(void){
	int n, number;
	std::cin >> n;

	for(int i=0;i<n;i++){
		input.clear();
		
		for(int j=0;j<10;j++){
			std::cin >> number;
			input.insert(input.end(), number);
		}
		std::vector<int> left, right;

		answer = "CHECK";
		
		dfs(0, left, right);
		if(answer.compare("CHECK")==0) answer="NO";
		std::cout << answer << std::endl;
	}
	return 0;
}

C++: def s(a,i,b,c):
	return  b==sorted(b) and c==sorted(c) if i==10 else s(a,i+1,b+[a[i]],c) or s(a,i+1,b,c+[a[i]])
	
for roop in range(int(raw_input())):
	print "YES" if s(map(int,raw_input().split()),0,[],[]) else "NO"

C++: #include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
static const int MAX_N = 10;
int a[MAX_N] = {0};

bool dfs(int a[],vector<int> r,vector<int> l,int i){
	if(i==MAX_N)return true;
	if(r.size()==0 || r[r.size()-1]<a[i]){
		r.push_back(a[i]);
		return solve(a,r,l,i+1);
	}
	if(l.size()==0 || l[l.size()-1]<a[i]){
		l.push_back(a[i]);
		return solve(a,r,l,i+1);
	}
	return false;
}


int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){//input
			cin>>a[j];
		}
		vector<int> r;
		vector<int> l;
		if dfs(a,r,l,0){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
}

C++: /*
 * AOJ 0033: Ball
 * 题意：序号为1-10的10个球，按一定排列顺序进入2个队列之一，最终每队入队球的序号都为增序的方案是否存在。
 * 类型：贪心
 * 算法：对于每个球，若大于队列顶端元素，则可以记录该情况并继续递归。每次优先加入左边，可保证左边的顶端元素大于右边。
 */

#include <iostream>

using namespace std;

int balls[10];

int main() {
  //每次就先看左边能不能放，能放就放入，否则再看右边，右边也不能放，则不存在方案
  int n;
  cin >> n;
  while (n--) {
    for (int i = 0; i < 10; i++) cin >> balls[i];
    int l = 0, r = 0;
    bool flag = true;
    for (int i = 0; i < 10; i++) {
      if (balls[i] > l) {
        l = balls[i];
      } else if (balls[i] > r) {
        r = balls[i];
      } else {
        flag = false;
        break;
      }
    }
    if (flag) cout << "NO" << endl;
    else cout << "YES" << endl;
  }
}



// int a[10];


// int main() {
//   int T;
//   scanf("%d", &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;
//       }
//     }
//     printf("%s\n", ans ? "YES" : "NO");
//   }
//   return 0;
// }

C++: #include<iostream>
using namespace std;
int main(){
  int N,m;
  cin>>N;
  while(N--){
    int B,C=0,i=0;
    bool f=true;
    cin>>B;
    while(++i<10){
      cin>>m;
      if(B>m&&C>m){
	f=false;break;
      }else if(B<m&&C>m){
	B=m;
      }else if(B>m&&C<m){
	C=m;
      }else{
	if(B>C)
	  B=m;
	else
	  C=m;
      }
    }
    cout<<(f?"YES":"NO")<<endl;
  }
  return 0;
}

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

using namespace std;

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


  for(int q=0; q<n;q++) {
    
    vector <int> ball;
    
    ball.resize(10);
    for(int i=0;i<10;i++) cin >> ball[i];
    reverse(ball.begin(),ball.end());
    
    int a[10],b[11] = {0};
    a[0] = ball.back();
    ball.pop_back();
   int ac = 1;
   int bc = 1;
    int t, flg = 0;
    
    while(ball.empty() == false) {

      t = ball.back();
      ball.pop_back();
      // cout << t << endl;

      if(t > a[ac-1] && a[ac-1] >= b[bc-1]) {
	a[ac] = t;
	ac++;
      }
      else if(t > b[bc-1]) {
	b[bc] = t;
	bc++;
      } else break;
    }

    //  for(int i=0;i<ac;i++) cout << a[i] << endl;

    if(ball.empty() == true) cout << "YES" << endl;
    else cout << "NO" << endl;

    ball.clear();

  }

  return 0;

}

C++: #include<cstdio>
#include<algorithm>

using namespace std;

int N;
int l[15];
int b,c;
//int res[1000000000000];


void solve(int k){
  for(int i=0;i<10;i++){
    if(b<l[i] && c<l[i]){
      if(l[i]-b < l[i]-c) b=l[i];
      else c=l[i];
    }
    else if(b<l[i] && c>l[i]) b=l[i];
    else if(b>l[i] && c<l[i]) c=l[i];
    else{
  //    res[k]=0;
      printf("NO\n");
      return;
    }
  }
  printf("YES\n");
  return;
}


int main(){
  scanf("%d",&N);

  for(int i=0;i<N;i++){
    b,c=0;
    scanf("%d%d%d%d%d%d%d%d%d%d",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9]);
    solve(i);
  }

  /*for(int i=0;i<N;i++){
    if(res[i]==0) printf("NO\n");
    else printf("YES\n");
  }
*/

  return 0;
}

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

int ary[20];
int main(){
	int N,b=0,c=0;
	cin>>N;
	for(int i=1;i<=N;i++){
		b=c=0;
		for(int j=1;j<=10;j++){
			cin>>ary[j];
		}
		bool fla=true;
		for(int j=1;j<=10;j++){
			if(b<c) swap(b,c);
			if(ary[j]>b) b=ary[j];
			else if(ary[j]>c) c=ary[j];
			else{
				fla=false;
				break;
			}
		}
		if(fla) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}