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<cstdio>
#include<cstring>
using namespace std;

int a[10];
int b[10],c[10],lb,lc;
int vis[10];
int n,m,t;

bool dfs(int s,int e)
{
    int cnt = 0;
    if(s==e) return true;

    if(!lb || b[lb-1] < a[s])
    {
        cnt++;
        b[lb++] = a[s];
        if(dfs(s+1,e)) return true;
        lb--;
        b[lb] = 0;
    }
    if(!lc || c[lc-1] < a[s])
    {
        cnt++;
        c[lc++] = a[s];
        if(dfs(s+1,e)) return true;
        lc--;
        c[lc] = 0;
    }
    return false;
}

int main()
{
    scanf("%d",&t);
    while(t--)
    {
        for(int i=0;i<10;i++)
            scanf("%d",&a[i]);
        lb = 0, lc = 0;
        if(dfs(0,10)) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

C++: #include<iostream>
#include<queue>
#include<stack>
using namespace std;
int main()
{
	int n;
	cin>>n;
	stack<int>q;
	stack<int>p;
	while(n--){
		
		q.push(0);
		p.push(0);
		int f=1;
		for(int i=1;i<=10;i++)
		{
			int t;
			cin>>t;
			if(p.top()<t)
			p.push(t);
			else if(q.top()<t)
			q.push(t);
			else{
				f=0;
			}
		}
		if(f==0)
		cout<<"NO"<<endl;
		else
		cout<<"YES"<<endl;
		while(!q.empty())
		q.pop();
		while(!p.empty())
		p.pop();
	
	}
 }

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

int main() {
	int n;
	cin >> n;
	for ( int i = 0; i < n; i++ ){
		deque<int>b,c;
		bool endflag = false;
		int dummy;
		cin >> dummy;
		b.push_back( dummy );
		cin >> dummy;
		c.push_back( dummy );
		for ( int j = 0; j < 8; j++ ){
			cin >> dummy;
			if ( !endflag ) {
				if ( dummy > b[b.size()-1] )	b.push_back( dummy );
				else if ( dummy > c[c.size()-1] )	c.push_back( dummy );
				else {
					cout << "NO" << endl;
					endflag = true;
				}
			}
		}
		if( !endflag )	cout << "YES" << endl;
	}
	
	return 0;
}

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

int l=0, r=0;
bool flag=true;

void solve(int N) {
	int a = 0;
	while (N > 0) {
		for (int i = 0; i < 10; i++) {
			cin >> a;
			if (a > l)
				l = a;
			else if (a > r)
				r = a;
			else 
				flag = false;
			if (l < r)
				swap(l, r);
		}
		if (flag == true)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
		N--;
	}
}
int main() {
	int n = 0;
	cin >> n;
	solve(n);
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  int a[10];
  int f,s;
  bool flg=true;
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>a[j];
    }
    f=0;s=0;flg=true;
    for(int i=0;i<10;i++){
      if(a[i]<f){
	if(a[i]<s)flg=false;
	else s=a[i];
      }
      else f=a[i];
    }
    if(flg)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
}

C++: #include <iostream>

using namespace std;

int main(void){

  int a;
  int b[10] = {0};
  int c[10] = {0};
  int out[10] = {0};

  int n;
  cin >> n;
  while(n--){

    for( int l = 10 ; l > 0 ; l-- ){
    cin >> a;
    int i = 0;
    int j = 0;
    int k = 0;
    if( b[i] < a ){
    b[i++] = a;
    }
    else if( c[j] < a ){
	c[j++] = a;
      }
    else out[k++] = a;
    }
    if( out[0] == 0 )cout << "YES" << endl;
    else cout << "NO" << endl;
  }
 return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int a[10];
int l, r;

bool dfs(int i)
{
    if (i == 10) return true;

    bool res = false;

    int tmp;

    if (l <= a[i]) {
        tmp = l;
        l = a[i];
        res = res || dfs(i + 1);
        l = tmp;
    }

    if (r <= a[i]) {
        tmp = r;
        r = a[i];
        res = res || dfs(i + 1);
        r = tmp;
    }

    return res;
}

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

    while (n--) {
        l = r = 0;
        for (int i = 0; i < 10; ++i) cin >> a[i];
        cout << (dfs(0) ? "YES" : "NO") << endl;
    }
}

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

using namespace std;

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

	bool flag = true;

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}

	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)
			cout << "YES" << endl;
		else
			cout << "NO"<<endl;
		flag = true;
	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define TEMP_T template<typename T>
TEMP_T void sort(T& v){ sort(v.begin(), v.end()); }
TEMP_T void revs(T& v){ reverse(v.begin(), v.end()); }
TEMP_T void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end())); }
TEMP_T void show(T& v, char delim=' ', char end='\n'){ for(int i=0; i<v.size()-1; i++) cout << v[i] << delim; cout << v[v.size()-1] << end; }
TEMP_T T    cums(T& v){ T r; r.push_back(v[0]); for(int i=1; i<v.size(); i++) r.push_back(r[i-1] + v[i]); return r; }
TEMP_T void maxe(T& v, T m){ v = max(v, m); }
TEMP_T void mine(T& v, T m){ v = min(v, m); }

static inline int in(){ int x; scanf("%d", &x); return x; }

struct Solver {
  Solver(vector<int> bs) : bs(bs) {}
  bool solve(int it=0, int a=0, int b=0){
    if (it == bs.size()) return true;
    if (a < bs[it] && solve(it + 1, bs[it], b)) return true;
    if (b < bs[it] && solve(it + 1, a, bs[it])) return true;
    return false;
  }
  vector<int> bs;
};

int main()
{
  int n = in();
  for (int i = 0; i < n; i++){
    vector<int> bs;
    for (int j = 0; j < 10; j++){
      bs.push_back(in());
    }
    Solver solver(bs);
    if (solver.solve()) puts("YES");
    else puts("NO");
  }
  return (0);
}

C++: #include <iostream>
using namespace std;
int main()
{
cout<<"YES"<<endl;
cout<<"NO"<<endl;
}

C++: #include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
int a[10];
bool ans;
void dfs(int i,int r,int l){
	if(i==10)return;
	if(a[i]<r&&a[i]<l){
		ans=0;
		return;
	}
	if(r<a[i])dfs(i+1,a[i],l);
	if(l<a[i])dfs(i+1,r,a[i]);
}
int main(){
	int t;
	cin>>t;
	while(t--){
		ans=1;
		for(int i=0;i<10;i++)cin>>a[i];
		dfs(0,0,0);
		if(ans)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

C++: #include<cstdio>

int main(void){
	int n,i,j;
	int a[1024][10];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<10;j++){
			scanf("%d",&a[i][j]);
		}
	}
	
	for(i=0;i<n;i++){
		int b[10],c[10];
		b[0]=a[i][0];
		bool x=true;
		int k=0,l=0;
		for(j=1;j<10;j++){
			if(a[i][j]>b[k]){
				k++;
				b[k]=a[i][j];
			}else {
				c[l]=a[i][j];
				l++;
			}
		}

		for(j=0;j<l-2;j++){
			if (c[j]>c[j+1]){
				x=false;
			}
			//if(c[j]>c[j+1]) break;
		}
		if(x==true){
			printf("YES\n");
		} else{
			printf("NO\n");
		}	
	}
	return 0;
}