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>
using namespace std;
#define NUM 10
int main(){
  int n;
  int ball[NUM];
  int b[NUM];
  cin>>n;
  for(int c=0;c<n;c++){
    for(int i=0;i<NUM;i++){
      cin>>ball[i];
      b[i]=-1;
    }
    int x=0;
    for(int j=0;j<NUM-1;j++){
      int t=ball[j];
      while(j<NUM-1 && t>=ball[j+1]){
	b[x]=ball[j+1];
	x++;
	j++;
      }
    }
    int f=true;
    for(int j=1;j<NUM && b[j]>0;j++){
      if(b[j]<=b[j-1]){
        f=false;
	break;
      }
    }
    if(f)
      cout<<"YES"<<endl;
    else
      cout<<"NO"<<endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
 
using namespace std;
 
#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
 
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;
 
int N;
vector<int>a;
 
int dfs(int n, int b, int c){
  if(n == 10) return 1;
 
  if(b < a[n] && dfs(n+1, a[n], c)) return 1;
  if(c < a[n] && dfs(n+1, b, a[n])) return 1;
  return 0;
}
 
int main(){
  scanf("%d", &N);
  rep(i, N){
    a.clear();
    int b;
    rep(i, 10){
      scanf("%d", &b);
      a.PB(b);
    }
 
    printf("%s\n", dfs(0, 0, 0)?"YES":"NO");
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int a[10];

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

int main() {
    int n;
    cin >> n;
    while (n--) {
        for (int i = 0; i < 10; i++) {
            cin >> a[i];
        }
        if (dfs(0, 0, 0) == true) {
            cout << "YES" << endl;
        }
        else {
            cout << "NO" << endl;
        }
    }

    return 0;
}

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

int main(){
  int n;
  cin>>n;
  for(int k=0;k<n;k++){
    vector<int> a(10);
    for(int i=0;i<10;i++)cin>>a[i];
    int x=a[0];
    int y=0;
    int fl=1;
    for(int i=1;i<10;i++){
      if(x>a[i]&&y>a[i]){
        fl=0;
        cout<<"NO"<<endl;
        break;
      }
      if(x>=y){
        if(x<a[i]){
          x=a[i];
        }else{
          y=a[i];
        }
      }else{
        if(y<a[i]){
          y=a[i];
        }else{
          x=a[i];
        }
      }
    }
    if(fl)cout<<"YES"<<endl;
  }
}

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

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

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

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

			if (!i) {
				a = x;
			}
			else {
				if (x > a) {
					a = x;
				}
				else {
					if (!b) {
						b = x;
					}
					else if (x>b) {
						b = x;
					}
					else {
						f = 1;
					}
				}
			}
		}

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

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

using namespace std;

vector<int> a;
stack<int> b, c;

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

	bool res1 = false, res2 = false;

	if (b.empty()) {
		b.push(a[i]);
		res1 = dfs(i + 1);
		b.pop();
	} else if(c.empty()) {
		c.push(a[i]);
		res2 = dfs(i + 1);
		c.pop();
	} else {
		if (b.top() < a[i]) {
			b.push(a[i]);
			res1 = dfs(i + 1);
			b.pop();
		}
		if (c.top() < a[i]) {
			c.push(a[i]);
			res2 = dfs(i + 1);
			c.pop();
		}
	}

	return res1 || res2;
}

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

	while (n--) {
		a.clear();
		while (b.size()) b.pop();
		while (c.size()) c.pop();

		for (int i = 0; i < 10; ++i) { int v; cin >> v; a.push_back(v); }

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

C++: #include<iostream>
#include<vector>
#include<stdlib.h>
using namespace std;
vector<int> balls;
bool dfs(int i,int left,int right,int len)
{
	if(i==len&&(balls[i-1]>left||balls[i-1]>right))return 1;
	if(balls[i-1]<left&&balls[i-1]<right)return 0;
	if(balls[i-1]>left){
		return dfs(i+1,balls[i-1],right,len);
	}
	if(balls[i-1]>right){
		return dfs(i+1,left,balls[i-1],len);
	}
	
}
int main()
{
	int T;
	cin>>T;
	while(T--){
		int x;
		while(cin>>x){
			balls.push_back(x);
		}
		int len=balls.size();
		if(dfs(1,-1,-1,len)){
			cout<<"YES"<<endl;
		}else cout<<"NO"<<endl;
	}
}

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] && d[j] < vb[cb - 1]) {
			cout << "NO" << endl;
			goto FINLOOP;
		}

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

			else if (d[j] > vb[cb - 1]) {
				vb[cb] = d[j];
				cb++;
			}
			
		}
		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 <iostream>
#include <cstdio>
using namespace std;

int main(){
    int n,s;
    cin >> n;
    for (int i=-; i < n; i++){
        int a=0, b=0, flg=0;
        for (int j = 0; j < 10; j++)}{
            cin >> s;
            if (s > a) a=s;
            else (s > b) b=s;
            else flg = 1;
        }
        printf("%s\n", flg==0? "YES": "NO");
    }
}

C++: #include<iostream>
int topA=-1, topB=-1,B;
int times;
int main(){
	std::cin >> times;
	for (int j = 0; j < times; j++){
		for (int i = 0; i < 10; i++){
			std::cin >> B;
			if (topA == -1 && topB == -1){
				topA = B;
			}
			else if (topA != -1 && topB == -1){
				topB = B;
			}
				else if (topA < B){
					topA = B;
				}
				else if (topB < B){
					topB = B;
				}
				else{
					std::cout << "NO\n";
					goto rip;
				}
			}
		std::cout << "YES\n";
	rip:;
		topA = -1,topB=-1;
		}

}

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;
    }
  }
}