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<vector>
#include<string>
#include<cstdlib>
#include<sstream>
#include<queue>
#include<deque>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

bool dfs(int depth,vi ball,stack<int> B,stack<int> C){
	if (depth == 10){
		return true;
	}
	bool ret,retB,retC;
	int A = ball[depth];
	
	if (B.top() < A){
		B.push(A);
		retB = dfs(depth + 1,ball,B,C);
		B.pop();
	}else{
		retB = false;
	}
	if (C.top() < A){
		C.push(A);
		retC = dfs(depth + 1,ball,B,C);
		C.pop();
	}else{
		retC = false;
	}

	if (retB or retC){
		ret = true;
	}else{
		ret = false;
	}

	return ret;

}

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

	for (int i = 0; i < n; i++){
		vi ball(10);
		stack<int> B,C;
		B.push(-1);
		C.push(-1);
		int num;
		for (int j = 0; j < 10; j++){
			cin >> ball[j];
		}

		if (dfs(0,ball,B,C)){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}

C++: #include <stdio.h>

int main(void) {

  int n;

  int A[10],B[10],C[10];
  int a;
  int b_idx,c_idx;

  int flag;
  int i,j;


  scanf("%d",&n);

  for(i=0;i<n;i++) {

    scanf("%d %d %d %d %d %d %d %d %d %d",&A[0],&A[1],&A[2],&A[3],&A[4],&A[5],&A[6],&A[7],&A[8],&A[9]);

    for(j=0;j<10;j++) B[j]=C[j]=0;

    flag=1;

    b_idx=c_idx=0;

    for(j=0;j<10;j++) {

      a=A[j];

      if(b_idx==0) {

	B[b_idx]=a;
	b_idx++;

      } else {

	if(B[b_idx-1]>a) {

	  if(C[c_idx-1]>a) {

	    printf("NO\n");
	    flag=0;

	    break;

	  } else {

	    C[c_idx]=a;
	    c_idx++;

	  }

	} else {

	  if(C[c_idx-1]>a) {

	    B[b_idx]=a;
	    b_idx++;

	  } else {

	    if((a-B[b_idx-1])<(a-C[c_idx-1])) {

	      B[b_idx]=a;
	      b_idx++;

	    } else {

	      C[c_idx]=a;
	      c_idx++;

	    }

	  }

	}

      }

    }

    if(flag==1) printf("YES\n");

  }
  
  return 0;

}

C++: #include <iostream>

using namespace std;

int main(void) {
    int N, a, b, c;
    cin >> N;
    for (; N--; ) {
        b = c = 0;
        bool ok = true;
        for (int i = 0; i < 10; i++) {
            cin >> a;
            if (a > b) {
                b = a;
            } else if (a > c) {
                c = a;
            } else {
                ok = false;
                break;
            }
        }
        if (ok) cout << "YES" << endl;
        else cout << "NO" endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
using namespace std;
 
 
int res=0;
 
bool saiki(int ball[],int ttB,int ttC,int res){
    if(res==10)return true;
    if(ball[res]>ttB){
        return saiki(ball,ball[res],ttC,res+1);
    }
    if(ball[res]>ttC){
        return saiki(ball,ttB,ball[res],res+1);
    }
    return false;
}
 
int main(void){
    int a,b;
    int ball[11];
    int ttB=0,ttC=0;
    int n;
    scanf("%d",&n);
    for(a=0;a<n;a++){
        for(b=0;b<10;b++){
            ball[b]=0;
        }
        ttB=0;
        ttC=0;
        res=0;
        for(b=0;b<10;b++){
            scanf("%d",&ball[b]);
        }
        if(saiki(ball,ttB,ttC,res)==true)printf("YES\n");else printf("NO\n");
    }
    return 0;
}

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

int b[10],c[10],bi,ci,flag;

int main()
{
    int n,ball;
    scanf("%d", &n);
    for(int I=0;I<n;++I) {
        for(int i=0;i<10;++i) {
            scanf("%d", &ball);
            if (!bi) { b[bi] = ball; bi++; continue; }
            else if (!ci) { c[ci] = ball; ci++; continue; }
            else if (b[bi] < ball) {
                ++bi;
                b[bi] = ball;
            } else if (c[ci] < ball) {
                ++ci;
                c[ci] = ball;
            } else {
                ++flag;
                break;
            }
        }
        (flag) ? puts("NO") : puts("YES");
    }

    return 0;
}

C++: #include <iostream>
using namespace std;
int a[10];
bool dfs(int cur,int l,int r){
	if(cur==10){
		return true;
	}
	return (a[cur]>l && dfs(cur+1,a[cur],r)) || (a[cur]>r && dfs(cur+1,l,a[cur]));
}
int main(){
	ios::sync_with_stdio(false);
	int T;
	cin>>T;
	while(T--){
		for(int i=0;i<10;i++)
			cin>>a[i];
		puts(dfs(0,0,0)?"YES":"NO");
	}
	return 0;
}

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

int n,count=0;
int input[10];
bool res;

bool dfs(int x,int ltop,int rtop){
//  cout<<x<<","<<ltop<<","<<rtop<<endl;
    if(x==10) return true;
    if(ltop<input[x]){
        if(dfs(x+1,input[x],rtop)) return true;}
    if(rtop<input[x]){
        if(dfs(x+1,ltop,input[x])) return true;}

    return false;
}

int main(){ 
    cin>>n; 
    while(count<n){
        res=false;
        for(int i=0;i<10;i++){
            cin>>input[i];
        }       
        if(dfs(0,0,0)) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        count++;
    }
    return 0;
}

C++: #include<iostream>
main(){
int n,i,A,B,C,f;
for(std::cin>>n;n-->0;puts(f?"NO":"YES"))
 for(B=C=f=i=0;i<10;i++){
  std::cin>>A;
  if(B<A)B=A;else C<A?C=A:f=1;
 }
}

C++: #include <iostream>
#include <string.h>

using namespace std;

int ball_list[10];
int right_val;      
int left_val;

bool flag;

void dfs(int right, int left){
  int count = right + left;
  int num = ball_list[count];

  if(flag) return;

  if(count == 10){
    flag = true;
  }else{
    if(right_val < ball_list[count]){
      right_val = num;
      dfs(right+1, left);
    }
    if(left_val < ball_list[count]){
      left_val = num;
      dfs(right, left+1);
    }
  }
}

int main(){
  int n;

  cin >> n;

  for(int i = 0; i < n; i++){
    flag = false;
    right_val = 0;
    left_val = 0;

    for(int j = 0; j < 10; j++){
      cin >> ball_list[j];
    }
    
    dfs(0, 0);

    cout << ((flag)? "YES" : "NO") << endl;
  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){

  int a,b,n,m,flag;
  
  cin >> m;
  for(int j=0;j<m;j++){
    a = b = flag = 0;
    for(int i=0;i<10;i++){
      
      cin >> n;
      
      if(a<n&&b>n) a=n;
      else if(a>n&&b<n) b=n;
      
      else if(a<n&&b<n){
	if( (a>b)? a=n:b=n);
      }
      else flag++;
      
    }
    printf("%s\n",(flag==0)? "YES":"NO");
  }

  return (0);
}

C++: #include<iostream>
int T[10];
int ans;

void method(int num,int A,int B){
  if(num==10){
    ++ans;
    return;
  }
  if(T[num]>A){
    method(num+1,T[num],B);
  }
  if(T[num]>B){
    method(num+1,A,T[num]);
  }
}
int main(){
  int n;

  std::cin >> n;

  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      std::cin >> T[j];
    }
    ans = 0;
    method(0,0,0);
    std::cout << ((!ans)? "NO" : "YES") << std::endl;
  }
}

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 cnt_b = 0;
    int cnt_c = 0;
    for( int i = 0 ; i < 4 ; i++ ){
      if( b[i] < b[i+1] )cnt_b++;
      if( c[i] < c[i+1] )cnt_c++;
    }
    if( cnt_b == 4 && cnt_c == 4 ) cout << "YES" << endl;
    else cout << "NO" << endl; 
  }
 return 0;
}