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<cstdio>
int n, a[10];
int b[11] = { }, c[11] =

{
};

bool
dfs (int l, int r)
{
  if (l + r == 9)
    return true;
  if (b[l] < a[l + r])
    {
      b[l + 1] = a[l + r];
      return dfs (l + 1, r);
    }
  else if (c[r] < a[l + r])
    {
      c[r + 1] = a[l + r];
      return dfs (l, r + 1);
    }
  return false;
}

int
main (void)
{
  scanf ("%d", &n);
  for (int i = 0; i < n; i++)
    {
      for (int j = 0; j < 10; j++) {
	scanf ("%d", &a[j]);
        b[j+1] = 0;
        c[j+1] = 0;
      }
      if (dfs (0, 0))
	puts ("YES");
      else
	puts ("NO");
    }
  return 0;
}

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

bool dfs(vector<int>& balls,int i, int left, int right){
    if(i >= balls.size()) return true;

    bool l = true, r = true;
    if(left > balls[i]) l = false;
    if(right > balls[i]) r = false;

    if(!l && !r) return false;

    bool ok = false;

    if(l) ok |= dfs(balls, i+1, balls[i], right);
    if(r) ok |= dfs(balls, i+1, left, balls[i]);

    return ok;
}
int main(){
    int N;
    cin >> N;
    
    for(int i=0;i<N;i++){
        vector<int> balls(10);
        for(int j=0;j<10;j++) cin >> balls[j];

        bool ans = dfs(balls, 0, 0, 0);

        if(ans) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

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

int Balls[10];

bool fork(int balls[], int i, int b, int c) {
    if (i == 10) return true;
    if (b > balls[i] && c > balls[i]) return false;
    if (b < balls[i]) fork(balls, i + 1, balls[i], c);
    if (c < balls[i]) fork(balls, i + 1, b, balls[i]);
}


int main() {
    int n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> Balls[j];
        if(fork(Balls, 0, 0, 0)) {cout << "YES" << endl;}
        else(){cout << "NO" << endl;}
        }

    }
        return 0;
}

C++: #include<iostream>
using namespace std;
int x[10];
int func(int n,int r,int l){
    if(n == 10)return 1;
    if(x[n]>r){
        if(func(n+1,x[n],l))return 1;
    }
    if(x[n]>l){
        if(func(n+1,r,x[n]))return 1;
    }
    return 0;
}
int main(){
	int k;
	cin>>k;
	while(k-->0){
		for(int i=0;i<10;i++)
			cin>>x[i];
		if(func(0,0,0))
			cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
	int n;
	int data[10];
	int a[11],b[11];
	int ai,bi;
	int k;
	int flag;
	cin>>n;
	while(n--){
		for(int i=0;i<10;i++) cin>>data[i];
		a[0]=b[0]=0;
		ai=bi=0;
		flag=0;
		for(k=0;k<10;k++){
			if(a[ai]<data[k]){
				a[ai+1]=data[k];
				ai++;
			}
			else if(b[bi]<data[k]){
				b[bi+1]=data[k];
				bi++;
			}
			if(data[k]<a[ai] && b[bi]>data[k])
				flag=1;
		}
		if(flag==1) cout<<"NO"<<endl;
		else cout<<"YES"<<endl;
	}
	return 0;
}

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

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		bool flag = false;
		int prev;
		int in[10];
		int used[10];
		for (int j = 0; j < 10; j++)
		{
			cin >> in[i];
		}
		prev = in[0];
		vector<int> B;
		vector<int> C;
		for (int j = 0; j < 10; j++)
		{
			if (prev > in[j])
			{
				C.push_back(in[j]);
				used[j] = false;
				continue;
			}
			else
			{
				prev = in[j];
				B.push_back(in[j]);
				used[j] = true;
			}
		}
		prev = C[0];
		for (int j = 0; j < C.size(); j++)
		{
			if (prev > C[j])
			{
				flag = true;
			}
			else
			{
				prev = C[j];
			}
		}
		if (flag) cout << "NO" << endl;
		else cout << "YES" << endl;
	}
	return 0;
}

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

int main(void){
	int c;
	for(int j = 0; j < c-1; j++){
		int data[10];
		for(int i = 0; i < 10; i++){
			cin >> data[i];
		}

		int B, C = 0;
		B = data[0];
		bool flag = 0;

		for(int i = 1; i < 10; i++){
			if(B+1 != data[i]){
				if(C == 0){
					C = data[i];
				}else if(C+1 != data[i]){
					cout << "NO" << endl;
					break;
				}else{
					C = data[i];
				}
			}else{
				B = data[i];
			}
			if(i == 9){cout << "YES" << endl;}
		}
	}

}

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

int main(){
    int n, tmp;
    vector<int> vb, vc, vb_, vc_;
    
    cin >> n;
    
    for(int i = 0;i < n;i++){
        vb.clear();
        vc.clear();
        vb_.clear();
        vc_.clear();
        
        for(int j  = 0;j < 10;j++){
            cin >> tmp;
            
            if(j%2 != 0){
                vb.push_back(tmp);
            }else{
                vc.push_back(tmp);
            }
        }
        
        vb_ = vb;
        vc_ = vc;
        
        sort(vb.begin(), vb.end());
        sort(vc.begin(), vc.end());
        
        if(vb_ == vb && vc_ == vc){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
        
    }
    
    return 0;
}

C++: #include<iostream>

int r=0,l=0;

int main(){
	int n;
	std::cin>>n;
	for(int i=0;i<n;++i){
		bool f=true;
		for(int j=0;j<10;++j){
			int a;
			std::cin>>a;
			if(r<a&&l<a){
				if(r<=l)l=a;
				else r=a;
			}else if(r<a)r=a;
			else if(l<a)l=a;
			else f=false;
			//std::cout<<r<<" "<<l<<" "<<f<<std::endl;
		}
		if(f)std::cout<<"OK"<<std::endl;
		else std::cout<<"NO"<<std::endl;
		r=0,l=0;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#define INF 1000000000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define all(x) (x).begin(),x.end()
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

int a[11];

int dfs(int left,int right,int cnt){
  //cout<<left<<" "<<right<<" "<<cnt<<endl;
  if(cnt==10)return cnt;
  if(left<a[cnt]&&right<a[cnt]) cnt=max(dfs(a[cnt],right,cnt+1),dfs(left,a[cnt],cnt+1));
  else if(left<a[cnt])cnt=dfs(a[cnt],right,cnt+1);
  else if(right<a[cnt]) cnt=dfs(left,a[cnt],cnt+1);
  
  return cnt;
}

int main(){
  int n;
  cin>>n;
  rep(i,n){
    rep(j,10)cin>>a[j];
    //rep(j,10)cout<<a[i]<<" ";
    //cout<<endl;
    if(dfs(a[0],-INF,1)==10)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
    int n,ball;
    cin>>n;
    for(int i=0; i<n; i++){
        int a=0,b=0,flg=0;
        for(int j=0; j<10; j++){
            cin>>ball;
            if(ball>a) a=ball;
            else if(ball>b) b=ball;
            else flg=1;
        }
        cout<<(flg==0?"YES":"NO")<<endl;
    }
}