Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var num int
	fmt.Scan(&num)

	for i := 0; i < num; i++ {
		sc.Scan()
		line := sc.Text()

		insertCheck(line)
	}
}

func insertCheck(line string) {
	var B, C []int

	for _, v := range strings.Split(line, " ") {
		ball, _ := strconv.Atoi(v)
		switch {
		case len(B) == 0:
			B = append(B, ball)
		case B[len(B)-1] < ball:
			B = append(B, ball)
		case B[len(B)-1] >= ball:
			switch {
			case len(C) == 0:
				C = append(C, ball)
			case C[len(C)-1] < ball:
				C = append(C, ball)
			case C[len(C)-1] >= ball:
				fmt.Println("NO")
				return
			}
		}
	}
	fmt.Println("YES")
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
int n;
vector<int> v;

void showVector( vector<int> vec ){
  for( int i = 0; i < vec.size(); i++ ) printf("%d: %d, ", i, vec.at(i));
  cout << endl;
}

bool follow( vector<int> v1 ){
  vector<int> v2;
  for(int i=0; i <  v1.size(); i++ ) v2.push_back( v1.at(i) );
  sort( v2.begin(), v2.end() );
  return v1 == v2;
}

bool dfs( int i, vector<int> l, vector<int> r ){
  if( i == 10 ){ 
    return follow(l) && follow(r);
  }

  vector<int> l2 = l;
  l2.push_back( v.at(i) );
  if( dfs( i + 1, l2, r ) ) return true;

  vector<int> r2 = r;
  r2.push_back( v.at(i) );
  if( dfs( i + 1, l, r2 ) ) return true;
  
  return false;
}

main(){
  vector<int> l, r;
  int tmp;
  cin >> n;
  for( int i=0; i < n; i++ ){
    v.clear();
    for( int j = 0; j < 10; j++ ){
      cin >> tmp;
      v.push_back( tmp );
    }
    if( dfs(0, l, r) ) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

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

int a[10];
int n;

bool dfs(int m,int left, int right){
    if(m==10) return true;
    if(a[m]>left){
        return dfs(m+1,a[m],right);
    }
    if(a[m]>right){
        return dfs(m+1,left,a[m]);
    }
    return false;
}

void solve(){
    for(int i=0;i<10;i++){
        cin>>a[i];
    }
    if(dfs(0,0,0)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return;
}

int main(){
    cin>>n;
    for(int i=0;i<2;i++){
        solve();
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int b[10];
  int t;
  cin>>t;
  while(t--){
    for(int i=0;i<10;i++)
      cin>>b[i];
    int now=b[0];
    b[0]=0;
    for(int i=1;i<10;i++)
      if(b[i]>now){
	now=b[i];
	b[i]=0;
      }
    /*for(int i=0;i<10;i++)
      cout<<b[i]<<" ";
      cout<<"\n";*/
    for(int i=0;i<10;i++)
      if(b[i]>0){
	now=i;
	break;
      }
    bool flag=true;
    for(int i=now;i<10;i++)
      if(b[i]>0&&b[i]<b[now])
	flag=false;
      else if(b[i]>0)
	now=i;
    if(flag)cout<<"YES\n";
    else cout<<"NO\n";
  }
}

C++: #include<iostream>
using namespace std;
int n;
int a[10], b[10], c[10];
int curB, curC;

bool dfs(int i){
	if(i == 10){
		return true;
	}
	
	if(a[i] > b[curB]){
		b[++curB] = a[i];
		return dfs(i + 1);
	}else if(a[i] > c[curC]){
		c[++curC] = a[i];
		return dfs(i + 1);
	}

	return false;
}

void solve(){
	cin >> n;
	while(n-- > 0){
		for(int i = 0; i < 10; i++){
			cin >> a[i];
			b[i] = c[i] = 0;
		}
		
		curB = 0;
		curC = 0;
		if(dfs(0)){
			cout << "YES" << "\n"; 
		}else{
			cout << "NO" << "\n";
		}
	}
}

int main(){
	solve(); 
}

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

int main(){
	int n, a, b, in, j;
	cin >> n;
	for(int i=0;i<n;i++){
		a = 0;
		b = 0;
		for(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;
			}
		}
		for (int y = j + 1; y < 10; y++) { cin >> in; }
	}
	return 0;
}

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

int main(){
  stack<int> r,l;
  int a,m[10][2],i;
  cin >> a;
  for(int k=0;k<a;k++){
    for(int j=0;j<10;j++)cin>>m[j][0];
    m[0][1]=1;
    i=1;
    r.push(m[0][1]);
    l.push(0);
    while(1){
      if(m[i][0]>r.top()){
	r.push(m[i][0]);
	m[i][1]=1;
	i++;
      }else if(m[i][0]>l.top()){
	l.push(m[i][0]);
	m[i][1]=-1;
	i++;
      }else {
	i--;
	while(1){
	  if(m[i][1]==-1){
	    l.pop();
	    i--;
	  }else{
	    r.pop();
	    m[i][1]=-1;
	    l.push(m[i][0]);
	    i++;
	    break;
	  }
	}
      }
      if(i==10){
	cout<<"YES"<<endl;
	break;
      }else if(i==1){
	cout<<"NO"<<endl;
	break;
      }
    }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
main(){
  int n,a;
  srand((unsigned)time(NULL));
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>a;
    }
    if(rand()%2==0){
      cout<<"YES"<<endl;
    }
    else{
      cout<<"NO"<<endl;
    }
  }
}

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

const int MAX = 10;
int ball[MAX];
int can;
int n;

void dfs(int left, int right, int num){
	if(num == 10) can = 1;
	if(can != 0) return;
	if(ball[num] > left) dfs(ball[num], right, num+1);
	if(ball[num] > right) dfs(left, ball[num], num+1);
	return;
}

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

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

using namespace std;

int a[10];

bool dfs(int i, int B, int C)
{
    if(i == 10)
        return true;

    if(a[i] > B)
        return dfs(i + 1, a[i], C);
    
    if(a[i] > C)
        return dfs(i + 1, B, a[i]);
    
    return false;


}

int main()
{
    int N;
    cin >> N;
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < 10; j++)
        {
            cin >> a[j];
        }
        dfs(0, 0, 0);
        cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
    }
    

    return 0;
}

C++: #include <iostream>
using namespace std;
int b, c, cnt;
bool dfs(int x){
    if(x > b){
        b = x;
        return 1;
    }
    if(x > c){
        c = x;
        return 1;
    }
    return 0;
}

int main(void){
    int N, x;
    cin >> N;
    while(N != 0){
        b = 0;
        c = 0;
        cnt = 0;
        for(int i = 0; i < 10; i++){
            cin >> x;
            cnt += dfs(x);
        }
        if(cnt == 10)   cout << "YES" << endl;
        else    cout << "NO" << endl;
        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;
            }
        }
    }
}

int main()
{
   if (Solution())
   {
       cout<<"YES"<<endl;
   }
   else
   {
        cout<<"NO"<<endl;
   }
    
    return 0;
}