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>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <functional>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr long long INF = 1LL << 62;
constexpr int MOD = 1e9 + 7;
constexpr double EPS = 1e-10;

bool dfs(int* a, vector<int> &b, vector<int> &c, int n) {
    if(n == 10) return true;

    bool ok = false;
    if(b.empty() || b.back() < a[n]) {
        b.push_back(a[n]);
        ok |= dfs(a, b, c, n+1);
        b.pop_back();
    }
    if(c.empty() || c.back() < a[n]) {
        c.push_back(a[n]);
        ok |= dfs(a, b, c, n+1);
        c.pop_back();
    }
    return ok;
}

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N; cin >> N;
    int a[10];
    REP(i,N) {
        REP(j,10) cin >> a[j];
        vector<int> b, c;
        if(dfs(a, b, c, 0)) cout << "YES";
        else cout << "NO";
        cout << '\n';
    }
    return 0;
}

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

int main()
{
	int n,A,B,f,ball;
	cin >> n;
	
	for(int i=0;i<n;i++){
		A=0;
		B=0;
		f=0;
		for(int j=0;j<10;j++){
			cin >> ball;
			if(ball<A && ball<B) {
				f=1;
				break;
			} else if(A<ball && ball<B){
				A=ball;
			} else if(ball<A && B<ball){
				B=ball;
			} else if(A>B){
				A=ball;
			} else {
				B=ball;
			}
		}
		
		if(f==0) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

C++: #include <iostream>

using namespace std;

int main()
{
        int n;
        int b[6], c[6];

        b[5] = c[5] = 0;

        cin >> n;
        for (int i = 0; i < n; i++) {
                int ib = 0, ic = 0;

                for (int j = 0; j < 10; j++) {
                        if (j % 2) {
                                cin >> c[ic++];
                        }
                        else {
                                cin >> b[ib++];
                        }
                }
                int cnt = 0;
                while (b[cnt] < b[cnt + 1] && c[cnt] < c[cnt + 1]) {
                        cnt++;
                }

                cnt == 4 ? cout << "YES" : cout << "NO";
                cout << endl;
        }

        return 0;
}

C++: #include <iostream>

using namespace std;
const int kBalln = 10;
int ball[kBalln];

bool ExistAsceOrder(int i, int a, int b){
  // 終了条件
  if (i == kBalln)  return true;

  // ボールiを筒Bに入れる場合
  if (a < ball[i] && ExistAsceOrder(i+1,ball[i],b)) return true;

  // ボールiを筒Cに入れる場合
  if (b < ball[i] && ExistAsceOrder(i+1,a,ball[i])) return true;

  // どちらの筒に入れても昇順にならない場合
  return false;
}

int main(){
  int n;

  cin >> n;
  for (int j = 0; j < n; ++j)
    {
      for (int i = 0; i < kBalln; ++i)
        {
          cin >> ball[i];
        }

      if(ExistAsceOrder(0,0,0))
        {
          cout << "Yes" << endl;
        }
      else
        {
          cout << "No" << endl;
        }
    }
  return 0;
}

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

int main(){
	int N;
	int A[11];
	int cnt1=0;
	cin>>N;
	while(1){
		
		if(cnt1==N){
			break;
		}
		cnt1++;
		for(int i=1;i<=10;i++){
			cin>>A[i];
		}
		int B=A[1];
		int Z[11];
		for(int i=1;i<=10;i++){
			Z[i]=0;
		}
		int C=0;
		int cnt2=0;
		int su=0;
		for(int i=2;i<=10;i++){
			if((B+1==A[i])/*||((su==1)&&(B<A[i]))*/){
				B=A[i];
				cnt2++;
				//cout<<"1"<<A[i]<<endl;
			}
			else if((C+1==A[i])/*||((su==1)&&(B<A[i]))*/){
				C=A[i];
				cnt2++;
				Z[i]=C;
				su=0;
//cout<<"2"<<A[i]<<endl;
			}
			else if(B<A[i]){
				B=A[i];
				//Z[i]=C;
				//su=0;
				cnt2++;
//cout<<"3"<<A[i]<<endl;
			}
			else if(C<A[i]){
				C=A[i];
				Z[i]=C;
				su=0;
				cnt2++;
//cout<<"4"<<A[i]<<endl;
			}
			//CにB＋1がはいっていたらsu=1にすること
			for(int q=1;q<=10;q++){
				if(B+1==Z[q]){
					su=1;
				}
			}
			
		}
		if(cnt2==9){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}
	return 0;	
}

C++: #include <cstdio>
#include <algorithm>
#include <stack>
using namespace std;

stack<int> B, C;
int A[10];

bool dfs(int index)
{
  bool ret = false;
  char s[11];

  if (index >= 10) {
    return true;
  }

  for (int i = 0; i < 11; i++) {
    if (i < index) s[i] = '>';
    else s[i] = 0;
  }

  if (B.empty() || B.top() < A[index]) {
    B.push(A[index]);
    // printf("%spush %d into B\n", s, A[index]);
    ret = dfs(index + 1);
    // printf("%s%s. pop %d from B\n", s, ret ? "succeeded" : "failed", A[index]);
    B.pop();
  }
  if (!ret && (C.empty() || C.top() < A[index])) {
    C.push(A[index]);
    // printf("%spush %d into C\n", s, A[index]);
    ret = dfs(index + 1);
    // printf("%s%s. pop %d from C\n", s, ret ? "succeeded" : "failed", A[index]);
    C.pop();
  }

  return ret;
}

bool solve()
{
  while (!B.empty()) B.pop();
  while (!C.empty()) C.pop();

  B.push(A[0]);
  bool ret = dfs(1);
  B.pop();

  return ret;
}

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

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      scanf("%d", A + j);
    }

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

  return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int ball[10];
int l,r;
bool flag;
void dfs(int num,int l,int r){
	if(num==10) return ;
	if(flag) return ;
	if(ball[num]>l) dfs(num+1,ball[num],r);
	else if(ball[num]>r) dfs(num+1,l,ball[num]);
	else{
		flag=true;
		return ;
	}
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int i=0;i<10;i++){
			cin>>ball[i];
		}
		l=0,r=0;
		flag=false;
	    dfs(i,l,r);
		if(flag){
			cout<<"NO"<<endl;
		}else{
			cout<<"YES"<<endl;
		} 
	}
}

C++: #include <stdio.h>

int main(void){
	int topB,topC;
	int n,tmp;
	int valid;
	
	for (scanf("%d", &n); n--;){
		topB=topC=0;
		valid=1;
		for (int i=0; i<10; i++){
			scanf("%d", &tmp);
			if (tmp > topB) topB=tmp;
			else if (tmp > topC)topC=tmp;
			else {
				valid=0;
				for (;i<10;i++) scanf("%d", &tmp);
				break;
			}
		}
		printf("%s\n",valid?"YES":"NO");
	}
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<vector>

using namespace std;

int main(){
    int n;
    bool flag = true;
    vector<int> b, c;
    b.push_back(0);
    c.push_back(0);
    vector<int> ::iterator b_it=b.begin(), c_it=c.begin();

    cin>> n;
    while(n--, n!=-1){
        for(int i=0; i<10; i++){
            if(flag){
                int num;
                cin>> num;
                if(num>*b_it){
                    b.push_back(num);
                    b_it = b.end()-1;
                }else if(num>*c_it){
                    c.push_back(num);
                    c_it = c.end()-1;
                }else{
                    flag = false;
                }
            }
        }
        if(flag){
            cout<< "YES"<< endl;
        }else{
            cout<< "NO"<< endl;
        }
    }
    return 0;
}