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<cstring> 
#include <cmath> 
#include<stack>
#include<vector>
#include<map> 
#include<set>
#include<queue> 
#include<algorithm>  
using namespace std;

typedef long long LL;
const int INF = (1<<30)-1;
const int mod=1000000007;
const int maxn=105;

int a[maxn];
int b[maxn],c[maxn];
int cnt1,cnt2;

bool ok(int b[],int c[]){
	for(int i=0;i<cnt1;i++){
		if(b[i] < b[i-1]) return false;
	}
	
	for(int i=0;i<cnt2;i++){
		if(c[i] < c[i-1]) return false;
	}
	return true;
}

int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		for(int i=0;i<10;i++) scanf("%d",&a[i]);
		
		int flag=0;
		for(int i=0;i< 1<<10;i++){
			 cnt1=0;cnt2=0;
			memset(b,0,sizeof(b));
			memset(c,0,sizeof(c));
			for(int j=0;j<10;j++){
				if(i>>j & 1) b[cnt1++]=a[j];
				else c[cnt2++]=a[j];				
			}
			
			if(ok(b,c)){
					flag=1;
					break;			
				}	
		//	printf("cnt1=%d  cnt2=%d\n",cnt1,cnt2);
		}
		if(flag) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <stack>
#include <sstream>
using namespace std;
int main(){
  int nlist[10],n,a;
  stack<int> b,c;
  b.push(0),c.push(0);
  bool f;
  cin>>n;
  for(;n;n--){
    f=true;
    for(int i=0;i<10;i++)
      cin>>nlist[i];
    for(int j=0;j<10;j++){
      a=nlist[j];
      if(!b.top())b.push(a);
      else{
	if(b.top()>a){
	  if(c.top()>a){f=false;break;}
	  else{c.push(a);}
	}
	else{b.push(a);}
      }
    }
    (f)?cout<<"YES"<<endl:cout<<"NO"<<endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<string.h>
int a[13],vis[13],flag;
void dfs(int x,int l,int r)
{
   	int i;
   	if(x==11)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()
{
	int T,i,j,k;
	scanf("%d",&T);
	while(T--)
	{
		flag=0;
		for(i=1;i<=10;i++)
		scanf("%d",&a[i]);
	memset(vis,0,sizeof(vis));
		dfs(1,0,0);
		if(flag)printf("NO\n");
		else printf("YES\n");
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#pragma region defins
#define ll long long
#define loop(i,n) for (int i = 0; i < n; i++)
#define loops(i,f,n) for (int i = (f); i < n; i++)
#define INF 100000000000000
#define sort(a) sort(a.begin(),a.end())
#define rsort(a) sort(a.rbegin(),a.rend())
using namespace std;
#pragma endregion
vector<int> balls(10);
bool dfs(int now, int btop, int ctop)
{
	if (now == 10)return true;
	if (balls[now] > btop)dfs(now + 1, balls[now], ctop);
	else if (balls[now] > ctop)dfs(now + 1, btop, balls[now]);
	else return false;
}

int main()
{
	int n; cin >> n;
	loop(i, n)
	{
		loop(i, 10)cin >> balls[i];
		cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
	}
}

C++: #include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
    int N,pre,current,second_pre;
    bool NO_FLG;

    scanf("%d",&N);
    for(int i=0;i<N;i++){
        pre = -1;
        second_pre = -1;
        NO_FLG = false;
        for(int k = 0; k < 9; k++){
            scanf("%d",&current);	//????????????????????????
            if(k == 0){	//??????????????????????????´?????????????????????
                pre = current;
            }else{
                if(pre > current){	//1?????????????????????????????§????????´???,current?????????1????????????????§????
                    if(second_pre == -1){	//?°?????????°????????\?????????????§????
                        second_pre = current;
                    }else{
                        if(second_pre > current){ //2????????????????????°??????current???????????§????????´???
                            printf("NO\n");
                            NO_FLG = true;
                            break;
                        }else{	//2????????????????????°??????current??????????°?????????´???
                            second_pre = current;
                        }
                    }
                }else{ //pre < current
                	pre = current;
                }
            }
        }
        if(!NO_FLG)printf("YES\n");

    }
    return 0;
}

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


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 res=0;
	int n;
	scanf("%d",&n);
	for(a=0;a<n;a++){
		memset(ball,0,sizeof(ball));
		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<iostream>
using namespace std;
int X,Y;
const int N=10;
int D,ball[N];

bool solve(int i){
	if(i==N)return true;//iがボールの個数に追いついたら終了
	if(X<ball[i]){//入るボールが入ってるボールより大きければ
	X=ball[i];//ボールを入れる
		if(solve(i+1))return true;
	
	}
	if(Y<ball[i]){
	Y=ball[i];
		if(solve(i+1))return true;
	}
	return false;

}
//solve関数　終わる条件→
//solve関数に入った初めの処理→
//solve関数に入って２回目の処理→


int main(){
	cin>>D;
	for(int l=0;l<D;l++){
		for(int i=0;i<N;i++)cin>>ball[i];
		X=ball[0];//一つ目のボールを右に入れておく
			if(solve(1))cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
}	

return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define Sort(x) sort((x).begin(),(x).end())
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

ll gcd(ll a,ll b){
    if(a<b){
        int t=a;a=b;b=t;
    }
    int c=a%b;
    while(c!=0){
        a=b;
        b=c;
        c=a%b;
    }
    return b;
}

ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}

bool isPrime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0)return false;
    }
    return true;
}

int kaizyo(int x){
    if(x==1)return x;
    else return x*kaizyo(x-1);
}

vector<int> v(10);
bool f=true;
bool dfs(int i,int top1,int top2){
    if(!f)return false;
    if(i==10)return true;
    
    
    if(top1>v[i]&&top2>v[i]){
        f=false;
        //return false;
    }
    else if(top1<v[i]&&top2>v[i]) {
        if(!dfs(i+1,v[i],top2))f= false;
        //return true;
    }
    else if(top1>v[i]&&top2<v[i]){
        if(!dfs(i+1,top1,v[i]))f= false;
        //return true;
    }
    else if(top1<v[i]&&top2<v[i]){
        if(top1<top2){if(!dfs(i+1,top1,v[i]))f=false;}
        else if(!dfs(i+1,v[i],top2))f= false;
        //return true;
    }
    if(f)return true;
    else return false;
}
int main() {
    int n;
    cin>>n;
    rep(i,0,n){
        rep(i,0,10){
            cin>>v[i];
        }
        if(dfs(0,0,0))cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}