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 <algorithm>
#include <functional>
#include <vector>
#include "stdio.h"
#include <string>
int si[10];
bool stack(int left, int right, int i){
	if (i == 9){
		if (left < si[i] || right < si[i]){
			return true;
		}
		else return false;
	}
	else if (left <= si[i]){
		return stack(si[i], right, i + 1);
	}
	else if (right <= si[i]){
		return stack(left, si[i], i + 1);
	}
	else return false;
}
int main(){
	int n;
	std::cin >> n;
	for (int e = 0; e<n; e++){
		for (int ai = 0; ai<10; ai++){
			std::cin >> si[ai];
		}
		if (stack(0, 0, 0) == true){
			std::cout << "YES\n";
		}
		else {
			std::cout << "NO\n";
		}
	}
}

C++: #include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int T;
int t[10];

bool solve(){
  int left=0,right=0;
  rep(i,10){
    if(t[i] < left && t[i] < right) return false;
    if(t[i] > left){
      if(t[i] > right && left < right){
        right = t[i];
      }
      else{
        left = t[i];
      }
    }
    else{
      right = t[i];
    }
  }
  return true;
}

int main(){
  cin>>T;
  while(T--){
    rep(i,10){
      cin>>t[i];
    }
    cout<<(solve() ? "YES" : "NO")<<endl;
  }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n,a,b,c;
	bool f;
	cin>>n;
	for(int i=0;i<n;i++){
		f=true;b=0;c=0;
		for(int j=0;j<10;j++){
			cin>>a;
			if(b>a&&c>a){
				f=false;
				break;
			}else if(b<a && c<a){
				if(b>=c)b=a;
				else c=a;
			}else if(b<a){
				b=a;
			}else if(c<a){
				c=a;
			}
		}
		if(f)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

	int n;
	cin>>n;

	int B=0,C=0;
	for(int i = 0; i < n; i++){
		bool f=false;
		vector<int> numList;
		for(int j = 0; j < 10; j++){
			int t;
			cin>>t;
			numList.push_back(t);
		}

		for(int j = 0; j < 10; j++){
			int num=numList[j];
			if(num>B&&num>C){
				if(num-B>num-C){
					C=num;
				}
				else
					B=num;
			}
			else if(num>B){
				B=num;
			}
			else if(num>C)
				C=num;
			else{
				f=true;
				cout<<"NO"<<endl;
				break;
			}
		}
		if(!f)
			cout<<"YES"<<endl;
	}

	return 0;
}

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

int main()
{
    int N;
    scanf("%d",&N);
    for(int i=0;i<N;++N) {
        int ball[10],index=0;
        for(int i=0;i<10;++i) {
            scanf("%d",&ball[i]);
        }
        while(index+2 <= 9) {
            if(ball[index] < ball[index+1]) {
                ++index;
                continue;
            } else if (ball[index] < ball[index+2]) {
                ++index;
                continue;
            } else {
                puts("NO");
                return -1;
            }
        }
        puts("YES");
        return 0;
    }
}

C++: #include<stdio.h>
int main(){
  int n;
  scanf("%d",&n);
  int ball[10];
  int i,j;
  for(j=0;j<n;j++){
    for(i=0;i<10;i++) scanf("%d",&ball[i]);
    int a=0,b=0;
    for(i=0;i<10;i++){
      if(a<ball[i]) a = ball[i];
      else if(b<ball[i]) b = ball[i];
      else{
	printf("NO\n");
	break;
      }
      if(i==9) printf("YES\n");
    }
  }
  return 0;
}

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

int main() {
	int n;
	int d[10];
	int va[10];
	int vb[10];
	int trush;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> d[i];
		}

		int ca = 0, cb = 0;
		va[0] = d[0];
		ca++;
		if (d[1] > va[0]) {
			va[1] = d[1];
			ca++;
		}

		else {
			vb[0] = d[1];
			cb++;
		}

	for (int j = 2; j < 10; j++) {

			if (d[j] > va[ca-1]) {
				va[ca] = d[j];
				ca++;
			}

			else if (d[j] > vb[cb-1]) {
				vb[cb] = d[j];
				cb++;
			}

			else if(d[j]<va[ca-1]||d[j]<vb[ca-1]){
				cout << "NO" << endl;
				goto FINLOOP;
			}
		}

	cout << "YES" << endl;
	FINLOOP:
		for (int i = 0; i < 10; i++) {
			va[i] = 0;
		}
		for (int i = 0; i < 10; i++) {
			vb[i] = 0;
		}
	}
	return 0;
}

C++: #include <cstdio>
#define loop(var,time) for (var = 0; var < (time); var++)
int balls[10];

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

int main() {
    int n;
    int tmp,i;
    scanf("%d", &n);
    loop(tmp, n) {
        loop(i,10) {
            scanf("%d", &balls[i]);
        }
        if (dfs(0,0,0)) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
}

C++: #include<cstdio>
int main()
{
	int n;
	scanf("%d", &n);
	while (n--)
	{
		int a[10];
		int b[10], c[10];
		int i,p;
		int cas=0;
		for (i = 0; i < 10; i++)
		{
			scanf("%d", &a[i]);
			if (a[i] == 1)
				p = i;
		}
		for (i = 1; i < p;i++)
		if (a[i] < a[i - 1])
			cas = 1;

		for (i = p + 1; i < 10; i++)
		{
			if (a[i]>a[p - 1] && a[i]>a[p])
				a[p - 1] = a[i];
			if (a[i] > a[p] && a[i] < a[p - 1])
				a[p] = a[i];
			if (a[i] < a[p])
				cas = 1;
		}
		if (cas == 1)
		{
			printf("NO\n");
			break;
		}
		printf("YES\n");

	}
}

C++: #include<iostream>

int ball[10];
int ls = 0, rs = 0;
bool res = true;

int main(){
	int n;
	std::cin >> n;
	for (int j = 0; j < n; j++){
		for (int i = 0; i < 10; i++)std::cin >> ball[i];

		for (int i = 0; i < 10; i++){
			int d1 = ball[i] - ls, d2 = ball[i] - rs;

			if (d1 > 0 && d2 > 0){
				if (d1 <= d2)ls = ball[i];
				else rs = ball[i];
			}
			else if (d1 > 0 && d2 < 0)ls = ball[i];
			else if (d1 < 0 && d2 > 0)rs = ball[i];
			else res = false;
		}

		std::cout << (res ? "YES" : "NO") << std::endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
        int set_number, L, R, flag = 0;
        cin >> set_number;
        array< int, 10 > ar;

        for ( int i = 0 ; i < set_number ; i++ )
        {
                for ( int j = 0 ; j < 10 ; j++ )
                {
                        cin >> ar[j];
                }

                L = ar[0];
                R = 0;
                for ( int j = 1 ; j < 10 ; j++ )
                {
                        if ( L < ar[j] )
                        {
                                L = ar[j];
                        }
                        else
                        {
                                if ( R < ar[j] )
                                {
                                        R = ar[j];
                                }
                                else
                                {
                                        cout << "NO" << endl;
                                        flag = 1;
                                        break;
                                }
                        }
                }

                if ( flag == 0 )
                {
                        cout << "YES" << endl;
                }
                flag = 0;
        }

        return 0;
}