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>
using namespace std;

int main(){
  bool ans;
  int n;
  int a[10],b,c;
  cin>>n;
  for(int i=0;i<n;i++){
    ans=true;
    for(int j=0;j<10;j++)cin>>a[j];
    b=c=0;
    for(int j=0;j<10;j++){
      if(a[j]<b&&a[j]<c){ans=false;break;
      }else if(b<a[j]&&c<a[j]){
	if(b>a[j])b=a[j];
	else c=a[j];
      }
      else if(b<a[j]&&c>a[j])b=a[j];
      else if(b>a[j]&&c<a[j])c=a[j];
    if(b>c)b=a[j];
    else c=a[j];
    }	
    
    if(ans==true)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;  
  }
  
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
static const int N = 10;

int main(){
  int input[N], left[N], right[N], leftNum, rightNum;
  int T;
  cin >> T;
  while(T--){
    for(int i = 0; i < N; i++)
      cin >> input[i];
    leftNum = 0;
    rightNum = 0;
    leftNum++;
    for(int i = 1; i < N; i++){
      if(left[leftNum - 1] < input[i]){
        left[leftNum] = input[i];
        leftNum++;
      } else {
        right[rightNum] = input[i];
        rightNum++;
      }
    }
    if(is_sorted(right, right + rightNum)){
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
long long MOD; template<class T> void mod(T &n){MOD=n;}
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long> 
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll


signed main(){
  int n; cin>>n;
  
  for(int c=0; c<n; c++){
    int a[15];
    for(int j=0; j<10; j++){
      cin>>a[j];
    }
    
    bool ans=false;
    for(int i=0; i<(1<<10); i++){
      vector<int> ve1,ve2;
      for(int j=0; j<10; j++){
        if(i&(1<<j)) ve1.push_back(a[j]);
        else ve2.push_back(a[j]);
      }
      

      bool no=false;
      for(int j=1; j<ve1.size(); j++){
        if(ve1[j]<ve1[j-1]){
          no=true;
          break;
        }
      }
      for(int j=1; j<ve2.size(); j++){
        if(ve2[j]<ve2[j-1]){
          no=true;
          break;
        }
      }
      if(!no){
        ans=true;
        break;
      }
      
    }
    
    if(ans) cout<<"YES"<<en;
    else cout<<"NO"<<en;
  }
}

C++: /*
* Filename:    aoj0033.cpp
* Desciption:  DFS
* Created:     2016-03-02
* Author:      JIngwei Xu [mail:xu_jingwei@outlook.com]
*
*/
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#define INT_MAX 2<<30
using namespace std;
//typedef long long ll;
int a[10],n;
int used[10];
bool ans=false;
bool check(){
	int ss=0;
	for (int i = 0; i < 10; i += 1)
	{
		if(used[i]==0){ss=a[i];break;}
	}
	if(ss==0)return true;
	for (int i = 0; i < 10; i += 1)
	{
		if(used[i]==0){
			if(a[i]<ss)return false;
			else ss=a[i];
		}
	}
	return true;
}
void dfs(int k,int rec){
	if(k==10){
		if(check())ans=true;
		return;
	}
	if(ans)return;
	if(a[k]>rec){
		used[k]=1;
		dfs(k+1,a[k]);
		if(ans)return;
		used[k]=0;
		dfs(k+1,rec);
		if(ans)return;
	}
	else{
		used[k]=0;
		dfs(k+1,rec);
	}
}
int main()
{
	scanf("%d",&n);
	for (int i = 0; i < n; i += 1)
	{
		for (int j = 0; j < 10; j += 1)
		{
			scanf("%d",&a[j]);
		}
		ans=false;
		for (int i = 0; i < 10; i += 1)
		{
			memset(used,0,sizeof(used));
			used[i]=1;
			dfs(i+1,a[i]);
			if(ans)break;
		}
		
		
		if(ans)printf("YES\n");
		else printf("NO\n");
		
	}
	return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  for(int i=0;i<n;i++) {
    int a=0;
    int b=0;
    bool failed = false;
    for(int i=0;i<10;i++) {
      int n;
      cin >> n;
      if(failed) {
        continue;
      }

      if(b <= a && a < n) {
        // cout << "1 " << a << ":" << b << ":" << n << endl;
        a = n;
      } else if (a < b && b < n) {
        // cout << "2 " << a << ":" << b << ":" << n << endl;
        b = n;
      } else if (b <= a && b < n) {
        // cout << "3 " << a << ":" << b << ":" << n << endl;
        b = n;
      } else if (a < b && a < n) {
        // cout << "4 " << a << ":" << b << ":" << n << endl;
        a = n;
      } else {
        // cout << "x " << a << ":" << b << ":" << n << endl;
        cout<<"NO"<<endl;
        failed = true;
        continue;
      }
      if(i==9) {
        cout<<"YES"<<endl;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)

int a[10];

//B:=B?????????????????° C*=C?????????????????° cnt:=??????????????°??????
bool dfs(int B, int C, int cnt){
	if(cnt == 10){
		return true;
	}
	if(B < a[cnt]){
		return dfs(a[cnt], C, cnt + 1);
	}
	if(C < a[cnt]){
		return dfs(B, a[cnt], cnt + 1);
	}
	if(B > a[cnt] && C > a[cnt]){
		return false;
	}
}
int main(void){
	int n; cin >> n;
	for (int i = 0; i < n; ++i){
		rep(j, 10) cin >> a[j];
		flag = false;
		dfs(0, 0, 0);
		if(flag) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int a[10],l,r;

bool dfs(int n)
{
	if(n>=10)return true;
	int x;
	if(a[n]>l)
	{
		x=l;
		l=a[n];
		if(dfs(n+1))return true;
		l=x;
	}
	if(a[n]>r)
	{
		x=r;
		r=a[n];
		if(dfs(n+1))return true;
		r=x;
	}
	return false;
}

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		for(int i=0;i<10;i++)scanf("%d",a+i);
		if(dfs(0))printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++:     #include <iostream>
    using namespace std;
     
    int N, H[10];
     
    void solve()
    {
      int big=0, small=0;
      bool flag = true;
      for (int i = 0; i < 10; i++)
      {
        if (H[i] > big) big = H[i];
        else if (H[i] > small) small = H[i];
        else
        {
          flag = false;
          break;
        }
      }
      if (flag) cout << "YES" << endl;
      else cout << "NO" << endl;
    }
     
    int main()
    {
      cin >> N;
      for (int i = 0; i < N; i++)
      {
        for (int j = 0; j < 10; j++) cin >> H[j];
        solve();
      }
      return 0;
    }