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 <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;

int n, k;// , a = 0, b = 0;
bool f = 1;
stack<int> s1, s2;

int main(){
	cin >> n;
	REP(i, n){
		REP(j, 10){
			cin >> k;
			if (j == 0){
				s1.push(k);
				//a = s1.top();
			}
			else if (j == 1){
				s2.push(k);
				//b = s2.top();
			}
			else{
				if (s1.top() < k || s2.top() < k){
					if (k - s1.top() > k - s2.top()){
						s2.push(k);
					}
					else{
						s1.push(k);
					}
					//a = s1.top();
					//b = s2.top();
				}
				else{
					f = 0;
				}
			}
			//cout << a << b << "\n";
		}
		if (f){
			cout << "YES\n";
		}
		else{
			cout << "NO\n";
		}
	}
}

C++: #include<stdio.h>
 
int unname(int *ball,int i,int b,int c)
{
    if(i==10) return 1;
    if(c<ball[i]){
        c=ball[i];
        i++;
        return unname(ball,i,b,c);
    }
    if(b<ball[i]){
        b=ball[i];
        i++;
        return unname(ball,i,b,c);
    }
    return 0;
}
 
int main()
{
    int ball[10];
    int result,i;
    int b=0,c=0;
    for(i=0;i<10;i++)
    {
        scanf("%d",&ball[i]);
    }
    c=ball[0];
    i=0;
    result=unname(ball,i,b,c);
    if(result==1) printf("YES\n");
    else printf("NO\n");
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
    int n;
    cin>>n;
    while(n--){
        int a[10],b=0,c=0,i;
        for(i=0;i<10;i++){
            cin>>a[i];
        }
        for(i=0;i<10;i++){
            if(a[i]>b&&a[i]>c){
                if(b>c){
                    b=a[i];
                }
                else{
                    c=a[i];
                }
            }
            else if(a[i]>b&&a[i]<c){
                b=a[i];
            }
            else if(a[i]<b&&a[i]>c){
                b=a[i];
            }
            else{
                break;
            }
        }
        if(i==10){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}

C++: /*
Á·Ï°Ìâ£ºBall_AOJ 0033
*/
#include <cstdio>
#include <cstring>
using namespace std;

int a[15];
int mark[15];
int count;

void dfs(int x)
{
	mark[x] = 1;
	for(int i=x+1; i<=9-i; i++)
		if(a[x]<a[i])
		{
			return dfs(i);
		}
		else
		{
			count++;
			return ;
			
		}
}

int main()
{
	int T;
	scanf("%d", &T);
	while(T--)
	{
		count=0;
		bool flag=false;
		memset(mark, 0, sizeof(mark));
		for(int i=0; i<10; i++)
			scanf("%d", &a[i]);
		for(int i=0; i<10; i++)
		{
			if(mark[i]==0)
				dfs(i);
		}
		if(count<=2)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
int main(){
	int N, i;
	int num[11];
	cin >> N;
	while( N-- > 0 ){
		for( i = 0; i < 10; i++ ){
			cin >> num[i];
		}
		stack<int> st1;
		stack<int> st2;
		for( i = 0; i < 10; i++ ){
			if( st1.empty() ){
				st1.push(num[i]);
				continue;
			}else if( st2.empty() ){
				st2.push(num[i]);
				continue;
			}
			if( st1.top() > num[i] && st2.top() > num[i] ){
				cout << "NO" << endl;
				break;
			}else if( st1.top() > st2.top() ){
				st1.push(num[i]);
			}else{
				st2.push(num[i]);
			}
		}
		if( i == 10 ) cout << "YES" << endl;
	}
}

C++: #include <stdio.h>
#include <string.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int a[10], dp[16][16];

bool can() {
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    rep (i, 10) {
        rep (j, 11) if (dp[i][j]) {
            const int pre = i == 0 ? 0 : a[i-1];
            if (a[i] > j) dp[i+1][pre] = 1;
            if (a[i] > pre) dp[i+1][j] = 1;
        }
    }
    rep (i, 11) if (dp[10][i]) return true;
    return false;
}

int main() {
    int T;
    scanf("%d", &T);
    while (T--) {
        rep (i, 10) scanf("%d", a+i);
        puts(can() ? "YES" : "NO");
    }
    return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n, max_len;
int num[11], dp[11];

int main(){
    //freopen("in.txt", "r", stdin);
    scanf("%d", &n);
    while(n--){
        for(int i=0; i<10; i++){
            scanf("%d", &num[i]);
        }
        memset(dp, 0, sizeof(dp));
        max_len = 1;
        dp[0] = 1;
        
        for(int i=1; i<10; i++){
            for(int j=0; j<i; j++){
                if(num[i] < num[j])
                    dp[i] = max(dp[i], dp[j] + 1);
            }
            max_len = max(max_len, dp[i]);
        }

        if(max_len > 2)
            printf("NO\n");
        else 
            printf("YES\n");
    }
    return 0;
}

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

using namespace std;

int n;
int stock[2][11];
int usea[11];

int dfs(int num, int r_num, int l_num) {
	int res = 0;

	if (usea[num] > stock[0][r_num]) {
		if (num == 9)
			return 1;
		stock[0][r_num + 1] = num;
		res = dfs(num + 1, r_num + 1, l_num);
		stock[0][r_num + 1] = -1;
		return res;
	}
	else if (usea[num] > stock[1][l_num]) {
		if (num == 9)
			return 1;
		stock[1][l_num + 1] = num;
		res = dfs(num + 1, r_num, l_num + 1);
		stock[1][l_num + 1] = -1;
		return res;
	}
	else {
		return 0;
	}
}


int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> usea[j];
		}
		if (dfs(0, 0, 0)) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n,a,b,c;
	cin>>n;
	for(int i=0;i<n;i++){
		bool t=true;
		b=0,c=0;
		for(int j=0;j<10;j++){
			cin>>a;
			if(b<a)
				b=a;
			if(b>a&&c<a)
				c=a;
			if(c>a)
				t=false;
		}
		if(t==true)
			cout<<"YES"<<endl;
		if(t==false)
			cout<<"NO"<<endl;
	}
	return 0;
}

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

int N;
int ball[10];
bool dfs(int,int,int);

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

bool dfs(int left, int right, int n){
    if(n==9 && (ball[9]>left || ball[9]>right)) return true;
    if(ball[n]>left && dfs(ball[n], right, n+1)) return true;
    if(ball[n]>right && dfs(left, ball[n], n+1)) return true;
    return false;
}

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];
     bool flag=true;
     for(int i=0;i<10;i++) cin>>arr[i];
     for(int i=0;i<8;i++)
     {
       if(arr[i]>arr[i+1]&&arr[i+1]>arr[i+2])
       {
         flag=false;
         break;                                      
       }        
     }     
     if(flag) cout<<"YES"<<endl;
     else cout<<"NO"<<endl;
   }
   //while(1);     
   return 0;  
 }