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 <vector>
#include <algorithm>
using namespace std;

int main()
{
int n;
scanf("%d", &n);
for(int testcase = 0; testcase < n; ++testcase) {
bool yes = false;
int s = 10;
vector<int> x;
x.resize(s);
for(int i = 0; i < s; ++i)
scanf("%d", &x[i]);
for(int bit = 0; bit < (1 << s); ++bit) {
int count = 0;
for(int i = 0; i < s; ++i)
count += (bit >> i) & 1;
if(count != s / 2)
continue;
bool valid = true;
for(int lr = 0; lr < 2; ++lr) {
int prev = -100;
for(int i = 0; i < s; ++i) {
if((bit >> i) == lr) {
if(prev >= x[i]) {
valid = false;
break;
}
prev = x[i];
}
}
}
if(valid) {
yes = true;
break;
}
}
printf("%s\n", yes ? "YES" : "NO");
}
return 0;
}

C++: #include <iostream>
using namespace std;
int a[20];
int b,c;
int main(){
    int ti;
    cin>>ti;
    while(ti--){
        b=c=0;
        bool flag=1;
        for(int i=1;i<=10;i++){
            cin>>a[i];
        }
        for(int i=1;i<=10;i++){
            if(b>a[i]&&c>a[i]){
                cout<<"NO"<<endl;
                flag=0;
                break;
            }
            if(a[i]>b){
                b=a[i];
                continue;
            }
            if(a[i]>c){
                c=a[i];
                continue;
            }
        }
        if(flag){
            cout<<"YES"<<endl;
        }
    }
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find(all(v), i) != (v).end())
#define ERASE(v,i) (v).erase(remove(all(v), i), (v).end())
#define INDEX(v,i) (find(all(v), i) - (v).begin())
#define rep(i,n) for(int i = 0; i < (int)n; ++i)
#define debug(x) cerr << #x << " = " << (x) << endl;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

const int INF = 100000000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

int main() {
	int N; cin >> N;
	for(int rou = 0; rou < N; rou++) {
		vector<int> data(10);
		rep(i,10) cin >> data[i];
		bool ans = false;
		for(int i = 0; i < (1<<10); i++) {
			vector<int> b;
			vector<int> c;

			rep(j,10) {
				if(i & (1<<j)) {
					b.pb(data[j]);
				} else {
					c.pb(data[j]);
				}
			}

			bool f = true;
			int bp = 0;
			int cp = 0;
			for(int j = 0, n = b.size(); j < n; j++) {
				if(b[j] < bp) f = false;
				bp = b[j];
			}
			for(int j = 0, n = c.size(); j < n; j++) {
				if(c[j] < cp) f = false;
				cp = c[j];
			}
			if(f) {
				ans = true;
				break;
			}
		}
		cout << (ans ? "YES" : "NO") << endl;
	}
	return 0;
}

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

using namespace std;

int a[10];

bool dfs(int B, int C, int i)
{
    if(i == 10)
        return true;
    else if(B < a[i])
        return dfs(a[i], C, i + 1);
    else if(C < a[i])
        return dfs(B, a[i], i + 1);
    
    return false;
}

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

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

int main() {
    int n;
    cin >> n;
    while(n--) {
        int l = 0, r = 0;
        bool ok = true;
        for(int i=0; i<10; ++i) {
            int x;
            cin >> x;
            if(l < x && r < x) {
                if(l < r) {
                    r = x;
                } else {
                    l = x;
                }
            } else if(l < x) {
                l = x;
            } else if(r < x) {
                r = x;
            } else {
                ok = false;
            }
        }
        if(ok) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}

C++: #include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;

int main(){
	int b,c,m,n,s;
	cin>>m;
	for(int i=0;i<m;i++){
		b=0,c=-1,s=0;
		for(int j=0;j<10;j++){
			cin>>n;
			if(n>b&&n>c){
				if(b>c)b=n;
				else c=n;
			}
			else if(n>b)b=n;
			else if(n>c)c=n;
			else s=1;
		}
		if(s==0)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int ball[10];
bool can = false;

void search(int r,int l,int n){
  //  cout << n << endl;
  if(n>=10) can = true;
  if(r<ball[n]) search(ball[n],l,n+1);
  if(l<ball[n]) search(r,ball[n],n+1);

}
 
int main(){
  int n;
  cin >> n;
  REP(i,n){
	REP(i,10) cin >> ball[i];
	int right=0;
	int left=0;
	can = false;
	search(right,left,0);
	if(can) cout << "Yes" << endl;
	else cout << "No" << endl;
  }

}

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

int a[12];

bool binary(int left,int right,int i);

int main()
{
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<10;j++)
		scanf("%d",&a[j]);

		if(binary(0,0,0))
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

bool binary(int left,int right,int i)
{
	if(i == 10) return true;
	if(right < a[i]) return binary(left,a[i],i+1);
	if(left < a[i]) return binary(a[i],right,i+1);
	return false;
}

C++: #include <cstdio>
#include <stack>
using namespace std;

stack<int> b,c;

int main()
{
    int ball,n;
    bool flag = true;
    scanf("%d", &n);
    for(int i=0;i<n;++i) {
        for(int j=0;j<10;++j) {
            scanf("%d", &ball);
            if (b.empty())           { b.push(ball); continue; }
            else if (b.top() < ball) { b.push(ball); continue; }
            else if (c.empty())      { c.push(ball); continue; }
            else if (c.top() < ball) { c.push(ball); continue; }
            else { flag=false; break;}
        }
        (flag) ? puts("YES") : puts("NO");
    }

    return 0;
}