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<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int maxn = 100;
int cas_e;
int b[10],l[10]={0},r[10]={0};
void dfs(int x,int y,int z)
{
    if(x==10){cas_e=1;return;}
    if(cas_e){return;}
    if(b[x]>l[y]){l[y]=b[x];dfs(x+1,y+1,z);}
    if(b[x]>r[z]){r[z]=b[x];dfs(x+1,y,z+1);}
}
int main()
{
    int a;
    cin>>a;
    while(a--)
    {
        for(int i=0;i<10;i++)
        {
            cin>>b[i];
        }
        cas_e=0;
        dfs(0,0,0);
        if(cas_e){cout<<"YES"<<endl;}
        else{cout<<"NO"<<endl;}
    }
    return 0;
}

C++: /* 
 author:hdsdogge 
 begin: 
 end: 
 cost: 
 */
#include<iostream>
#include<string>
#include<queue>
#include<map>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<vector>
#include<bitset>
#include<cstdlib>
#include<list>
#include <sstream>
#include<ctype.h>
using namespace std;
const int maxn=100+10;
typedef pair<int,int> P;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
int T,n,m;
int a[maxn];
bool ans;
void dfs(int l,int r,int cnt){
    if(cnt==10)
        ans=true;
    if(a[cnt]>l)
        dfs(a[cnt],r,cnt+1);
    if(a[cnt]>r)
        dfs(l,a[cnt],cnt+1);
}
int main() {
    //freopen("test","r",stdin);
    //freopen("out","w",stdout);
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cin>>T;
    while(T--){
        for(int i=0;i<10;i++)
            cin>>a[i];
        ans=false;
        dfs(0,0,0);
        if(ans)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

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

using namespace std;

int main(void) {
    int N, a, b, c;
    cin >> N;
    for (; N--; ) {
        b = c = 0;
        bool ok = true;
        for (int i = 0; i < 10; i++) {
            cin >> a;
            if (a < b && a < c) {
                ok = false;
                break;
            } else if (a < b) {
                c = a;
            } else if (a < c) {
                b = a;
            } else if (b > c) {
                b = a;
            } else {
                c = a;
            }
        }
        cout << (ok ? "YES" : "NO") << endl;
    }
    return 0;
}

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

using namespace std;

int pou[12] = {0};


int dfs(int nau,int b,int c){
  if(nau == 11) return 1;
  if(pou[nau-1] > b){
    if( dfs(nau+1,pou[nau-1],c) == 1){
      return 1;
    }
  }

  if(pou[nau-1] > c){
    if( dfs(nau+1,b,pou[nau-1])==1){
      return 1;
    }
  }

  return 0;
}



int main(){

  int n=0;

  scanf("%d",&n);

  for(int i = 0;i < n;i++){

    for(int j = 0;j < 10;j++){
      scanf("%d",&pou[j]);
    }

    if(dfs(1,0,0) == 1){
      printf("YES\n");
    }else{
      puts("NO");
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;


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

C++: #include <stdio.h>

#include <stack>

int main(void){
    using namespace std;
    stack<int> a,b;
    int n,j,i,ball,flag;
    scanf("%d",&n);
    for(j=0; j<n; j++){
        flag=0;
        for(i=0; i<10; i++){
            scanf("%d",&ball);
            if(a.empty()){
                a.push(ball);
            }else if(a.top() < ball){
                a.push(ball);
            }else if(b.empty()){
                b.push(ball);
            }else if(a.top() < ball){
                b.push(ball);
            }else{
                flag=1;
            }
        }
        if(flag==0){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}

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

int main(){
	int n;
	std::cin >> n;
	while (n){
		std::vector<int> ball(10);
		for (int i = 0; i < 10; ++i)std::cin >> ball[i];
		int b = 0, c = 0;
		for (int i = 0; i < 10; ++i){
			if (b < c){
				std::swap(b, c);
			}
			else if (b < ball[i]){
				b = ball[i];
			}
			else if (c < ball[i]){
				c = ball[i];
			}
			else {
				std::cout << "NO" << std::endl;
				break;
			}
			if(i==9){
				std::cout << "YES" << std::endl;
				break;
			}
		}
		n--;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
 
int balls[10];
 
bool dfs(int idx, int b, int c){
    if(idx > 9) return true;
     
    bool ok = false;
    if(b < balls[idx]) ok = dfs(idx+1, balls[idx], c);
    if(c < balls[idx]) ok = dfs(idx+1, b, balls[idx]);
    return ok;
}
 
int main() {
    int n; cin >> n;
    while(n--){
        for(int i = 0; i < 10; i++) cin >> balls[i];
	cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
    }
}

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

bool dfs(vector<int> que, int index, int left, int right) {
    if (index == que.size()) {
        return true;
    } else {
        bool res = false;
        if (que[index] > left) res |= dfs(que, index+1, que[index], right); 
        if (que[index] > right) res |= dfs(que, index+1, left, que[index]); 
        return res;
    }
}

int main() {
    int T; cin >> T;
    string s;
    getline(cin, s);
    for (int i = 0; i < T; i++) {
        vector<int> v;
        getline(cin, s);
        stringstream ss(s);
        int t;
        while (ss >> t) v.push_back(t);

        cout << (dfs(v, 0, 0, 0) ? "YES" : "NO") << endl;
    }
}

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

int n;
int a[10];


bool dfs(int i, int left, int right) {
    if (i == 9) return a[i] > left || a[i] > right;
    if (a[i] > left && dfs(i+1, a[i], right)) return true;
    if (a[i] > right && dfs(i+1, left, a[i])) return true;
    return false;
}

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

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

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

int Balls[10];

bool dfs(int i, int R, int L)
{
	if(i == 10) return true;

	if(dfs(i+1, Balls[i], L) && Balls[i] > R) return true;

	if(dfs(i+1, R, Balls[i]) && Balls[i] > L) return true;

	return false;
}

void main()
{
	int n;

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

		if(dfs(0, 0, 0)) cout << "YES\n";
		else cout << "NO\n";
	}
}