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>

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>
#include<string.h>

using namespace std;

int N;
int balls[10];
void dfs(int n, int a, int b){
if(n==10)return true;
if(balls[n]>a) return dfs(n+1,balls[n],b);
if(balls[n]>b) return dfs(n+1,a,balls[n]);
return false;
}
int main(){
cin>>N;
for(int i=0;i<N;i++){
for(int j=0;j<10;j++){
cin>>balls[j];
}
if(dfs(0,0,balls[0]))cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}

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;
  scor (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 <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 <stdio.h>

int ball[10];

bool can(int n,int left,int right){
	bool flag;
	
	if(n==10) return true;
	if(ball[n]>right && can(n+1,left ,ball[n])return true;
	if(ball[n]>left  && can(n+1,ball[n],right)return true;
	
	return false;
}


int main(){
	
	int N;
	
	scanf("%d",&N);
	
	for(int i=0;i<N;i++){
		for(int j=0;j<10;j++){
			scanf("%d",&ball[j]);
		}
		
		printf(can(0,0,0)?"YES":"NO");
		
		
	}
}

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 << "YEY" << endl;
        }
      else
        {
          cout << "NO" << endl;
        }
    }
  return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int a[10];
int b[10];
bool flag;
int c[10];
void dfs(int aa,int bb,int cc)
{
    if(bb+cc==10)
    {
        flag=true;
        return ;
    }
    if(bb==0||(a[aa]>b[bb-1]&&b[bb]==0))
    {
        b[bb]=a[aa];
        dfs(aa+1,bb+1,cc);
        b[bb]=0;
    }
    if(cc==0||(a[aa]>c[cc-1]&&c[cc]==0))
    {
        c[cc]=a[aa];
        dfs(aa+1,bb,cc+1);
        c[cc]=0;
    }
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        for(int i=0;i<10;i++)
            cin>>a[i];
        flag=false;
        dfs(0,0,0);
        if(flag)
            printf("YES\n");
        else
            printf("NO\n");


    }
    return 0;
}

C++: #include <cstdio>
using namespace std;
int A[10];
int N;
int flag;

void dfs(int x, int l, int r) {
  if (x == 10) return;
  if (flag) return;
  if (A[x] > l)
    dfs(x + 1, A[x], r);
  else if (A[x] > r)
    dfs(x + 1, l, A[x]);
  else {
    flag = 1;
    return;
  }
}

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

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

using namespace std;

int ball[11];
int a[11],b[11];
bool ans;

bool dfs(int i,int p,int q)
{
	 if(ball[i] < a[p] && ball[i] < b[q]) return false;
	 if(i == 9) return true;
	 bool tmp = false;
	 if(a[p] < ball[i])
	 {
		 a[p+1] = ball[i];
		 tmp = (tmp || dfs(i+1,p+1,q));
	 }
	 if(b[q] < ball[i])
	 {
	 	b[q+1] = ball[i];
		 tmp = (tmp || dfs(i+1,p,q+1));
	 }
	 return tmp;
}


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

C++: #include <iostream>

using namespace std;

bool s( int ord[], int const i, int const bef = -1 )
{
    if ( i > 10 )
        return true;

    if ( bef != -1 && bef > ord[i] )
        return false;

    return s( ord, i+1, ord[i] ) || s( ord, i+2, ord[i] );
}

int main()
{
    int n;
    cin >> n;

    for( int iii=0; iii<n; ++iii ) {
        int ord[10];
        for( int i=0; i<10; ++i )
            cin >> ord[i];

        cout << ( s( ord, 0 ) || s( ord, 1 ) ? "YES" : "NO" ) << endl;
    }
}

C++: #include <iostream>
using namespace std;
int main(){
	int N;
	cin >> N;
	while(N--){
		int pipe[2] = {0};
		int i=0;
		bool f=false;
		for(; i < 10; i++){
			int num;
			cin >> num;
			if(pipe[1] > pipe[0]){
				
				if(num > pipe[1]){
					pipe[1] = num;
				}else if(num > pipe[0]){
					pipe[0] = num;
				}else{
					f=true;
				}
				
			}else{
				if(num > pipe[0]){
					pipe[0] = num;
				}else if(num>pipe[1]){
					pipe[1] = num;
				}else{
					f=true;
				}
			}
			
		}
		if(!f) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}