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 <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
const ll INF = 114514810;
const ll MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
//int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///


int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		int l = 0, r = 0;
		bool f = true;
		REP(i, 10)
		{
			int t;
			cin >> t;
			if (t > l) l = t;
			else if (t > r) r = t;
			else f = false;
		}
		puts(f ? "YES" : "NO");
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <cctype>
#include <cstdlib>
#include <set>
#include <map>
#include <sstream> 
#define  ll long long
using namespace  std;
const    ll   len=105;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		vector<int>v1;
		vector<int>v2;
		int j=0;
		int w=0,temp;
		for(int i=0;i<10;i++)
		{
			cin>>temp;
			if(i==0)
				v1.push_back(temp);
			else
			{
				if(v1[v1.size()-1]<temp)
					v1.push_back(temp);
				else
				{
					if(v2.size()==0)
						v2.push_back(temp);
					if(v2[v2.size()-1]>temp&&v2.size()!=0)
						w=1;
					else
					if(v2[v2.size()-1]<temp&&v2.size()!=0)
						v2.push_back(temp); 	
				}  
			}
		}
		if(w==1)printf("NO\n");
		else
		 printf("YES\n");
	}
	return 0;
}

C++: #include <iostream>
#include <stdlib.h>
#include <queue>

using namespace std;

int main() {

	int n;
	int num[10];
	int min_A = 0, min_B = 0;
	int pos;

	while (cin >> n)
	{
		while (n-- > 0)
		{
			for (int i = 0; i < 10; i++)
			{
				cin >> num[i];
			}
			for ( pos = 0; pos < 10; pos++)
			{
				if (num[pos] > min_A)
				{
					min_A = num[pos];
				}
				else if (num[pos] > min_B)
				{
					min_B = num[pos];
				}
				else
				{
					break;
				}
			}
			if (pos == 10)
			{
				cout << "YES" << endl;
			}
			else
			{
				cout << "NO" << endl;
			}
		}

	}
	return 0;
}

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

using namespace std;

int main(void)
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i=0; i<n; i++) {
        int a[10];
        bool f = 0;
        for(int j=0; j<10; j++) cin >> a[j];
        for(int j=0; j<8; j++) {
            if(a[j] > a[j+1] && a[j+1] > a[j+2]) f = 1;
        }
        printf("%s\n", f ? "No" : "Yes");

    }

    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 10;
int num[N];
bool dfs(int i,int a,int b){
	if(i == N)	return true;
	if(num[i] > a)	if(dfs(i+1,num[i],b))	return true;
	if(num[i] > b)	if(dfs(i+1,a,num[i]))	return true;
	return false;
}
bool solve(){ return dfs(0,-1,-1); }
int main(){
	int T;	scanf("%d",&T);
	while(T--){
		for (int i = 0; i < N; ++i)	scanf("%d",num+i);
		if(solve())	puts("YES");
		else		puts("NO");
	}
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;

#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

typedef long long ll;

int ball[10];
stack<int> r, l;

bool dfs(int n){
    if(n==10) return true;
    bool ret = false;
    // r?????\??????
    int rt = r.top();
    r.push(ball[n]);
    if(r.top()>rt){
        ret |= dfs(n+1);
        r.pop();
    }
    else r.pop();

    int lt = l.top();
    l.push(ball[n]);
    if(l.top()>lt){
        ret |= dfs(n+1);
        l.pop();
    }
    else l.pop();
    return ret;
}

int main(){
    int t;
    cin >> t;
    while(t--){
        while(!r.empty()) r.pop();
        while(!l.empty()) l.pop();
        r.push(0);
        l.push(0);
        FOR(i,0,10) cin >> ball[i];
        if(dfs(0)){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<queue>
using namespace std;
int main(void){
	int n;
	cin>>n;
	vector<int> a(10);
	for(int i=0;i<n;i++){
		queue<int>b,c,d;
for(int j=0;j<10;j++){
	cin>>a[j];
}
for(int j=0;j<10;j++){
	if(b.empty()){
		b.push(a[j]);
	}else if(b.back()<a[j]){
		b.push(a[j]);
	}else if(c.empty()){
		c.push(a[j]);
	}else if(c.back()<a[j]){
		c.push(a[j]);
	}else{
		d.push(a[j]);
	}

}
if(d.empty()){
	cout<<"YES"<<endl;
}else{
	cout<<"NO"<<endl;
}
	}
	return 0;
}

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

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

    int b = 0;
    int c = 0;
    int flag = true;
    for(int j = 0; j < 10; j++) {
      if(data[j] > b) b = data[j];
      else if(data[j] > c) c = data[j];
      else {
	flag = false;
	break;
      }
    }
    if(flag) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int n;
int ball[12],s[12];
bool jud()
{
	int pre=0;
	for(int i=0;i<10;i++)
	 if(!s[i])
	 	if(ball[i]<pre)
	 		return false;
	 	else 
	 		pre=ball[i];
	pre=0;
	for(int i=0;i<10;i++)
	 if(s[i])
	 	if(ball[i]<pre)
	 		return false;
	 	else 
	 		pre=ball[i]; 	
	return true;
}
bool DFS(int x)
{
	if(x==10) return jud();
	if(DFS(x+1)) return true;
	s[x]=1;
	if(DFS(x+1)) return true;
	s[x]=0;
	return false;
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		memset(s,0,sizeof(s));
		for(int j=0;j<10;j++)
			scanf("%d",&ball[i]);
		if(DFS(0))
			cout<<"YES"<<endl;
		else 
			cout<<"NO"<<endl;
	}
}