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<cstdio>

using namespace std;

int ball[10];

bool dfs(int i,int b,int c){
	if(i==10)return true;
	if(ball[i]>b && dfs(i+1,ball[i],c))return true;
	if(ball[i]>c && dfs(i+1,b,ball[i]))return true;
	return false;
}

int main(){
	int lines;
	scanf("%d",&lines);
	for(int i = 0;i<lines;i++){
		for(int j=0;j<10;j++)scanf("%d",&ball[j]);
		if(dfs(0,0,0)){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
}

C++: #include<stdio.h>

int main()
{
	int loop,right,left,data;
	int i,j;
	scanf("%d",&loop);
	while(loop-->0)
	{
		right=left=j=0;
		for(i=0;i<10;i++)
		{
			scanf("%d",&data);
			if(data>right)
				right=data;
			else if(data>left)
				left=data;
			else
				j=1;
		}
		if(j==1)
			printf("NO\n");
		else
			printf("YES\n");
	}
}

C++: #include<cstdio>
#include<cstring>
int ball[11];
int temp[2][11];
bool dfs(int x)
{
	if(x>10)
		return 1;
	if(temp[0][0]==0||temp[0][temp[0][0]]<ball[x])
	{
		temp[0][++temp[0][0]]=ball[x];
		if(dfs(x+1))
			return 1;
		temp[0][0]--;
	}
	if(temp[1][0]==0||temp[1][temp[1][0]]<ball[x])
	{
		temp[1][++temp[1][0]]=ball[x];
		if(dfs(x+1))
			return 1;
		temp[0][0]--;
	}
	return 0;
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		for(int i=1;i<=10;i++)
			scanf("%d",ball+i);
		memset(temp,0,sizeof temp);
		if(dfs(1))
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

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

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

using namespace std;

int a[10], b[2][10];
int len[2];
bool ans;


void dfs(int step) {
    if(ans) return;
    if(step == 10){
        ans = true;
    }
    for(int i = 0; i < 2; ++i){
        if(len[i] == 0 || a[step] > b[i][len[i] - 1]){
            b[i][len[i]++] = a[step];
            dfs(step + 1);
            --len[i];
        }
    }
}

void solve() {
    ans = false;
    for(int i = 0; i < 10; ++i) {
        cin >> a[i];
    }
    dfs(0);
}

int main() {
    int T;
    cin >> T;
    while(T--) {
        solve();
        cout << (ans ? "YES" : "NO") << endl;
    }
    return 1;
}

C++: public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] boll = new int[10];
		for(int k = 0; k < n; k++) {
			for(int i = 0; i < 10; i++) {
				boll[i] = scan.nextInt();
			}
			int judg = 0;
			for(int i = 0; i < n; i++) {
				int right,left;
				right = boll[0];
				left = 0;
				for(int m = 1; m < 10; m++) {
					if(right > boll[m]) {
						if(left < boll[m]) {
							left = boll[m];
						}
						else {
							judg = 0;
							break;
						}
					}
					else if(right < boll[m]) {
						right = boll[m];
					}
					judg = 1;
				}
				if(judg == 0) {
					System.out.println("NO");
				}
				else {
					System.out.println("YES");
				}
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

C++: #include <iostream>
using namespace std;
int a[10];

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

int main(){
	int T;cin>>T;
	while(T--){
		for(int i=0;i<10;i++)cin>>a[i];
		if(dfs(0,0,0))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 <cstdio>
using namespace std;
int l[12],r[12],q[12];
bool yon;
void dfs(int i,int j,int k){
	if(i == 10){
		yon = true;
		return ;
	}
	if(q[i] > l[j-1]){
		l[j] = q[i];
		dfs(i+1,j+1,k);
	}
	if(q[i] > r[k-1]){
		r[k] = q[i];
		dfs(i+1,j,k+1);
	}
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--){
		for(int i=1;i<=10;i++){
			scanf("%d",&q[i]);
		}
		yon = false;
		l[0] = -1;
		r[0] = -1;
		dfs(1,1,1);
		if(yon){
			printf("YES\n");
		}else{
			printf("NO\n"); 
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;

    for( int iii=0; iii<n; ++iii ) {
        stack<int> p[2];
        bool succ = true;

        for( int i=0; i<10; ++i ) {
            int ball;
            cin >> ball;

            if ( p[0].empty() ) {
                p[0].push( ball );

            } else {
                int diff = 999, t;
                for( int j=0; j<2; ++j ) {
                    int r = 0;
                    if ( !p[j].empty() )
                        r = ball - p[j].top();
                    if ( r < 0 )
                        continue;

                    if ( r < diff ) {
                        diff = r;
                        t = j;
                    }
                }

                if ( diff == 999 ) {
                    succ = false;
                } else {
                    p[t].push( ball );
                }
            }
        }

        cout << ( succ ? "YES" : "NO" ) << endl;
    }
}

C++: #include <iostream>

using namespace std;

int main() {
	int n; cin >> n;
	for (int t = 0; t < n; ++t) {
		int a[10];
		for (int i = 0; i < 10; ++i) cin >> a[i];

		bool ans = false;
		for (int k = 0; k < (1 << 10); ++k) {
			int top[2] = {-1, -1};
			bool f = true;
			for (int i = 0; i < 10; ++i) {
				int tid = k & i ? 1 : 0;
				if (a[i] < top[tid]) {
					f = false;
					break;
				}
				top[tid] = a[i];
			}
			ans |= f;
		}

		if (ans) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

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

using namespace std;

int main() {
	vector<int> left;
	vector<int> right;
	vector<int> all;

	bool flag = true;

	int n;
	cin >> n;
	if (n == 0) return -1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else  if (all.size() == (i+1)*(j+1)) {

						}
						else {
							flag = false;
						}			  						
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}

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

	return 0;
}