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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

const int n = 10;
int t;
int a, b, c;

int main()
{
  cin >> t;

  while(t--){
    bool ok = true;
    b = c = 0;
    rep(i, n){
      cin >> a;
      //if(b > c) swap(b, c);
      if(a > c){ c = a;  continue; }
      if(a > b){ b = a;  continue; }
      ok = false;
      break;
    }
    puts(ok ? "YES" : "NO");
  }

  return 0;
}

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

int n;
int a[10];
vector<int> l, r;
vector<int> emp;

bool dfs(int p){
	printf("p=%d\n", p);
	/*
	printf("l ");
	for(int i=0; i<l.size(); i++){
		printf("%d ", l[i]);
	}
	printf("\nr ");
	for(int i=0; i<r.size(); i++){
		printf("%d ", r[i]);
	}
	printf("\n");
*/
	if(p == 10) return true;
	l.push_back(a[p]);
	if(l.size() == 1 || l[l.size() - 2] < l[l.size() - 1]){
		return dfs(p+1);
	}else{
		l.pop_back();
		r.push_back(a[p]);
		if(r.size() == 1 || r[r.size() - 2] < r[r.size() - 1]){
			return dfs(p+1);
		}else{
			r.pop_back();
			return false;
		}
	}
}

int main(){
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		l = emp;
		r = emp;
		for(int j=0; j<10; j++){
			scanf("%d", &a[j]);
		}
		if(dfs(0)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

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

int main()
{
	queue<int> a;  // 開口部
	int n;
	int ball = 10;
	cin>>n;
	while( n-- > 0){
		int b=0, c=0;
		int k;
		for(int i=0;i<ball;i++){
			cin>>k;
			a.push( k );
		}
		
		// 最初の一つをbに入れておく
		b = a.front();
		a.pop();
		
		for(int i=0;i<ball-1;i++){
			if( a.front() > b && a.front() > c){
				if( a.front() - b > a.front() - c){
					c = a.front();
				}else{
					b = a.front();
				}
			}else if( a.front() > b){
				b = a.front();
			}else if( a.front() > c){
				c = a.front();
			}else{  // ゲームオーバー
				cout<<"NO"<<endl;
				while(1){
					if( a.empty()){
						break;
					}else{
						a.pop();
					}
				}
				break;
			}
			
			a.pop();
			if( a.empty()){
				cout<<"YES"<<endl;
				while(1){
					if( a.empty()){
						break;
					}else{
						a.pop();
					}
				}
			}
		}
	}
	return 0;
}

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

int main()
{
        int n;
        int b = 0;
        int c = 0;
        int d = 0;
        int A[10] = {};
        int B[10] = {};
        int C[10] = {};
        cin >> n;
        for (int i = 0;i < n;i++) {
                for (int j = 0;j < 10;j++) {
                        cin >> A[j];
                }

                for (int j = 0;j < 10;j++) {
                        if (d == 0) {
                                if (j == 0) {
                                        B[0] = A[0];
                                        b++;
                                }
                                if ((A[j] > B[b]) && (B[b] > C[c])) {
                                        B[b] = A[j];
                                        b++;
                                }
                                if (A[j] > C[c]) {
                                        C[c] = A[j];
                                        c++;
                                }
                                if ((A[j] < B[b - 1]) && (A[j] < C[c - 1])) {
                                        cout << "NO" << endl;
                                        d = 1;
                                }
                        }
                }
                if (d == 0) {
                        cout << "YES" << endl;
                }
                d = 0;
        }
        return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int ball[11];
    int n;
    int left = 0, right = 0;
    cin >> n;
    while(n--){
        for(int i = 0; i < 10; ++i) cin >> ball[i];
        bool flag = true;
        for(int i = 0; i < 10; ++i){
            int dl = ball[i] - left, dr = ball[i] - right;
            if(((dl >> 31) & 1) && ((dr >> 31) & 1)){
                flag = false;
                break;
            }
            else if(((dl >> 31) & 1) || ((dr >> 31) & 1)){
                if((dl >> 31) & 1) right = ball[i];
                else left = ball[i];
            }
            else{
                if(dl > dr) right = ball[i];
                else left = ball[i];
            }
        }
        cout << (flag ? "YES" : "NO") << endl;
    }
    return 0;
}

C++: //貪欲法(嘘解法かも…)
#include<iostream>
using namespace std;

int corn1,corn2;
bool flag;

int main(){
	int n,i,j;
	int t;
	
	cin >> n;
	for( i = 0;i < n;i++ ){
		corn1 = 0;
		corn2 = 0;
		flag = true;
		for( j = 0;j < 10;j++ ){
			cin >> t;
			
			if( corn1 < t )
				corn1 = t;
			else if( corn2 < t )
				corn2 = t;
			else
				flag = false;
		}
		if( flag )
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

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

using namespace std;

#define N 10

int main(){
  int tc; //test case
  cin >> tc;

  while(tc-->0){
    //maximun 1024 pattern. try all

    int n[10];
    for(int i=0; i<N; i++){ scanf("%d", &n[i]); }

    int b, c; //tube
    bool ans = false;
    for(int i=0; i<(1<<N); i++){
      int bit=i; b=c=0;
      for(int j=0; j<N; j++){
	if(bit%2==0){ // to B
	  if(b < n[j]) b=n[j];
	  else break;
	} else { // to C
	  if(c < n[j]) c=n[j];
	  else break;
	}
	if(j==N-1){
	  ans=true;
	  goto OUT;
	}
	bit /= 2;
      }
    }

  OUT:
    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;

  }
}

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

using namespace std;

int a[10];

bool dfs(int i, int left, int right) {
  if(i == 10) { return true; }

  bool ans = false;
  if(left < a[i]) {
    ans = dfs(i+1, a[i], right);
  }
  if(right < a[i]) {
    ans = dfs(i+1, left, a[i]);
  }
  return ans;
}

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

  for(int i = 0; i < n; i++) {
    for(int j = 0; j < 10; j++) {
      scanf("%d", &a[j]);
    }
    cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int a[10];
bool dfs(int i,int j,int k){
	if(k==10||(i<a[k]&&dfs(a[k],j,k+1))||(j<a[k]&&dfs(i,a[k],k+1)))return true;
	return false;
}
int main() {
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		for(int j=0;j<10;j++)cin>>a[j];
		cout<<(dfs(0,0,0)?"YES":"NO");
	}
	return 0;
}