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<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    int n; cin>>n;
    rep(i,n){
        vi v(11,0); pii pr; bool check=true;
        rep(i,10)cin>>v[i];
        pr.first=v[0];
        pr.second=v[1];
        for(int j=2; j<10;j++){
            int left=(-pr.first+v[j]); int right=(-pr.second+v[j]);
            if(pr.first>v[j]&&pr.second>v[j])check=false;
            else if(left>0&&right<0)pr.first=v[j];
            else if(left<0&&right>0)pr.second=v[j];
            else if(right>left&&v[j]>pr.first)pr.first=v[j];
            else if(right<left&&v[j]>pr.second)pr.second=v[j];
            else check=false;
            
        }
        if(check)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}

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

using namespace std;
int a[15];
int dfs(int x, int y, int step)
{
    if( step == 11)
        return 1;
    if(x < a[step])  return dfs(a[step], y, step+1);
    else if(y < a[step]) return dfs(x, a[step], step+1);
    else
        return 0;
}
int main ()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        int i;
        for(i = 1; i <= 10; i++)
            scanf("%d", &a[i]);
        if(dfs(0, 0, 1))
            printf("YES\n");
        else
            printf("NO\n");
    }
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int num[2] = {0};
		int flag = 1;
		for (int j = 0; j < 10; j++) {
			int k;
			cin >> k;
			if (num[0] < k && num[1] < k) {
				num[num[0] < num[1]] = k;
			}
			else if (num[0] < k && num[1] >= k) {
				num[0] = k;
			}
			else if (num[0] >= k && num[1] < k) {
				num[1] = k;
			}
			else {
				flag = 0;
			}
		}
		if (flag) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

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

int B[11]={0};
int C[11]={0};

bool DFS(int *a,int i=0,int b=1,int c=1)
{
	bool judge=true;

	if(i==10)
		return judge;

	judge=false;

	if(B[b-1]<a[i]){
		B[b]=a[i];
		judge=DFS(a,i+1,b+1,c);
		
	}
	if(C[c-1]<a[i]){
		C[c]=a[i];
		judge=DFS(a,i+1,b,c+1);
		
	}

	return judge;
}        

int main()
{
        int N;
	int i=0;
        cin>>N;

	while(i<N){
          int A[10];
          for(int i=0;i<10;i++){
           cin>>A[i];
          }

          if(DFS(A)==true){
           cout<<"YES"<<endl;
          }
          else{
           cout<<"NO"<<endl;
          }

          i++;
        }
                
        return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int N, A[10], C = 1;

	cin >> N;

	for (int p = 0; p < N; p++)
	{
		cin >> A[0] >> A[1] >> A[2] >> A[3] >> A[4] >> A[5] >> A[6] >> A[7] >> A[8] >> A[9];

		for (int i = 0; i < 10; i++)
		{
			if (A[i] == C)
			{
				C++;
			}
		}

		for (int i = 0; i < 10; i++)
		{
			if (A[i] == C)
			{
				C++;
			}
		}

		if (C == 11)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}

		C = 1;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	int n,s,right=20,left=20,ans=0,d;
	cin>>n;
	for(int p=0;p<n;p++){
		ans=0;
		right=0;
		left=0;
		for(int q=0;q<10;q++){
			//cout<<right<<"   "<<left<<endl;
			if(right>left){//rightのほうが必ず小さい
				d=right;
				right=left;
				left=d;
			}
			cin>>s;
			if(s>left){
				left=s;
			}else if(s<right){
				ans=2;
				right=s;
			}else{
				right=s;
			}
		}
		if(ans==2){
			cout<<"NO"<<endl;
		}else{
			cout<<"YES"<<endl;
		}
	}
}

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

std::string answer;
std::vector<int> input, left, right;

void dfs(int i, std::vector<int> L, std::vector<int> R){
	int temp, L_flag, R_flag;
	std::vector<int> Add_L, Add_R;

	if(answer.compare("YES")==0 || i>9) return;

	L_flag = R_flag = 0;
	if(L.size()>0){
		temp = L[0];
		for(unsigned int j=1; j<L.size(); j++){
			if(temp>L[j]){
				L_flag = 1;
				break;
			}
			temp = L[j];
		}
	}
	if(R.size()>0){
		temp = R[0];
		for(unsigned int j=1; j<R.size(); j++){
			if(temp>R[j]){
				R_flag = 1;
				break;
			}
			temp = R[j];
		}
	}

	if(L_flag>0 || R_flag>0) { return; }
	else if(L_flag==0 && R_flag==0 && i==9) { answer = "YES"; }
	
	Add_L = L;
	Add_L.insert(Add_L.end(), input[i]);
	Add_R = R;
	Add_R.insert(Add_R.end(), input[i]);

	dfs(i+1, Add_L, R);
	dfs(i+1, L, Add_R);
}

int main(void){
	int n, number;
	std::cin >> n;

	for(int i=0;i<n;i++){
		input.clear();
		left.clear();
		right.clear();
		
		for(int j=0;j<10;j++){
			std::cin >> number;
			input.insert(input.end(), number);
		}
		answer = "CHECK";
		dfs(0, left, right);
		if(answer.compare("CHECK")==0) answer="NO";
		std::cout << answer << std::endl;
	}
	return 0;
}

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

int main(){
	int n,ball,tp[2],con;
	
	cin >> n;
	
	for(; n > 0; n--){
		
		tp[0] = tp[1] = 0;
		
		for(int i = 0; i < 10; i++){
			cin >> ball;
			
			if(tp[0] > tp[1]){
				con = 0;
			}else{
				con = 1;
			}
			
			if(ball > tp[con]){
				tp[con] = ball;
			}else if(ball > tp[!con]){
				tp[!con] = ball;
			}else{
				cout << "NO" << endl;
				break;
			}
			
			if(i == 9){
				cout << "YES" << endl;
			}
		}
	}
	
	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 = 0, r = 0;
		for(int i = 0; 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;
}