Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	for i := 0; i < n; i++ {
		a := -1
		b := -1
		ans := true
		// それぞれの筒の一番上にあるたまの数字に着目すればよい
		for j := 0; j < 10; j++ {
			x := nextInt()
			if x > a {
				a = x
			} else if x > b {
				b = x
			} else {
				ans = false
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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;
}

C++: #include <iostream>
using namespace std;
int ch[12],one,two=0,g,q;

int DFS(int g){
if(g == 10)
    {
        q=0;
        return 1;
    }
else
{
    for(int i = g; i < 10; i++){
            if(q==0)return 1;
            if(ch[i] > one)
                {
                    one = ch[i];
                    DFS(i+1);
                }
            else if( ch[i] > two)
                {
                    two = ch[i];
                    DFS(i+1);
                }
            else if(ch[i] < two && ch[i] < one)
                {
                    return 0;
                }
    }
return 0;
}
}
int main()
{
    int n;
    cin >> n;
    while(n--){
     for(int i = 0; i < 10; i++)
        cin >> ch[i];
     one = ch[0];
     q=1;
     if(DFS(1)) cout << "Yes" << endl;
     else cout << "NO" << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <algorithm>
#define HEIGHT 10

using namespace std;

int a[HEIGHT];

void solve(){
	bool f=true;
	int right,left;
	right = left = 0;
	for(int i=0;i<HEIGHT;i++){
		if(right<a[i] && left<a[i]){
			if(right<left){
				left = a[i];
			} else {
				right = a[i];
			}
		} else if(right<a[i]){
			right = a[i];
		} else if(left<a[i]){
			left = a[i];
		} else {
			f = false;
			break;
		}
	}
	if(f) printf("Yes\n");
	else printf("No\n");
}
			
int main(){
	
	int lp;
	scanf("%d",&lp);
	
	for(int i=0;i<lp;i++){
		for(int j=0;j<HEIGHT;j++){
			scanf(" %d",&a[j]);
		}
		solve();	
	}
	return 0;
}