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<math.h>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<iomanip>
using namespace std;
#define INF 1<<20

struct edge{
	int to;
	int cost;
	edge() {};
	edge(int a, int b) {
		to = a;
		cost = b;
	}
};

struct Node {
	int pos;
	int cost;
	Node() {};
	Node(int a, int b) {
		pos = a;
		cost = b;
	}
	bool operator <(const Node& rhs) const {
		return cost > rhs.cost;
	}
};

void dijkistra(int st, int TO,int V,vector<vector<edge> > graph) {
	priority_queue<Node> q;
	vector<int> d(V);
	for (int i = 0;i < V;i++) {
		d[i] = INF;
	}
	d[st] = 0;
	q.push(Node(st, 0));
	while (!q.empty()) {
		Node s = q.top(); q.pop();
		int pos = s.pos;
		for (int i = 0;i < graph[pos].size();i++) {
			int to = graph[pos][i].to;
			int cost = graph[pos][i].cost;
			if (d[pos] + cost < d[to]) {
				d[to] = d[pos] + cost;
				q.push(Node(to, d[to]));
			}

		}
	}
	cout << d[TO] << endl;
}
int partition(int A[],int p, int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p;j < r;j++) {
		if (x >= A[j]) {
			i = i + 1;
			swap(A[i], A[j]);
		}
	}
		swap(A[i + 1], A[r]);
		return i + 1;
}
void quicksort(int A[], int p, int r) {
	if (p < r) {
		int q = partition(A, p, r);
		quicksort(A, p, q-1);
		quicksort(A, q + 1, r);
	}
}

int getNumberOfCoin(int C[],int n,int m) {
	int T[50000];
	for (int j = 0;j <= n;j++) {
		T[j] = INF;
	}
	T[0] = 0;
	for (int i = 0;i < m;i++) {
		for (int j = 0;j <= n;j++) {
			if (j - C[i] >=0  ) {
				T[j] = min(T[j], T[j - C[i]] + 1);
			}
		}
	}
	return T[n];
}
int knapsack(int w, int n,int* v,int* ww) {
	int W[101][10001];
		for (int j = 0;j <= w;j++) {
			W[0][j] = 0;
		}
	for (int i = 0;i < n;i++) {
		for (int k = 0;k < n;k++){
			for (int j = 0;j <= w;j++) {
				if (j - ww[k] < 0) {
					W[i + 1][j] = W[i][j];
				}
				if (j - ww[i] >= 0) {
					W[i + 1][j] = max(W[i][j], W[i][j - ww[k]] + v[k]);

				}
			}
		}
	}
	return W[n][w];
}
int fib(int n) {
	vector<int> v(n+1);
	v[0] = 1;
	v[1] = 1;
	for (int i = 2;i < n+1;i++) {
		v[i] = v[i - 2] + v[i - 1];
	}
	return v[n];
}
int isPrime(int x) {
	if (x <= 1) return false;
	if (x>2 && x % 2 == 0) return false;
	for (int i = 2;i <= sqrt(x);i++) {
		if (x%i == 0) {
			return false;
		}
	}
	if (x == 2) return true;
	return true;
}
int main() {
	int a[10];
	int n;
	cin >> n;
	for (int i = 0;i < n;i++) {
		bool flag = false;
		for (int j = 0;j < 10;j++) cin >> a[j];
		for (int j = 0;j < (1 << 10);j++) {
			int max1 = 0;
			int max2 = 0;
			for (int k = 0;k < 10;k++) {
				if (j >> k & 1) {
					if (a[k] > max1) max1 = a[k];
					else break;
				}
				else {
					if (a[k] > max2) max2 = a[k];
					else break;
				}
				if (k == 9) flag = true;
			}
			
		}
		if (flag) cout << "YES" << endl;
		else cout << "NO" << endl;
	}


	}

C++: #include <iostream>

using namespace std;

bool all_dropped_between(bool* dropped, int lower, int upper){
  if (lower == 0)
    return all_dropped_between(dropped, 1, upper);
  if (lower == upper - 1)
    return true;
  else
    return dropped[lower - 1] && all_dropped_between(dropped, lower + 1, upper);
}

int main(){
  int n;
  bool dropped[10];

  cin >> n;
  while(n--){
    for(int i=0; i<10; i++){
      dropped[i] = false;
    }

    int b = 0, c = 0;
    int a[10];
    for(int i=0; i<10; i++){
      cin >> a[i];
    }

    for(int i=0; i<10; i++){
      dropped[a[i] - 1] = true;

      if(b < a[i] && c < a[i]){
        if(b < c)
          c = a[i];
        else
          b = a[i];
      }
      else if(b < a[i]){
        if(!all_dropped_between(dropped, b, a[i])){
          cout << "NO" << endl;
          break;
        }
        else
          b = a[i];
      }
      else if(c < a[i]){
        if(!all_dropped_between(dropped, c, a[i])){
          cout << "NO" << endl;
          break;
        }
        else
          c = a[i];
      }

      if(i == 9)
        cout << "YES" << endl;
    }
  }
}

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

#include <string.h>

int a[10];

int memo[10][10+1][10+1];

int search(int i, int j, int k)
{
  if (memo[i][j][k] >= 0)
    return memo[i][j][k];
  
  if (i == 9)
    return memo[i][j][k] = a[i];

  int r = 0;

  if (a[i] > j)
    r = std::max(search(i + 1, a[i], k), r);
		 
  if (a[i] > k)
    r = std::max(search(i + 1, j, a[i]), r);
  
  return memo[i][j][k] = r;
}

int main(int argc, char** argv)
{
  int N;

  std::cin >> N;

  while (N --) {
    for (int i = 0; i < 10; i ++)
      std::cin >> a[i];

    memset(memo, -1, sizeof(memo));

    std::cout << (search(0, 0, 0) ? "YES" : "NO") << std::endl;
  }
}

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

int main() {
	int n;
	cin >> n;
	for ( int i = 0; i < n; i++ ){
		deque<int>b,c;
		bool endflag = false;
		int dummy;
		cin >> dummy;
		b.push_back( dummy );
		cin >> dummy;
		c.push_back( dummy );
		for ( int j = 0; j < 8; j++ ){
			cin >> dummy;
			if ( !endflag ) {
				if ( c.size() - 1 ) {
					if ( b[b.size() -1] > c[c.size() -1] ) {
						if ( dummy > b[b.size()-1] )	b.push_back( dummy );
						else if ( dummy > c[c.size()-1] )	c.push_back( dummy );
						else {
							cout << "NO" << endl;
							endflag = true;
						}
					} else {
						if ( dummy > c[c.size()-1] )	c.push_back( dummy );
						else if ( dummy > b[b.size()-1] )	b.push_back( dummy );
						else {
							cout << "NO" << endl;
							endflag = true;
						}
					}
				} else {
					if ( dummy > b[b.size()-1] )	b.push_back( dummy );
					else	c.push_back( dummy );
				}
			}
		}
		if( !endflag )	cout << "YES" << endl;
	}
	
	return 0;
}

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

using namespace std;

int main() {
	vector<int> left;
	vector<int> right;
	vector<int> all;

	bool flag = true;

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else
							flag = false;
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}

		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO"<<endl;
		flag = true;
	}

	return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main(){
  int N;
  cin >> N;
  int boll[10];
  stack<int> B,C;
  B.push(0); C.push(0);
  for(int i=0;i<N;i++){
    for(int j=0;j<10;j++) cin >> boll[j];
    for(int j=0;j<10;j++){
        if(boll[j]>B.top()) B.push(boll[j]);
        else if(boll[j]>C.top()) C.push(boll[j]);
        else{
          cout << "NO" << endl;
          break;
        }
        if(j==9) cout << "YES" << endl;
    }
  }
  return 0;
}