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

using namespace std;

int main(void){

  int b[5];
  int c[5];

  int n;
  cin >> n;
  while(n--){

    int a[10];
    int j = 0;
    int k = 0;
    for( int i = 0 ; i < 10 ; i++ ){
      cin >> a[i];
      if( i % 2 == 0 ){
	b[j++] = a[i];
      }
      if( i % 2 == 1 ){
	c[k++] = a[i];
      }
    }
    int temp_b[5];
    int temp_c[5];

    for( int i = 0 ; i < 5 ; i++ ){
      temp_b[i] = b[i];
      temp_c[i] = c[i];
    }

    sort( b , b + 5 );
    sort( c , c + 5 );

    int cnt_b = 0;
    int cnt_c = 0;

    for( int i = 0 ; i < 5 ; i++ ){
      if( temp_b[i] == b[i] )cnt_b++;
      if( temp_c[i] == c[i] )cnt_c++;
    }
    if( cnt_b == 5 && cnt_c == 5 ) cout << "YES" << endl;
    else cout << "NO" << endl; 
  }
  return 0;
}

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

int main()
{
	int ball = 10;	//ボールの数
	int n,k;	//n:セットの数 k:メモ
	cin >> n;	
	queue<int> a;	//開口部Ａ
	int b = 0 , c = 0;	//筒Ｂ、筒Ｃ
	queue<bool> flag;	//成功したセット


	for (int i=0; i < n; i++){		//1セットのループ
		for (int j=0; j < ball; j++){
			cin >> k;
			a.push( k );
		}
		b = a.front();
		a.pop();	//最初の一個
		
		for (int j=0; j < (ball-1); j++){		//ボールのループ
			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>
#include <stack>
using namespace std;
int main(){
  stack<int>st[2];
  int n,f;
  cin >> n;
  while(n--){
    f = 1;
    st[0].push(0);st[1].push(0);
    int i;
    for(i = 0 ; i < 10 ; i++ ){
      int a;
      cin >> a;
      if(a-st[0].top() > 0 && a-st[1].top() <= 0){
	st[0].push(a);
      } else if(a-st[1].top() > 0 && a-st[1].top() <= 0){
	st[1].push(a);
      } else if(a-st[1].top() > 0 && a-st[1].top() > 0){
	if(st[1].top() < st[0].top())st[0].push(a);
	else st[1].push(a);
      }else{f=0;}
    }
    if(f)cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	vector<bool>l;
	int o[10], n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++)cin >> o[j];
		int sum = o[0], num = 0;
		for (int k = 1; k < 10; k++) {
			if (o[k] < sum) {
				num++;
			}
			sum = max(sum, o[k]);
		}
		l.push_back(!(num >= 2));
	}
	for (bool b : l) {
		if (b)cout << "YES";
		else cout << "NO";
		cout << endl;
	}
	char c;
	cin >> c;
}

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

int a[15],lef[15],rig[15];
bool flag;

bool solve(){
	for(int i=0; i<1024; i++){
		memset(lef,0,sizeof(lef));
		memset(rig,0,sizeof(rig));
		int lc=0,rc=0,j;
		int cnt = 0;
		for(cnt=0,j=i; cnt<10; cnt++,j>>=1){
			if(j&1) lef[lc++] = a[cnt];
			else rig[rc++] = a[cnt];
		}
		flag = true;
		for(int j=1; j<lc; j++)
			if(lef[j]<lef[j-1]){
				flag = false;
				break;
			}

		for(int j=1; j<rc; j++)
			if(rig[j]<rig[j-1]){
				flag=false;
				break;
			}

		if(flag) return true;
	}
	return false;
}

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

}

C++: #include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <utility>
#include <climits>
#include <cstdlib>

using namespace std;

#define NDEBUG

#ifndef NDEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...)
#endif

int N;

const char *solve(int (&balls)[10]) {
    for (int trial = 0; trial < (1 << 10); trial++) {
        int left_top = 0, right_top = 0;
        int i;
        for (i = 0; i < 10; i++) {
            int dir = ((trial >> i) & 1);
            int ball = balls[i];
            if (dir) { // left
                if (left_top == 0) {
                    left_top = ball;
                    continue;
                }
                if (left_top > ball) {
                    break;
                }
                left_top = ball;
            } else { // right
                if (right_top == 0) {
                    right_top = ball;
                    continue;
                }
                if (right_top > ball) {
                    break;
                }
                right_top = ball;
            }
        }
        if (i == 10) {
            return "YES";
        }
    }
    return "NO";
}

int main() {
    scanf(" %d", &N);
    debug("===\n");
    debug("%d\n", N);
    for (int i = 0; i < N; i++) {
        int balls[10];
        for (int j = 0; j < 10; j++) {
            scanf(" %d", &balls[j]);
        }
        for (int j = 0; j < 10; j++) {
            debug("%d ", balls[j]);
        }
        debug("\n");
        printf("%s\n", solve(balls));
    }
}

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

using namespace std;

int a[11];

bool dfs(int I, int A, int B) {
	if (I == 10) return true;
	if (a[I] > A) {
		if (dfs (I + 1, a[I], B)) {
			return true;
		}
	}
	if (a[I] > B) {
		if (dfs(I + 1, A, a[I])) {
			return true;
		}
   	}
   	return false;
}

int main () {
	int T;
	cin >> T; 
	while (T--) {
		for (int i=0; i<10; i++) {
			cin >> a[i];
		}
		if (dfs(0,0,0)) {
			cout << "YES" <<endl;
		}
		else cout << "NO" <<endl;
	}
	return 0;
}

C++:  
 #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
  
 int main()
 {
   int N;
   cin>>N;
   while(N--)
   {
     int arr[10];
     int left[10],right[10];
     bool flag=true;
     int cnt1,cnt2;
     cnt1=cnt2=0;
     for(int i=0;i<10;i++) cin>>arr[i];
     for(int i=0;i<10;i++)
     {
       if(i==0) left[cnt1++]=arr[i];
       else
       {
         if(cnt2==0)
         {
           if(left[cnt1-1]<arr[i]) left[cnt1++]=arr[i];
           else right[cnt2++]=arr[i]; 
         }
         else
         {
           int left_win=arr[i]-left[cnt1-1];
           int right_win=arr[i]-right[cnt2-1];
           if(arr[i]<min(left[cnt1-1],right[cnt2-1]))
           {
             flag=false;
             break;                                          
           }    
           else if(arr[i]>left[cnt1-1]&&arr[i]<right[cnt2-1]) left[cnt1++]=arr[i];
           else if(arr[i]<left[cnt1-1]&&arr[i]>right[cnt2-1]) right[cnt2++]=arr[i];
           else
           {
             if(right_win>left_win) left[cnt1++]=arr[i];
             else right[cnt2++]=arr[i];    
           }
         }   
       }        
     }
     if(flag) cout<<"YES"<<endl;
     else cout<<"NO"<<endl;
   }
   //while(1);     
   return 0;  
 }