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 <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
using namespace std;


#define li			long long int
#define rep(i,to)	for(int i=0;i<((int)(to));i++)
#define repp(i,start,to)	for(int i=(int)(start);i<((int)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl

li a[10];

int main(){
	li t;
	cin>>t;
	rep(case_num, t){
		rep(i,10)cin>>a[i];
		li l=0, r=0;
		bool res=true;
		rep(i,10){
			if(a[i]<min(l,r)){
				res=false;
				break;
			}
			else if(a[i]>max(l,r)){
				if(l>=r)l=a[i];
				else r=a[i];
			}
			else if(a[i]>l)l=a[i];
			else if(a[i]>r)r=a[i];
			else{
				res=false;
				break;
			}
		}
		cout<<(res ? "YES" : "NO")<<endl;
	}
	
	return 0;
}

C++: #define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
	int n;
	for (cin >> n; n--;)
	{
		vector<int> b;
		vector<int> c;

		for (int i = 0; i < 10; i++)
		{
			int x;
			cin >> x;

			if (i == 0)
			{
				b.push_back(x);
			}
			else if (i == 1)
			{
				c.push_back(x);
			}
			else
			{
				if (x > b.back())
				{
					b.push_back(x);
				}
				else if (x > c.back())
				{
					c.push_back(x);
				}
			}
		}

		cout << (b.size() + c.size() == 10 ? "YES" : "NO") << endl;
	}
}

C++: #include <map>
#include <vector>
#include <queue>
#include <cmath>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <memory.h>
#include <algorithm>

using namespace std;

int main()
{
	int T;

	cin>>T;
	while(T--)
	{
		int a,b;
		a=b=0;
		int temp;
		int i;

		for(i=0;i<10;i++)
		{
			cin>>temp;
			if(temp>a)
			{
				a=temp;
				continue;
			}
			if(temp>b)
			{
				b=temp;
				continue;
			}
			break;
		}

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

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int n;

bool dfs(queue<int> S,int l,int r){
  if(S.empty())
    return true;
  int x = S.front();
  S.pop();

  if(x < l&& x <r)
    return false;
  else if(x < l)
    return dfs(S,l,x);
  else if(x <r)
    return dfs(S,x,r);
  else 
    return dfs(S,x,r)||dfs(S,l,x);
}

int main()
{
  cin>>n;
  for(int i = 0;i < 2;i++){
    queue<int> S1;
    for(int j = 0;j < 10;j++){
      int ball;
      cin >>ball;
      S1.push(ball);
    }
    if(dfs(S1,0,0)){
      cout <<"YES"<<endl;
      }else
      cout <<"NO"<<endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int N,m;
  cin>>N;
  while(N--){
    int B,C=0,i=0;
    bool f=true;
    cin>>B;
    while(++i<10){
      cin>>m;
      if(B<m){
	if(B<C&&C<m)C=m;
	else B=m;
      }else if(C<m){
	C=m;
      }else{
	f=false;
      }
    }
    cout<<(f?"YES":"NO")<<endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int num[10];
bool dfs(int start, int topl, int topr)
{
	if (start == 9)
	{
		if (num[start] > topl || num[start] > topr)
			return true;
		else
			return false;
	}
	else
	{
		bool b1 = false, b2 = false;
		if (num[start] > topl)
			b1=dfs(start + 1, num[start], topr);
		if (num[start] > topr)
			b2 = dfs(start + 1, topl, num[start]);
		return b1 || b2;
	}
}
	
int main()
{
	int k;
	cin >> k;
	while (k--)
	{
		for (int i = 0; i <= 9; ++i)
			cin >> num[i];
		if (dfs(0,0,0))
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;

int n;
int usea[11];

int dfs(int num, int r_num, int l_num) {
	int res = 0;

	if (usea[num] > r_num) {
		if (num == 9)
			return 1;
		res = dfs(num + 1, usea[num], l_num);
		return res;
	}
	else if (usea[num] >l_num) {
		if (num == 9)
			return 1;
		res = dfs(num + 1, r_num, usea[num]);
		return res;
	}
	else {
		return 0;
	}
}


int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> usea[j];
		}
		if (dfs(0, -1, -1)) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <climits>
using namespace std;
int b = INT_MIN, c = INT_MIN;
bool push(int ball) {
    if(ball > b) b = ball;
    else if (ball > c) c = ball;
    else return(false);
    return(true);
}

int main(void) {
    int num; cin >> num;
    int ans = 0;
    for(int r = 0; r < num; r++) {
        for(int c = 0; c < 10; c++) {
            int input; cin >> input;
            bool result = push(input);
            if(!result) ans += -100;
            else ans++;
        }
        if(ans >= 0) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

C++: //0033
//include-------------------------------------
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<stack>

using namespace std;

//typedef--------------------------------------
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define MP make_pair

//repetition-----------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

//constant-------------------------------------
const double PI = acos(-1.0);

//cout,cin-------------------------------------
#define COUT(x) cout<<(x)<<endl;
#define CIN(x) cin>>(x);


int main(){
	int n;
	int x[10];
	bool ans;

	CIN(n);

	REP(i, n){
		
		REP(j, 10) CIN(x[j]);
		stack<int> B, C;
		B.push(0);
		C.push(0);

		REP(j, 10){
			if ((B.top() > x[j]) && (C.top() > x[j])){
				ans = false;
				break;
			}
			else { 
				if ((B.top() >= C.top()) && (B.top() < x[j])) B.push(x[j]);
				else C.push(x[j]);
			}

		}
		COUT(ans==false?"NO":"YES");
		
	}