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<cstring>
#include<cstdio>
#include<string>
#include<queue>
#include<algorithm>

using namespace std;

int t;
int s[15];
int a[15],b[15];
int la,lb;
bool ok;

void DFS(int index){
	if(ok){
		return;
	}
	if(index==10){
		ok=true;
		return;
	}
//	cout<<"a:"<<endl;
//		for(int i=0;i<la;i++){
//			cout<<a[i]<<' ';
//		}
//		cout<<endl;
//	cout<<"b:"<<endl;
//		for(int i=0;i<lb;i++){
//			cout<<b[i]<<' ';
//		}
//		cout<<endl;
	if(la==0||s[index]>a[la-1]){
		a[la++]=s[index];
		DFS(index+1);
		la--;
	}
	if(lb==0||s[index]>b[lb-1]){
		b[lb++]=s[index];
		DFS(index+1);
		lb--;
	}
}

int main(){
	cin>>t;
	while(t--){
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		la=lb=0;
		ok=false;
		for(int i=0;i<10;i++){
			cin>>s[i];
		}
		DFS(0);
		if(ok){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
//		for(int i=0;i<la;i++){
//			cout<<a[i]<<' ';
//		}
//		cout<<endl;
//		for(int i=0;i<lb;i++){
//			cout<<b[i]<<' ';
//		}
//		cout<<endl;
	}
	return 0;
}

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

int main(){
int a[10];
int n,b=0,c=0;
cin>>n;
for(int i=0;i<n;i++){
for(int j=0;j<10;j++){
cin>>a[j];
if(a[j]>b){b=a[j];}
if(a[j]<b&&a[j]>c){c=a[j];}
if(a[j]<b&&a[j]<c){
cout<<"NO"<<endl;
break;}
if(j==9){
cout<<"YES"<<endl;
break;}
}
}}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[15],r[15],l[15],lcnt,rcnt,cnt;
bool flag;
bool solve(){
	for(int i=0;i<1024;++i){
		memset(l,0,sizeof(l));
		memset(r,0,sizeof(r));
		lcnt=rcnt=0;
		for(int cnt=0,j=i;cnt<10;cnt++,j>>=1){
			if(j&1)l[lcnt++]=a[cnt];
			else r[rcnt++]=a[cnt];
		}
		flag=true;
		for(int j=1;j<lcnt;j++){
			if(l[j]<l[j-1]){
				flag=false;
				break;
			}
		}
		if(flag){
			for(int j=1;j<rcnt;j++){
				if(r[j]<r[j-1]){
					flag=false;
					break;
				}
			}
		}
		if(flag)return true;//只要能找出就返回true 
	}
	return false;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		for(int i=0;i<10;i++)cin>>a[i];
		puts(solve()?"YES":"NO");
	}
	return 0;
}

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

int ball[10];

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

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

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

C++: #include <stdio.h>

int main(){
int n,i,j;
int a,b,c,f;

scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a);
b=0;
f=0;
for(j=1;j<10;j++){
scanf("%d",&c);
if(a>c&&b>c)f=1;
else if(a<c&&b<c){
if(a>b)a=c;
else b=c;
}
else{
if(a>b)b=c;
else a=c;
}
}
if(f==0){
printf("YES\n");
}
else if(f==1){
printf("NO\n");
}
}
return 0;
}

C++: #include<iostream>
using namespace std;
int d[10]={};
bool f;
void dfs(int l,int r, int s){
  if(s==10) f=true;
  //cout << l << r << d[s] << endl;
  if(l<d[s]){
    dfs(d[s],r,s+1);
  }
  if(r<d[s]){
    dfs(l,d[s],s+1);
  }
}
int main(){
  int n;cin >> n;
  while(n--){
    int r=0,l=0;
    f=false;
    for(int i=0;i<10;i++){
      cin >> d[i];
      //cout << l << ":" << r << endl;
    }
    dfs(0,0,0);
    if(!f) cout << "NO" << endl;
    else cout << "YES" << endl;
  }  
}

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

bool DFS(int t_b,int t_c,int th,int* balls){
  if(th==10)return true;
  if(t_b<balls[th]&&t_c<balls[th])
      if(t_b>t_c)return DFS(balls[th],t_c,th+1,balls);
      else return DFS(t_b,balls[th],th+1,balls);
  else if(t_b<balls[th])return DFS(balls[th],t_c,th+1,balls);
  else if(t_c<balls[th])return DFS(t_b,balls[th],th+1,balls);
  else return false;
}
int main(){
  int n;
  cin>>n;
  for(int j=0;j<n;j++){
    int balls[10];
    for(int i=0;i<10;i++)cin>>balls[i];
    int t_b=0,t_c=0;int drop_balls=0;
    if(DFS(0,0,1,balls))cout<<"YES";
    else cout<<"NO";
    cout<<endl;
  }
}

C++: //dfs
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<iostream>

using namespace std;
typedef long long ll;
#define cls(x) memset(x,0,sizeof(x))


const int INF = 0x3f3f3f3f;
const int SZ = 100;

int main() {
  int total = 1 << 10;
  int n;
  cin >> n;
  int a[10];
  while(n-- > 0) {
    for(int i = 0; i < 10; ++i) {
      cin >> a[i];
    }
    bool flag;
    for(int p = 0; p < total; ++p) {
      int cur = p;
      int pre_left = -1, pre_right = -1;
      flag = true;
      for(int i = 0; i < 10; ++i) {
        if((cur >> i) & 1) {
          //left
          //cout << a[i] << endl;
          if(a[i] > pre_left) {
            pre_left = a[i];
          } else {
            flag = false;
            break;
          }
        } else {
          // right
          if(a[i] > pre_right) {
            pre_right = a[i];
          } else {
            flag = false;
            break;
          }
        }
      }
      if(flag) break;
    }
    if(flag)  {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
int l[12],r[12],q[12];
bool yon;
void dfs(int i,int j,int k){
	if(i == 10){
		yon = true;
		return ;
	}
	if(q[i] > l[j-1]){
		l[j] = q[i];
		dfs(i+1,j+1,k);
	}
	if(q[i] > r[k-1]){
		r[k] = q[i];
		dfs(i+1,j,k+1);
	}
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--){
		for(int i=1;i<=10;i++){
			scanf("%d",&q[i]);
		}
		yon = false;
		l[0] = -1;
		r[0] = -1;
		dfs(1,1,1);
		if(yon){
			printf("YES\n");
		}else{
			printf("NO\n"); 
		}
	}
	return 0;
}

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

int main(){
	int nums[10];
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int a;
		for(int j = 0; j < 10; j++){
			cin >> a;
			nums[j] = a;
		}
		int l = nums[0], r = nums[1];
		for(int i = 2; i < 10; i++){
			int minimum = min(l, r);
			int maximum = max(l, r);
			if(nums[i] < minimum){
				cout << "NO" << endl;
				break;
			}
			if(nums[i] > maximum){
				if(l > r){
					l = nums[i];
				} else {
					r = nums[i];
				}
			} else {
				if(nums[i] > l){
					l = nums[i];
				}else if(nums[i] > r){
					r = nums[i];
				}
			}
			if(i == 9)
				cout << "YES" << endl;
		}
	}
	return 0;
}