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>
#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 cnt = 0;
		for (int i = 1; i < 10; ++i){
			if (ball[i] < ball[0])cnt++;
		}
		if (cnt < 4)std::cout << "YES" << std::endl;
		else std::cout << "NO" << std::endl;
		n--;
	}
	return 0;
}

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

int main(){
	int ball[10];
	int cell[2][10]={0};
	int n,i,k,cell_1=1,cell_2=1,flag=0;
	
	scanf("%d",&n);
	
	for(k=0;k<n;k++){
		for(i=0;i<10;i++)scanf("%d",&ball[i]);
		
		cell[0][0]=ball[0];
		cell[1][0]=ball[1];

		for(i=2;i<10;i++){
			if(cell[0][cell_1-1] < ball[i]){
				cell[0][cell_1]=ball[i];
				cell_1++;
			}
			else if(cell[1][cell_2-1] < ball[i]){
				cell[1][cell_2]=ball[i];
				cell_2++;
			}
			else flag=1;
		}
		
		if(flag==0)printf("YES\n");
		else printf("NO\n");
	
	}
	return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#define rep(i, n) for (int i=0; i<n; ++i)
#define FOR(i, a, b) for (int i=a; i<b; ++i)
#define pb(x) push_back(x)
#define ll long long
#define ul unsigned long long
#define dbg(x) cout  << #x << " : " << (x) << endl
#define out(x) cout << (x)
#define outl(x) cout << (x) << endl
#define int(n); int n; cin >> n;
#define long(n); long long n; cin >> n;
#define dbl(f); double f; cin >> f;
#define s(s); string s; cin >> s;
#define into(a, n) for (int i = 0; i < n; ++i) cin >> a[i]
using namespace std;

const int inf =1500000000;

int a[11],b[11],c[11];

bool dfs(int l,char x) {
  if (l>=11) return true;
  if (x=='b') {
    b[l]=a[l];
    rep(i, l) if(b[l]<b[i]) {b[l]=-1; return false;}
  }
  if (x=='c') {
    c[l]=a[l];
    rep(i, l) if(c[l]<c[i]) {c[l]=-1; return false;}
  }
  bool p= dfs(l+1,'b')||dfs(l+1,'c');
  b[l]=-1;c[l]=-1;
  return p;
}

int main () {
  int(n);
  bool flg;
  rep(i, n) {
    flg=false;
    b[0]=-1;c[0]=-1;
    FOR(i, 1, 11) {
      cin>>a[i];
      b[i]=-1; c[i]=-1;
    }
    flg=dfs(1,'b')||dfs(1,'c');
    outl(flg?"YES":"NO");
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n,l[10],a,b;
  cin>>n;
  while(n){
    a=b=0;
    cin>>l[0]>>l[1]>>l[2]>>l[3]>>l[4]>>l[5]>>l[6]>>l[7]>>l[8]>>l[9];
    for(int i=0;i<10;i++){
      if(!(i%2)){
	if(l[i]>a)a=l[i];
	else
	  break;
      }
      else{
	if(l[i]>b)b=l[i];
        else
	  break;
      }
    }
    (a==l[8]&&b==l[9])?cout<<"YES":cout<<"NO";
    cout<<endl;
    n--;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
using namespace std;
const int maxn = 10001;
int a[maxn];
int vis[maxn];
void dfs(int pre , int cur)
{
    if(cur < 10 && a[pre] < a[cur])
    {
        vis[cur] = 1;
        dfs(cur , cur + 1);
    }
    else if(cur < 10 && a[pre] > a[cur]){
        dfs(pre , cur + 1);
    }
}

int main()
{
    #ifdef DoubleQ
    freopen("in.txt" , "r" , stdin);
    #endif // DoubleQ
    int n;
    cin >> n;
    while(n --){
        for(int i = 0 ; i < 10 ; i ++){
            cin >> a[i];
        }
        bool flag = false;
        for(int i = 0 ; i < 10 ; i ++){
            memset(vis , 0 , sizeof(vis));
            vis[i] = 1;
            dfs(i , i + 1);
            int pre = 0;
            for(int j = 0 ; j < 10 ; j ++){
                if(vis[j] == 0){
                    if(pre > a[j]){
                        flag = true;
                        break;
                    }
                    else pre = a[j];
                }
            }
            if(!flag){
                cout << "YES" << endl;
                break;
            }
        }
        if(flag) cout << "NO" << endl;

    }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int d=0;d<n;d++){
	int a[10]={},b[10]={},c[10]={};
	for(int i=0;i<10;i++){
		cin>>a[i];
	}
	int j=0,k=0;
	for(int i=0;i<10;i++){
		if(b[j]<a[i]){
			b[j+1]=a[i];
			j++;
		}
		else if(c[k]<a[i]){
			c[k+1]=a[i];
			k++;
		}
		else{
			cout<<"NO"<<endl;
			goto age;;
		}
	}
	cout<<"YES"<<endl;
	age:;
}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int d[10];
bool solve(){
  int a=0;
  int b=0;
  for(int i=0;i<10;i++){
    if(a<d[i]){a=d[i];continue;}
    else if(b<d[i]){b=d[i];continue;}
    else return false;
  }
  return true;
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>d[j];
    }
    cout<<(solve()?"YES":"No")<<endl;
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>

typedef long long ll;
using namespace std;

typedef pair<int,int> P;

void seek_lcs(int a,int b,int dp[10+1][10+1],int* num,int* base,vector<int>& idx){
	if(a==0 || b==0){
		return;
	}

	if(num[a] == base[b]){
		seek_lcs(a-1,b-1,dp,num,base,idx);
		idx.push_back(num[a]);
	}
	else{
		if(dp[a-1][b] >= dp[a][b-1]){
			seek_lcs(a-1,b,dp,num,base,idx);
		}
		else{
			seek_lcs(a,b-1,dp,num,base,idx);
		}
	}

}

int main()
{
	int T;
	cin >> T;
	for(int t=0;t<T;t++){

		int num[10+1];
		int base[10+1];
		int dp[10+1][10+1];

		memset(dp,0,sizeof(dp));

		for(int i=1;i<=10;i++){
			scanf("%d",num+i);
			base[i]=i;
		}
		num[0]=0;
		base[0]=0;

		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				if(num[i+1]==base[j+1]){
					dp[i+1][j+1] = max(dp[i+1][j],max(dp[i][j+1],dp[i][j]+1));
				}
				else{
					dp[i+1][j+1] = max(dp[i+1][j],max(dp[i][j+1],dp[i][j]));
				}
			}
		}

		vector<int> idx;
		stack<int> stk;
		seek_lcs(10,10,dp,num,base,idx);

		for(int i=1;i<=10;i++){
			if(find(idx.begin(),idx.end(),num[i]) != idx.end()){
				continue;
			}

			if(stk.empty() || stk.top() < num[i]) stk.push(num[i]);
		}

		printf("%s\n",idx.size() + stk.size() == 10 ? "YES" : "NO");
	}
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){

  int blank,n,num[10],i;
  vector <int> a,b;

  cin>>n;
  for(int j=0;j<n;j++){
  for(i=0;i<10;i++) cin>>num[i];
  blank=0;
  a.clear();
  b.clear();
  a.push_back(0);
  b.push_back(0);
  for(i=0;i<10;i++){

    if(num[i]>a.back() && num[i]>b.back()){
      if(a.back()<=b.back()){
	b.push_back(num[i]);
	continue;
      }
      else {
	a.push_back(num[i]);
	continue;
      }
    }

    if(num[i]>a.back()){
      	a.push_back(num[i]);
	continue;
    }
      if(num[i]>b.back()){
      	b.push_back(num[i]);
	continue;
    }
      
      blank=1;
      break;

  }

  if(blank==0) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  }
  
  return 0;

}