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 <stack>

using namespace std;

bool Solution()
{
    int n;
    
    int left = 0;
    int right = 0;
    
    int a[10];
    
    cin>>n;
    
    where(n--)
    {
        for (int i = 0; i < 10; i++)
        {
            cin>>a[i];
        }
        
        for (int i = 0; i < 10; i++)
        {
            if (a[i] > left) // at the beginning, compare with first ball and the ball before first ball (empty)
            {
                left = a[i];
            }
            else if (a[i] > right)
            {
                right = a[i];
            }
            else                 //when can not enter to the both bottles to the end, then return false
            {
                return false;
            }
        }
        
        return true;
    }
}

int main()
{
   if (Solution())
   {
       cout<<"YES"<<endl;
   }
   else
   {
        cout<<"NO"<<endl;
   }
    
    return 0;
}

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

int main(){
  int n;
  
  cin >> n;
  for(int j = 0 ; j < n ; j++){ 

    int ball[10]={0},left[5]={0},right[5]={0};
    int lmax=0,rmax=0,lcnt=0,rcnt=0,lc=0,rc=0;
    
    for( int i = 0 ; i < 10 ; i++ ){
      cin >> ball[i];
      
      if(i % 2 == 0) left[lc++] = ball[i];
      else right[rc++] = ball[i];
      
      if( lmax < left[lc-1] ){
	lmax = left[lc-1];
	lcnt++;
      }   
      
      if( rmax < right[rc-1] ){
	rmax = right[rc-1];
	rcnt++;
      }
     
    }
    if( lcnt == 5 && rcnt == 5 ) cout << "YES" << endl;
    else cout << "NO" << endl;
  } 
  return 0;
}

C++: #include<iostream>
#include<queue>
using namespace std;
int main (){
	int n;
	cin>>n;
	queue <int > p,q;
	int a[10];
	while(n--){
		for (int i=0;i<10;i++){
			cin>>a[i];
			if(!i) p.push(a[i]);
			if(a[i]<p.back()) q.push(a[i]);
			else p.push(a[i]);
		}
		int t=q.front(),k=0;
		q.pop();
		while(!q.empty()){
			if(t>q.front()){
				k=1;
				break;
			}else {
				q.pop();
			}
		}
		if(k) cout<<"NO"<<endl;
		else cout<<"YES"<<endl; 
	}
}

C++: #include <cstdio>

using namespace std;
#define INF 1000000000

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

  for (int i = 0; i < N; ++i) {
    int B = 0, C = 0;
    bool ans = true;
    for (int j = 0; j < 10; ++j) {
      int A;
      scanf("%d", &A);
      int diffB = INF, diffC = INF;
      if (A > B) diffB = A - B;
      if (A > C) diffC = A - C;
      if (diffB == INF && diffC == INF) ans = false;
      if (diffB < diffC) B = A;
      else C = A;
    }
    if (ans) puts("YES");
    else puts("NO");
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,a;
  int f = 0;
  int b = 0 ,c = 0;
  cin >> n;
  while(n--){
    for(int i = 0;i < 10;i++){
      cin >> a;
      if(b < a)b = a;
      else if(c < a)c = a;
      else {
	f = 1;	
      }  
    }
    if(f == 1)cout << "NO" << endl;
    else cout << "YES" << endl;
  }
  return 0;
}

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

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); i++)
#define loops(i,f,n) for(int i = (f); i < (n); i++)
#define INF 100000000
typedef pair<int, int> pii;

vector<int> A(10);
bool ans = false;
void dfs(int a, int b, int cnt)
{
	if (cnt == 9)
	{
		if (a < A[cnt])ans = true;
		if (b < A[cnt])ans = true;
		return;
	}
	if (A[cnt] > a)dfs(A[cnt], b, cnt + 1);
	if (A[cnt] > b)dfs(a, A[cnt], cnt + 1);
	if (A[cnt] < a && A[cnt] < b)return;
}

int main()
{
	int n;
	cin >> n;
	loop(k, n)
	{
		loop(i, 10)
		{
			cin >> A[i];
		}
		ans = false;
		dfs(0, 0, 0);
		cout << (ans ? "YES" : "NO") << endl;
	}
	return 0;
}

C++: //
//  main.cpp
//

#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
#include <limits>
#include <math.h>
#include <queue>
#include <tuple>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <memory>

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0033

using namespace std;

// #define TEST

#ifdef TEST
static const string g_SAMPLE = R"(2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 11)";
static FILE* g_IN_FP;
static const char* g_IN_FN = "in.txt";
#define scanf(...) fscanf(g_IN_FP, __VA_ARGS__)
#endif // TEST

int main() {
#ifdef TEST
    g_IN_FP = fopen(g_IN_FN, "w");
    fwrite(g_SAMPLE.c_str(), 1, g_SAMPLE.size(), g_IN_FP);
    fclose(g_IN_FP);
    g_IN_FP = fopen(g_IN_FN, "r");
#endif // TEST
    int N;
    scanf("%d", &N);
    for (int n = 0; n < N; n++) {
        vector<int> balls;
        for (int i = 0; i < 10; i++) {
            int ball;
            scanf("%d", &ball);
            balls.push_back(ball);
        }
        bool foundGoodBits = false;
        for (int bits = 0; bits < (1 << 10); bits++) {
            if (bits > (~bits & ((1 << 10) - 1))) {
                continue;
            }
            function<bool(int)> isGoodBits = [&balls](int bits) -> bool {
                int zeroTop = 0;
                int oneTop = 0;
                for (int bit = 0; bit < 10; bit++) {
                    int* topPtr = (bits & (1 << bit)) != 0 ? &oneTop : &zeroTop;
                    if (balls[bit] <= *topPtr) {
                        return false;
                    } else {
                        *topPtr = balls[bit];
                    }
                }
                return true;
            };
            if (isGoodBits(bits)) {
                foundGoodBits = true;
                break;
            }
        }
        if (foundGoodBits) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <climits>
using namespace std;
int b = INT_MIN, c = INT_MIN;
bool push(vector<int> ball) {
    vector<int>::iterator ite;
    for(ite = ball.begin(); ite != ball.end(); ite++) {
        if(*ite > b) b = *ite;
        else if (*ite > c) c = *ite;
        else return(false);
    }
    return(true);
}

int main(void) {
    int num; cin >> num;
    for(int r = 0; r < num; r++) {
        vector<int> vec;
        for(int c = 0; c < 10; c++) {
            int input; cin >> input;
            vec.push_back(input);
        }
        if(push(vec)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return(0);
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <cstring>
#include <string>
#include <sstream>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

vector<int> in(10);
string res;

void dfs(int, int, int);

int main(void){
    int n; cin >> n;
    while(n --){
        res = "NO";
        rep(i, 10) cin >> in[i];

        dfs(0, 0, 0);
        cout << res << endl;
    }

    return 0;
}

void dfs(int left, int right, int cur){
    if(cur == in.size()) res = "YES";
    if(res == "YES") return;

    if(left < in[cur]) dfs(in[cur], right, cur + 1);
    if(right < in[cur]) dfs(left, in[cur], cur + 1);
}