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>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> pint;
#define rep(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

int main(){
	int n;
	cin>>n;
	rep(i,n){
		int a=0,b=0;
		bool f=true;
		rep(j,10){
			int k;
			cin>>k;
			if(a<k)a=k;
			else if(b<k)b=k;
			else f=false;
		}
		cout<<(f?"YES":"NO")<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
main(){
  int n,a;
  srand((unsigned)time(NULL));
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>a;
    }
    if(rand()%2==0){
      cout<<"YES"<<endl;
    }
    else{
      cout<<"NO"<<endl;
    }
  }
}

C++: //AOJ 0033 Ball
#include<stdio.h>

int main(){
	int l,r,tmp;
	int n;
	scanf("%d",&n);
	while(n--){
		l = r = 0;
		bool flag = true;
		for(int i = 0;i<10;++i){
			scanf("%d",&tmp);
			if(!flag)continue;
			if(tmp<l&&tmp<r){
				flag = false;
				continue;
			}
			if(l>r){
				if(l<tmp)l=tmp;
				else r = tmp;
			}
			else{
				if(r<tmp)r=tmp;
				else l = tmp;
			}
		}
		if(flag)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
#include<string>
#include<cstring>
#include<cmath>
#include<bitset>
#include<set>
#include<map>
#include<sstream>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
int n;
int num[11];
int rr,lll;
bool b;
void dfs()
{
	bitset<10> ans;
	int alll=1<<10;
	while(alll-->0)
	{
		ans=static_cast<bitset<10> >(alll);
		bool b=true;
		rr=0;
		lll=0;
		rep(i,10)
		{
			if(ans[i])
			{
				if(num[i]>lll)
				{
					lll=num[i];
				}
				else
				{
					b=false;
					break;
				}
			}
			else
			{
				if(num[i]>rr)
				{
					rr=num[i];
				}
				else
				{
					b=false;
					break;
				}
			}
		}
		if(b)break; 
	}
	if(alll>=0)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return;
}
int main()
{
	cin>>n;
	while(n--)
	{
		rep(i,10)cin>>num[i];
		dfs();
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>

using namespace std;

int ball[16];

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

int main()
{
	int n;

	cin >> n;

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

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

C++: #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int s1=0,s2=0;
		bool flag =1;
		for(int i=0;i<10;i++)
		{
			int n;
			cin>>n;
			if(i==0)
			{
				s1=n;
			}
			else
			{
				if(n>s1 && n>s2)
				{
					if(s1>s2)
						s1=n;
					else
						s2=n;
				}
				else if(n>s1 && n<s2)
				{
					s1=n;
				}
				else if(n>s2 && n<s1)
					s2=n;
				else 
				{
					flag=0;
					break;
				}
				
				
			}
		}
		if(flag)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

C++: #include<stdio.h>  
#include<string.h>  
int x[15],l[15],r[15];  
int kase;  
void dfs(int i,int j,int k)
{  
    if(i>10)
    {  
        kase=1;  
        return;  
    }  
    if(kase)  
    {  
        return;  
    }  
    if(x[i]>l[j-1])
    {  
        l[j]=x[i];dfs(i+1,j+1,k);  
    }  
    if(x[i]>r[k-1])
    {  
        r[k]=x[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",&x[i]);  
        }  
        kase=0;  
        dfs(1,1,1);  
        if(kase)  
        {  
            printf("YES\n");  
        }  
        else  
        {  
            printf("NO\n");  
        }  
    }  
    return 0;  
}

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

using namespace std;

const int BALL_NUM = 4;

long n;

bool IsLeft(int num, int left, int right) {
    if (left > num) { return false; }
    if (left > right || right > num) { return true; }
    else { return false; }
}

int main() {
    int b, left = 0, right = 0;
    bool flag = true;
    scanf("%ld", &n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < BALL_NUM; j++) {
            scanf("%d", &b);
            printf("%d %d %d ", b, left, right);
            if (b < min(left, right)) {
                printf("%d\n", 0);
                flag = false;
                break;
            }
            if (IsLeft(b, left, right)) { printf("%d\n", 1); left = b; }
            else { printf("%d\n", 2); right = b; }
        }
        if (flag) { printf("%s\n", "YES"); }
        else { printf("%s\n", "NO"); }
    }

    return 0;
}

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>
using namespace std;

int main(){
	int N;
	int A[11];
	int cnt1=0;
	cin>>N;
	while(1){
		
		if(cnt1==N){
			break;
		}
		cnt1++;
		for(int i=1;i<=10;i++){
			cin>>A[i];
		}
		int B=A[1];
		int C=0;
		int cnt2=0;
		int cnt3=2;
		for(int i=2;i<=10;i++){
			if(B+1==A[i]){
				B=A[i];
				cnt2++;
			}
			else if(C<A[i]){
				C=A[i];
				cnt2++;
			}
			
			cnt3++;	
		}
		if(cnt2==9){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}
	return 0;	
}

C++: #include <iostream>

using namespace std;

int ball[10];

bool dfs (int n, int a, int b)
{
    if (n==10) return true; //no ball left
    if (ball[n]>a) return dfs(n+1,ball[n],b); //search further
    if (ball[n]>b) return dfs(n+1,a,ball[n]);
    return false;
}

int main()
{
    //DFS for the first time
    int n;
    cin>>n;
    bool ret[n];
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<10; j++) cin>>ball[j];
        ret[i]=dfs(0,0,0);
    }
    for (int i=0; i<n; i++)
    {
        if (ret[i]) cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}