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;

int caseCnt, numbers[10], curNum;
stack<int> Left, Right;

bool used[10], result;

void clear_stack(){
    while( !Left.empty())  Left.pop();
    while(!Right.empty()) Right.pop();
}

bool dfs(int index, int left_or_right){
    if(!left_or_right){
        if(Left.empty() || numbers[index] > Left.top())
            Left.push(numbers[index]);
        else
            return false;
    }else{
        if(Right.empty() || numbers[index] > Right.top())
            Right.push(numbers[index]);
        else
            return false;
    }
    if(index == 9)return true;
    else if(dfs(index+1, 0))return true;
    else if(dfs(index+1, 1)) return true;
    else return false;
}

int main(){
    cin >> caseCnt;

    while(caseCnt--){
        result = false;
        clear_stack();

        for(int i=0; i<10; ++i) cin >> numbers[i];

        result = dfs(0, 0);
        if(result){
            cout << "YES\n";
            continue;
        }

        result = dfs(0, 1);
        if(result) cout << "YES\n";
        else       cout << "NO\n";
    }
    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std;
int ball[15];
int leftFront, rightFront;
bool isOK;
void DFS(int depth)
{
    if(depth == 10 || isOK)
    {
        isOK = true;
        return;
    }

    if(ball[depth] > leftFront)
    {
        leftFront = ball[depth];
        DFS(depth + 1);
    }

    if(ball[depth] > rightFront)
    {
        rightFront = ball[depth];
        DFS(depth + 1);
    }

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

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

        isOK = false;
        leftFront = 0;
        rightFront = 0;

        DFS(0);

        if(isOK)
            printf("YES\n");
        else
            printf("NO\n");
    }

	return 0;
}

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

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

int main(){
	int n, a, b, in;
	cin >> n;
	for(int i=0;i<n;i++){
		a = 0;
		b = 0;
		for(int j=0;j<10;j++){
			cin >> in;
			if(in>a){
				a = in;
			}
			else if(in>b){
				b = in;
			}
			else{
				cout << "NO" << endl;
				break;
			}
			if (j==9){
				cout << "YES" << endl;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;
#define FOR(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
int num[10];
int B[10];
int C[10];
bool flag;
void solve(int, int, int);

int main(void){
	int N;
	cin >> N;
	for(int k = 0; k < N; k++){
		flag = false;
		fill_n(B , 10, -1);
		fill_n(C , 10, -1);
		for(int i = 0; i < 10; i++){
			cin >> num[i];
		}
		solve(0, 0, 0);
		if(flag){cout << "YES" << endl; continue;}
		cout << "NO" << endl;
	}

	return 0;
}

void solve(int cnt,int right, int left){
	if(cnt == 10){
		flag = true;
		return;
	}
	if(num[cnt] > right) solve(cnt+1, num[cnt], left);
	if(num[cnt] > left) solve(cnt+1, right, num[cnt]);
}

C++: #include <iostream>
#define _for(i,a,b) for(int i = (a); i < b; ++i)
#define _rep(i,a,b) for(int i = (a); i <= b; ++i)
using namespace std;
int a[10+2];
bool flag = 0;
void dfs(int i, int l, int r){
    if(flag) return;
    if(i == 10) {
        flag = 1;
        return;
    }
    if(a[i] > l) dfs(i+1, a[i], r);
    if(a[i] > r) dfs(i+1, l, a[i]);
}
int main(){
    int n;
    cin>>n;
    while(n--){
        flag = 0;
        _for(i,0,10) cin>>a[i];
        dfs(0,0,0);
        if(flag) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
int main()
{
    int N; cin >> N;
    while (N--) {
        int a[10];
        stack<int> b, c;
        for (int i = 0; i < 10; ++i) cin >> a[i];
        b.push(0);
        c.push(0);
        bool ok = true;
        for (int i = 0; i < 10; ++i) {
            if (b.top() > c.top()) {
                if (b.top() < a[i]) b.push(a[i]);
                else if (c.top() < a[i]) c.push(a[i]);
                else ok = false;
            }
            else {
                if (c.top() < a[i]) c.push(a[i]);
                else if (b.top() < a[i]) b.push(a[i]);
                else ok = false;
            }
        }
        cout << (ok ? "YES" : "NO") << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int case_cnt;
int ball[12];
bool visited[12];
int maxx;
int main()
{
  cin>>case_cnt;
  while(case_cnt--)
  {
	
	  for(int i=1;i<=10;i++) 
	  {
		  cin>>ball[i];
		  visited[i]=false;
	  }
	  maxx=ball[1];
	  visited[1]=true;
	  //找到一段递增序列
	  for(int i=2;i<=10;i++) 
	  {
		 if(ball[i]>maxx)
		 {
			 visited[i]=true;
			 maxx=ball[i];
		 }
	  }
	  //剩下的数中有无不递增的。先找到剩下数中的第一个
	  maxx=-1;
	  int i;
	  for(i=2;i<=10;i++) 
	  {
		 if(visited[i]) continue;
		 if(ball[i]<maxx) break;
		 maxx=ball[i];
	  }
	  if(i==11) cout<<"YES"<<endl;
	  else cout<<"NO"<<endl;
  }
   return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<string>
using namespace std;

static int N;
static vector<int> balls;
static vector<int> A, B;
static bool flag;

void dfs(int id)
{
	if (flag) return;
	if (id >= 10)
	{
		flag = true;
		return;
	}
	//printf("%d\n", id);
	if ((A.size() > 0 && balls[id] > A.back()) || A.size() == 0)
	{
		A.push_back(balls[id]);
		dfs(id + 1);
	}
	else if ((B.size() > 0 && balls[id] > B.back()) || B.size() == 0)
	{
		B.push_back(balls[id]);
		dfs(id + 1);
	}
	
}




int main()
{
	while (scanf("%d", &N) != EOF)
	{
		while (N--)
		{
			balls.clear();
			balls.resize(10);
			for (int i = 0; i < 10; i++) scanf("%d", &balls[i]);
			A.clear();
			B.clear();
			flag = false;
			dfs(0);
			printf(flag ? "YES\n" : "NO\n");
		}
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
int a[10];
bool ans;
void dfs(int i,int r,int l){
	if(i==10)return;
	if(ans==0)return;
	if(r<a[i])dfs(i+1,a[i],l);
	else if(l<a[i])dfs(i+1,r,a[i]);
	else ans=0;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		for(int i=0;i<10;i++)cin>>a[i];
		dfs(0,0,0);
	if(ans)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	}
}