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++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>

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<stdio.h>
const int nn = 10;
int a[nn];
using namespace std;
bool dfs()
{
	int left = -1;
	int right = -1;
	
	int T = 0;
	while (T<nn)
	{
		if (right < a[T])
		{
			right = a[T++];
			continue;
		}
		if (left < a[T])
		{
			left = a[T++];
			continue;
		}
		return false;
	}
	return true;
}
int main()
{
	//freopen("in.txt", "r", stdin);
	int N;
	scanf("%d", &N);
	while (N--)
	{
		for (int i = 0; i < nn; i++)
			scanf("%d", &a[i]);
		if (dfs())
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#include<cstdio>
#define MAXN 2555
#define INF 0x3f3f3f3f
#define v first
#define b second
using namespace std;
stack<int>q;
stack<int>p;
int s[15];
bool flag;
void dfs(int x)
{
   if(x==10)
   {
      flag=true;
      return ;
   }
   if(s[x]>q.top())
   {
      q.push(s[x]);
      dfs(x+1);
      q.pop();
   }
   if(s[x]>p.top())
   {
      p.push(s[x]);
      dfs(x+1);
      p.pop();
   }
   return ;
}
int main()
{
   int t;
   scanf("%d",&t);
   q.push(0);
   p.push(0);
   while(t--)
   {
      flag=false;
      for(int i=0;i<10;i++)
         scanf("%d",&s[i]);
      dfs(0);
      if(flag)
         cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
   }
   return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
 
using namespace std;
 
const double eps=1e-10;

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

	for(int i=0;i<n;i++){
		vector<int> a(10);
		for(int j=0;j<10;j++) cin>>a[j];

		bool ok=false;

		for(int j=0;j<(1<<10);j++){
			vector<int> b,_b,c,_c;

			for(int k=0;k<10;k++){
				if(j & (1<<k)) b.push_back(a[k]);
				else c.push_back(a[k]);
			}

			_b=b; _c=c;
			sort(_b.begin(),_b.end());
			sort(_c.begin(),_c.end());

//			reverse(_b.begin(),_b.end());
//			reverse(_c.begin(),_c.end());

			if(b==_b && c==_c){
				cout<<"YES"<<endl;


				ok=true; break;
			}

		}

		if(!ok) cout<<"NO"<<endl;

	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;
#define FOR(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;

int main(void){
	queue <int> rque, lque;
	int N;
	cin >> N;
	for(int k = 0; k < N; k++){
		int have[10];
		for(int j = 0; j < 10; j++){
			cin >> have[j];
		}
		int set = have[9];
		have[9] = -1;
		for(int i = 8; i >= 0; i--){
			if(set > have[i]){
				set = have[i];
				have[i] = -1;
			}
		}
		for(int i = 8; i >= 0; i--){
			if(have[i] != -1){
				set = have[i];
				have[i] = -1;
				break;
			}
		}
		for(int i = 8; i >= 0; i--){
			if(have[i] != -1 && set > have[i]){
				set = have[i];
				have[i] = -1;
			}
		}
		for(int i = 0; i < 10; i++){
			if(have[i] != -1){
				cout << "NO" << endl;
				break;
			}else{
				cout << "YES" << endl;
				break;
			}
		}

	}

	return 0;	
}

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

int main(){
  int N,t,B,C;
  cin >> N;
  for(int i = 0 ; i < N ; i++){
    B = C = 0;
    for(int j = 0; j < 10; j++){
      cin >> t;
      if(B > t && C > t){
	cout << "NO" << endl;
	break;
      }
      else if(B < t && C < t){
	if(B < C) C = t;
	else B = t;
      }
      else if(B < t) B = t;
      else if(C < t) C = t;
      if(j == 9) cout << "YES" << endl;
    }
  }
  return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)


int main(){
	
	int n;
	cin>>n;
	
	rep(loop, n){
		int m=10;
		int in[10];
		bool ans = false;
		rep(i,m)cin>>in[i];
		rep(i,(1<<m)){
			vector<int> a;
			vector<int> b;
			rep(j,m){
				if((i&(1<<j))>0)a.push_back(in[j]);
				else b.push_back(in[j]);
			}
			
			bool ok=true;
			rep(j,a.size()-1)if(a[j]>a[j+1])ok=false;
			rep(j,b.size()-1)if(b[j]>b[j+1])ok=false;
			if(ok)ans=true;
		}
		if(ans)puts("YES");
		else puts("NO");
	}
	
}

C++: #include <iostream>
using namespace std;
int d[10];
int l;
int r;

bool choose(int i, bool b);

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

  for (int i=0; i<n; i++) {
    for (int j=0; j<10; j++) {
      cin >> d[j];
    }
    l = r = 0;
    if (choose(0, true)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }

}

bool choose(int i, bool b) {
  int old;
  int *p;
  if (b) p = &l;
  else p = &r;
  if (d[i] > *p) {
    if (i == 9) return true;
    old = *p;
    *p = d[i];
    if (choose(i+1, true)) return true;
    if (choose(i+1, false)) return true;
    *p = old;
    return false;
  } else {
    return false;
  }
}

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

int num[10];
int left_num[10], right_num[10];
int l, r;

bool dfs(int i) {
	if (i == 10) {
		return true;
	}
	if (i == 0) {
		left_num[l] = num[i];
		return dfs(i + 1);
	}
	if (left_num[l] < num[i]) {
		l++;
		left_num[l] = num[i];
		return dfs(i + 1);
	}
	if (right_num[r] < num[i]) {
		if (r == 0) {
			right_num[r] = num[i];
			return dfs(i + 1);
		} else {
			r++;
			right_num[r] = num[i];
			return dfs(i + 1);
		}
	}
	return false;
}

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

	while (N--) {
		l = 0, r = 0;
		for (i = 0; i < 10; i++) {
			scanf("%d", &num[i]);
			left_num[i] = 0;
			right_num[i] = 0;
		}
		if (dfs(0)) {
			printf("YES\n");
		} else {
			printf("NO\n");
		}
	}

	return 0;
}