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<fstream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

vector<int> v(10);

int l,r;
int flag;

void dfs(int d){

    if(d==10){
        flag=1;
        return;
    }

    if(flag) return;

    int x = v[d];

    if(x>l){

        int tmp = l;
        l=x;
        dfs(d+1);
        l=tmp;

    }

    if(flag) return;

    if(x>r){

        int tmp = r;
        r=x;
        dfs(d+1);
        r = tmp;

    }

}

int main(){

    int N;

    cin >> N;

    for(int t=0;t<N;++t){

        for(int i=0;i<10;++i)cin >> v[i];

        l = r = flag = 0;

        dfs(0);

        if(flag)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;

    }

    return 0;

}

C++: #include<iostream>
using namespace std;
int main(void)
{
int n;
cin>>n;

for(int i=0;i<n;i++)
{
	int a[10]={0};
	for(int j=0;j<10;j++)
	{
	int x;
	cin>>x;
	a[j]=x;
	}
	int b=a[0],c=a[0],k;
		for(k=1;k<10;k++)
		{
			if(b<a[k])b=a[k];
			else if(c<a[k])c=a[k];
			else 
			{
			cout<<"NO"<<endl;
			break;
			}
		}
		if(k==10)cout<<"YES"<<endl;
	/*for(int i=0;i<10;i++)
	{
	cout<<b[i]<<" ";

	}
	cout<<endl;
	for(int i=0;i<10;i++)
	{
	cout<<c[i]<<" ";
	}
	for(int i=0;i<10-1;i++)
	{
		if(b[i]>b[i+1] && b[i+1]!=0 || c[i]>c[i+1] && c[i+1]!=0)
		{
		cout<<"NO"<<endl;
		break;
		}
	else 
		{
		cout<<"YES"<<endl;
		break;
		}
	}*/
}
return 0;
}

C++: #include<algorithm>
#include<stdio.h>
#include<vector>
#include<queue>

using namespace std;

int A[13] = { 0 };

bool solve(int a, int b,int c) {
	if (++c == 10)
		return true;
	else {
		bool r = false;
		if (a < A[c])
			r = solve(A[c], b, c);
		if (b < A[c] && r == false)
			r = solve(a,A[c], c);
		
		return r;
	}
}

int main(void) {
	A[10] = A[11] = A[12] = 100;
	int n = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++)
			scanf("%d", &A[j]);
		if (solve(A[0], 0, 0))
			printf("YES\n");
		else
			printf("NO\n");
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

bool flag;
int a[10], b[10], c[10];

void dfs(int ap, int bp, int cp){
  
  // cout << ap << ' ' << bp << ' ' << cp << endl;

  if(ap == 10){
    flag = true;
    return;
  }

  if(ap < 2){
    if(ap){
      b[0] = a[ap];
      dfs(ap + 1, bp + 1, cp);
      b[bp] = 0;
    }
    else{
      c[0] = a[ap];
      dfs(ap + 1, bp, cp + 1);
      c[cp] = 0;
    }
  }
  else{

    if(a[ap] > b[bp - 1]){
      b[bp] = a[ap];
      dfs(ap + 1, bp + 1, cp);
      b[bp] = 0;
    }
    
    if(a[ap] > c[cp - 1]){
      c[cp] = a[ap];
      dfs(ap + 1, bp, cp + 1);
      c[cp] = 0;
    }

  }

  return;

}

int main(){

  int n;

  cin >> n;

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

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

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

  }

}

C++: #include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
int a[10];
for(int j=0;j<10;j++)scanf("%d",&a[i]);
bool ans=true;
for(int j=0;j<10;j++){
for(int k=j+1;k<10;k++){
for(int l=k+1;l<10;l++){
if(a[j]>a[k]&&a[k]>a[l])ans=false;
}
}
}
if(ans)printf("YES\n");
else printf("NO\n");
}
return 0;
}

C++: #include <cstdio>

using namespace std;

int ball[10];

bool dfs(int left, int right, int n) {
  if (n == 10) return true;
  return ((left < ball[n]) && dfs(ball[n], right, n + 1)) ||
    ((right < ball[n]) && dfs(left, ball[n], n + 1));
}

int main() {
  int n;
  scanf("%d", &n);

  while (n--) {
    for (int i = 0; i < 10; ++i) {
      scanf("%d", &ball[i]);
    }

    if (dfs(0, 0, 0)) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
  
  return 0;
}

C++: using namespace std;

#include <cstdio>

int a[10];

bool dfs(int i, int l, int r){
	if (i == 10){
		return true;
	}
	if (l < a[i]){
		return dfs(i + 1, a[i], r);
	}
	if (r < a[i]){
		return dfs(i + 1, l, a[i]);
	}
	return false;
}

int main(){
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			scanf("%d", &a[j]);
		}
		printf("%s\n", dfs(0, 0, 0) ? "YES" : "NO");
	}
	return 0;
}

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

int value[10];

string dfs(int left,int right,int i)
{
	if(i == 10) return "YES";
	if(left < value[i])
	{
		return dfs(value[i],right,i+1);
	}
	if(right < value[i])
	{
		return dfs(left,value[i],i+1);
	}
	return "NO";
}


int main()
{
	int n;
	cin >> n;
	
	while(n--)
	{
		for(int i=0;i<10;i++)	
		{
			cin >> value[i];	
		}
		cout << dfs(0,0,0) << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int n, ball[10];

bool solve(int idx, int l, int r) {

    if(idx == 10) return true;

    bool ret = false;
    if(ball[idx] > l) ret = ret || solve(idx + 1, ball[idx], r);
    if(ball[idx] > r) ret = ret || solve(idx + 1, l, ball[idx]);
    return ret;

}

int main() {

    cin >> n;

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < 10; ++j) {
            cin >> ball[j];
        }
        cout << (solve(0, 0, 0) ? "YES" : "NO") << endl;
    }

}

C++: 2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1

C++: #include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		int in[10];
		for(int j=0;j<10;j++){
			cin >> in[j];
		}
		bool ok=true;
		int low=0,hi=0;
		for(int j=0;j<10;j++){
			if(in[j]<=low){
				ok=false;
				break;
			}
			if(in[j]<hi){
				low=in[j];
			}
			else{
				hi=in[j];
			}
		}
		if (ok){
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}

C++: #include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
int a[10];
bool ans;
void dfs(int i,int r,int l){
	if(i==10)return;
	if(ans==0)return;
	if(r<a[i])dfs(i+1,a[i],l);
	else if(l<a[i])dfs(i+1,r,l);
	else ans=0;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		for(int i=0;i<10;i++)cin>>a[i];
		dfs(0,0,0);
	if(ans)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	}
}

C++: #include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;

int main(){
    int mod=1000000007;
    int a,b,c;
    int ans[2]={0,0};
    int n;
    scanf("%d",&n);
    for (int i=0;i<n;++i) {
        int l=0,r=0;
        vector<int> a(10);
        for(auto&e:a) {
            scanf("%d",&e);
        }
        int f=1;
        for (int j=0;j<10;++j) {
            if (j==0) l=a[0];
            else if (a[j]<l && a[j]<r) {
                f=0;
                printf("NO\n");
                break;
            } else if (a[j]>l && a[j]<r) {
                l=a[j];
            } else if (a[j]<l && a[j]>r) {
                r=a[j];
            } else if ((a[j]-l)>(a[j]-r)) {
                r=a[j];
            } else {
                l=a[j];
            }
        }
        if (f) printf("YES\n");
    }
    return 0;
}