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 <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#define NUM_OF_BALLS 10
using namespace std;

int N;
queue<int> A;

//並べられるかどうかの判定とB,Cの値の更新
bool dfs(int B,int C){
	int ball;
	if(A.empty()) return true;
	else{
		ball = A.front();A.pop();
		if(ball <= min(B,C)){
			while(!A.empty())A.pop();
			return false;
		}
		if(ball > B)return dfs(ball,C);
		if(ball > C)return dfs(B,ball);

		printf("e\n");return false;
	}
}

void solve(){
	if(dfs(0,0))printf("YES\n");
	else printf("NO\n");
	return;
}

int main() {
	int tmp;
	scanf("%d",&N);

	for(int n = 0;n < N;n++){
		for(int i = 0;i < NUM_OF_BALLS;i++){
			scanf("%d",&tmp);
			A.push(tmp);
		}

		solve();
	}
   

    return 0;
}

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

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

		int B, C = 0;
		B = data[0];
		bool flag = 0;

		for(int i = 1; i < 10; i++){
			if(B+1 != data[i]){
				if(C == 0){
					C = data[i];
				}else if(C+1 != data[i]){
					cout << "NO" << endl;
					break;
				}else{
					C = data[i];
				}
			}else{
				B = data[i];
			}
			if(i == 9){cout << "YES" << endl;}
		}
	}

}

C++: #include <iostream>
#include <vector>
#include <string>
#include <queue>
#define INF 10000000
using namespace std;
typedef pair<int,int> P;

int n;
int ba[10];

bool all(int,int,int);

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin >> ba[j];
    }
    if(all(0,0,0)){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }
}

bool all(int end,int l,int r){
  if(end==10){
    return true;
  }
  if(ba[end]>l){
    return all(end+1,ba[end],r);
  }
  if(ba[end]>r){
    return all(end+1,l,ba[end]);
  }
  return false;
}

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

int main(){
	stack<int> b,c;
	int n;
	cin>>n;

	for(int i=0;i<n;i++){
		bool flag=true;
		b.push(0);c.push(0);
		for(int j=0;j<10;j++){
			int t;
			cin>>t;
			if(b.top()<t && c.top()<t){
				if(b.top()>c.top()) b.push(t);
				else c.push(t);
			}
			else if(b.top()<t){
				b.push(t);
			}
			else if(c.top()<t){
				c.push(t);
			}
			else {
				flag=false;
			}
		}
		cout<<(flag?"YES":"NO")<<endl;

		while(!b.empty()) b.pop();
		while(!c.empty()) c.pop();
	}
	return 0;
}

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

//????????????
//test?????£???wrong answer????????£??????

int ball[10];
bool can = false;

void search(int r,int l,int n){
  //  cout << n << endl;
  if(n>=10) {
	can = true;
	return;
  }
  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>
#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; }
            if (b.top() < ball) { b.push(ball); continue; }
            if (c.empty())      { c.push(ball); continue; }
            if (c.top() < ball) { c.push(ball); continue; }
            flag=false;
            break;
        }
        (flag) ? puts("YES") : puts("NO");
    }

    return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
bool sf;
int T,st1,st2,x;
    int a[20],b[20],s[20];
void dfs(int i)
{
    if(i==10)
    {
        sf=1;
        return ;
    }
    if(sf)return ;
    if(a[st1]<s[i])
    {
        a[++st1]=s[i];
        dfs(i+1);
        a[st1]=0;
        st1--;
    }
    if(b[st2]<s[i])
    {
        b[++st2]=s[i];
        dfs(i+1);
        b[st2]=0;
        st2--;
    }

}
int main()
{
   // freopen("input.txt","r",stdin);

    cin>>T;
    while(T--)
    {
        for(int i=0;i<10;i++)
            cin>>s[i];
        sf=0;
        dfs(0);
        if(sf)cout<<"YES\n";
        else cout<<"NO\n";

    }





    return 0;
}

C++: #include 	   <stdio.h>
#include <vector>  

using namespace std;			

void solve(vector<int> left, vector<int> right, vector<int> all, int n) {
	bool flag = true;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else
							flag = false;
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}	 	
		if (flag)
			printf("YES\n");
		else
			printf("NO\n");
		flag = true;
	}
}

int main() {		
	vector<int> left;
	vector<int> right;
	vector<int> all;


	int n;
	scanf("%d", &n);
	if (n <= 0) return -1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			scanf("%d", &temp);
			all.push_back(temp);
		}
	}	  

	solve(left, right, all, n);

	return 0;
}

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

int main() {
	int n;
	int a;
	vector<int>d;
	vector<int>va;
	vector<int>vb;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> a;
			d.push_back(a);
		}

		va[0] = d[0];
		if (d[1] > va[0]) { va[1] = d[1]; }
		else { vb[0] = d[1]; }

	for (int j = 2; j < 10; j++) {
			int b = va.size();
			int c = vb.size();

			if (d[j] > va[b]) {
				va.push_back(d[j]);
			}
			else if (d[j] > vb[c]) {
				vb.push_back(d[j]);
			}
			else {
				cout << "NO" << endl; 
				goto FINLOOP;
			}
		}
		cout << "YES" << endl;
			FINLOOP:
		;
		d.erase(d.begin(), d.end());
		va.erase(va.begin(), va.end());
		vb.erase(vb.begin(), vb.end());
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main (){
       int N;
       cin>>N;
       for(int j=0;j<N;j++){
       int a[20]={0},b[20]={0},t;
       int ac=0,bc=0;
       for(int i=0;i<10;i++){
              cin>>t;
              if(a[ac]<t){
                 a[ac+1]=t;
                 ac++;
               }
               else if(b[bc]<t){
                  b[bc+1]=t;
                  bc++;
                }
       
                else break;
           
           }
           if(ac+bc==10){
                 cout<<"YES"<<endl;
            }
           else cout<<"NO"<<endl;
           }
return 0;
}