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<stdio.h>
int a[10];
int bstack[10];
int btop;
int cstack[10];
int ctop;
bool dfs(int i)
{
    bool b1=false,b2=false;
    if(i==10)
        return true;
    if(btop==-1 || bstack[btop]<a[i])
    {
        btop++;
        bstack[btop]=a[i];
        i++;
        b1=dfs(i);
        btop--;
    }
    if(ctop==-1 || cstack[ctop]<a[i])
    {
        ctop++;
        cstack[ctop]=a[i];
        i++;
        b2=dfs(i);
        ctop++;
    }
    return b1|b2;
}
int main()
{
    int n;
    while(n--)
    {
        for(int i=0;i<10;i++)
        {
            scanf("%d",&a[i]);
        }
        btop=-1;
        ctop=-1;
        if(dfs(0))
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

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

#define V vector<int>{0}

int main() {
	int n, x, z;
	cin >> n;

	for (int i = 0; i < n; i++) {
		vector< vector<int> > v = { V, V, V };
		z = 1;
		for (int j = 0; j < 10; j++) {
			cin >> x;
			for (int k = 0; k < z; k++) {
				if (v[k].back() < x) {
					v[k].push_back(x);
					break;
				}

				if (k == z - 1) {
					v[z].push_back(x);
					z++;
					break;
				}
			}

			if (z == 3) {
				x = -1;
				break;
			}
		}

		if (x == -1) {
			cout << "NO";
		}
		else {
			cout << "YES";
		}
		cout << endl;
	}
	return 0;
}

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

int main(){
    int i,j,k,fl;
    int a[10],b[10]={0};
    int ball[10];
    cin >> k;
    for(int g=0;g<k;g++){
        fl=0;
        for(int n=0;n<10;n++) cin >> ball[n];
        i=1;
        j=0;
        a[0] = ball[0];
        for(int n=1;n<10;n++){
            if(ball[n] < a[i] && ball[n] < b[j]){
                cout << "NO" << endl;
                fl = 0;
                break;
            }
            else if((ball[n] - a[i] > ball[i] - b[j]) && ball[n] > b[j]){
                b[j] = ball[n];
                j++;
                fl = 1;
            }
            else if((ball[n] - a[i] < ball[i] - b[j]) && ball[n] > a[i]){
                a[i] = ball[n];
                i++;
                fl = 1;
            }
        }
        if(fl == 1) cout << "YES" << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,a;
  int b = 11,c = 11;
  cin >> n;
  while(n--){
    for(int i = 0;i < 10;i++){
      cin >> a;
      if(b > a)b = a;
      else if(c > a)c = a;
      else {
	cout << "NO" << endl;
	return 0;
      }  
    }
    cout << "YES" << endl;
  }
  return 0;
}

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

int balls[20];
int R, L;

bool dfs(int n) {
  if (n == 10) {
    return true;
  }
  if (R < balls[n]) {
    R = balls[n];
    if (dfs(n+1)) {
      return true;
    }
  }
  if (L < balls[n]) {
    L = balls[n];
    if (dfs(n+1)) {
      return true;
    }
  }
  return false;
}

int main(void) {
  int N;
  cin >> N;
  while (N--) {
    for (int i = 0; i < 10; i++) {
      cin >> balls[i];
    }
    R = balls[0];

    if (dfs(1)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }

  return 0;
}

C++: #include <cstdio>
int T,a[10];
void solve(){
    for(int i=0;i<(1<<10);i++){
        int pre1=0,pre2=0,flag=1;
        for(int j=0;j<10;j++){
            if((1<<j)&i){
                if(a[j]<pre1){flag=0;break;}
                pre1=a[j];
            }else{
                if(a[j]<pre2){flag=0;break;}
                pre2=a[j];
            }
        }if(flag){puts("YES");return;}
    }puts("NO"); return;
}
int main(){
    scanf("%d",&T);
    while(T--){
        for(int i=0;i<10;i++)scanf("%d",a+i);
        solve();
    }return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

bool dfs(vector<int>::iterator iter, vector<int>::iterator end, int left, int right) {
  if(iter == end) return true;
  bool res = false;
  if(*iter > left) res |= dfs(iter + 1, end, *iter, right);
  if(*iter > right) res |= dfs(iter + 1, end, left, *iter);
  return res;
}

bool solve() {
  vector<int> a(10);
  for(int i = 0;i < 10;i++) cin >> a[i];
  return dfs(begin(a), end(a), 0, 0);
}

int main() {
  int t;
  cin >> t;
  for(int i = 0;i < t;i++) {
    if(solve()) {
      cout << "YES" << endl;
    }
    else {
      cout << "NO" << endl;
    }
  }
}

C++: int a[10];

bool dfs(int k, int B, int C){
    if(k == 10) return true;
    if(a[k] > B){
        if(dfs(k + 1, a[k], C))
            return true;
    }
    if(a[k] > C){
        if(dfs(k + 1, B, a[k]))
            return true;
    }
    return false;
}

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

int main(int argc, char const *argv[]){

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

    return 0;
}

C++: #include<cstdio>
#include<cstring>
int t;
int a[15];

int main()
{
    scanf("%d",&t);
    while(t--)
    {
        int i;
        int z[15],y[15];
        memset(z,0,sizeof(z));
        memset(y,0,sizeof(y));
        for( i=0;i<10;i++)
            scanf("%d",&a[i]);

            z[0]=a[0];int f=1;
            int t=0;int tt=0;
            for(int i=1;i<10;i++)
            {
                if(a[i]>z[t])
                {
                    z[++t]=a[i];
                    f++;
                }
                else if(a[i]>y[tt-1])
                    {
                        y[tt++]=a[i];
                        f++;
                    }
            }
            printf("%d!",f);
        if(f==10)printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int func(int a,int b,int c);
int ball[10];

int main(){
  int n;
  cin >> n;
  while(n--){
    for(int i=0;i<10;i++) cin >> ball[i];
    if(func(0,0,0) != 0) cout << "YES\n";
    else cout << "NO\n";
  }
}
int func(int a,int b,int c){
  int ans=0;
  if(a == 10) return 1;
  if(ball[a]>b) ans += func(a+1,ball[a],c);
  if(ball[a]>c) ans += func(a+1,b,ball[a]);
  return ans;
}

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 < 10; k++){
            scanf("%d",&current);
            if(pre > current){
				if(second_pre == -1){
					second_pre = current;
				}else{
					if(second_pre > current){
						NO_FLG = true;
						//break;
					}else{
						second_pre = current;
					}
				}
			}else{
				pre = current;
			}
        }
        if(NO_FLG==false){
        	printf("YES\n");
        }else{
        	printf("NO\n");
        }
    }
    return 0;
}