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 <bits/stdc++.h>
using namespace std;


int main() {
  int n;
  int data[10];
   while ( cin >> n ) {
     int flag = 1;
     for ( int i = 0; i < 10; i++ ) cin >> data[i];
     for ( int i = 0; i < 8; i++ ) {
       if ( data[i] > data[i+1] && 
	    data[i+1] > data[i+2] && data[i] > data[i+2] ) {
	 flag = 0;
       }
     }
     if ( flag ) cout << "YES" << endl;
     else cout << "NO" << endl;
  }
  return 0;
}

C++: #include<stdio.h>
	int data[10];

int push(int right,int left,int i)
{
	if(i>=9)
		return 1;

	if(data[i]<right && data[i]<left)
		return 0;
	else
	{
		if(data[i]>right)
			if(push(data[i],left,i+1))
				return 1;
		if(data[i]>left)
			if(push(right,data[i],i+1))
				return 1;
	}
	return 0;
}

int main()
{
	int loop;
	scanf("%d",&loop);
	for(int j=0;j<loop;j++)
	{
		int right=0;int left=0;
		for(int i=0;i<10;i++)
			scanf("%d",&data[i]);

		if(push(right,left,0))
			printf("YES\n");
		else 
			printf("NO\n");
	}
}

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

using namespace std;

typedef vector<int> VI;

void solve() {
  VI balls;
  for (int i = 0; i < 10; i++) {
    int n;
    cin >> n;
    balls.push_back(n);
  }

  int l = 0;
  int r = 0;
  for (int i = 0; i < 10; i++) {
    int n = balls[i];
    if (n > l) {
      l = n;
    } else if (n > r) {
      r = n;
    } else {
      cout << "NO" << endl;
      return;
    }
  }

  cout << "YES" << endl;
}

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    solve();
  }

  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int n;
  cin>>n;
  rep(j,n){
    bool ok=true;
    int a,b=0,c=0;
    rep(i,10){
      cin>>a;
      if(a>b)b=a;
      else if(a>c)c=a;
      else ok=false;
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}

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

int main() {
int a[10],b[11],c[11];
int n;
cin>>n;
for (int jjj=1;jjj<=n;jjj++){
	for(int kk=0;kk<10;kk++) cin>>a[kk];
int bb=0,cc=0;
b[0]=0;
c[0]=0;
for (int k=0;k<10;k++){
	if(a[k]>b[bb] && b[bb]>=c[cc]){
		b[bb+1]=a[k];
		bb=bb+1;
	}
	else{
		c[cc+1]=a[k];
		cc=cc+1;
	}
}
	int l=0,m=0;
	for(int i=1;i<bb;i++){
		if(b[i]-b[i-1]<0){
			l=2;
		}
	}
	for(int j=1;j<cc;j++){
		if(c[j]-c[j-1]<0){
			m=2;
		}
	}
	if(l+m==0){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
	
}

	return 0;
}

C++: #include<iostream>
#include<queue>
using namespace std;
 
int main()
{
  int ball = 10;	//ボールの数
	int n,k;	//n:セットの数 k:メモ
	cin >> n;	
	queue<int> a;	//開口部Ａ

 
	for (int i=0; i < n; i++){			//1セットのループ
		int b = 0 , c = 0;	//筒Ｂ、筒Ｃ
		for (int j=0; j < ball; j++){
			cin >> k;
			a.push( k );
		}
		b = a.front();
		a.pop();	//最初の一個
		
		for (int j=0; j < (ball-1); j++){		//ボールのループ
			if (a.front() > b && a.front() > c){	//どっちも乗せられる
				if (a.front() - b > a.front() - c){
					c = a.front();
				}else{
					b = a.front();	//差の小さい方に乗せる
				}
			}else if(a.front() > b){
				b = a.front();
			
			}else if(a.front() > c){
				c = a.front();
			
			}else {	
				cout << "NO" << endl;
				while(1){
					if(a.empty()){
						break;
					}else{
						a.pop();
					}				//中身を空に
				}
				break;	//終了
			}
 
			a.pop();	//乗せた
			if (a.empty()){		//最後まで乗せた
				cout << "YES" << endl;
				while(1){
					if(a.empty()){
						break;
					}else{
						a.pop();
					}
				}
			}
		}
	}

	return 0;
 
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <iostream>
#include <string.h>
#include <map>
#include <set>
#include <functional>

using namespace std;

const int INF = (1<<30) - 1;


int main(){
	ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while(T--){
        bool ok = true;
        int l, r;
        l = r = -1;
        for(int i=0; i<10; i++){
            int b;
            cin >> b;
            if(l >= r && b > l)
                l = b;
            else if(b > r)
                r = b;
            else
                ok = false;
            //cout << l << " " << r << endl;
        }
        cout << (ok ? "YES" : "NO") << endl;
    }
    
	return 0;
}

C++: /*
P135
POJ 2718 Smallest Difference
*/


#include <iostream>
#include <map>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <functional>
#include <string.h>
using namespace std;

int a[10];
void read()
{
    for(int i=0; i<10; ++i)
        scanf("%d", a+i);
}

void solve()
{
    int x1=0, x2=0;
    bool ans = true;
    for(int i=0; i<10; ++i)
    {
        if(x1 < x2) swap(x1, x2);
        if(x1 < a[i]) x1 = a[i];
        else if(x2 < a[i]) x2 = a[i];
        else {ans = false; break;}
    }
    if(ans) printf("YES\n");
    else printf("NO\n");
}



vector<int> L_bucket;
vector<int> R_bucket;

bool dfs2(int d){
    if(d == 10) return true;
    bool flag = false;
    if(L_bucket.size() == 0 || L_bucket.back() < a[d]){
        L_bucket.push_back(a[d]);
        flag = dfs2(d+1);
        L_bucket.pop_back();
    }
    if(flag) return true;
    if(R_bucket.size() == 0 || R_bucket.back() < a[d]){
        R_bucket.push_back((a[d]));
        flag = dfs2(d+1);
        R_bucket.pop_back();
    }
    if(flag) return true;
    return false;
}

void solve2()
{
    if(dfs2(0)) printf("YES\n");
    else printf("NO\n");
}

int main()
{
    int T;
    scanf("%d", &T);
    while(T--){
        read();
        solve2();
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;

int n, k;
stack<int> sb, sc;
bool f = 1;

int main(){
	cin >> n;
	REP(i, n){
		REP(j, 10){
			cin >> k;
			if (sb.empty()){
				sb.push(k);
			}
			else if (sc.empty()){
				sc.push(k);
			}
			else{
				if (sb.top() < k){
					sb.push(k);
				}
				else if (sc.top() < k){
					sc.push(k);
				}
				else{
					f = 0;
				}
			}
		}
		if (f){
			cout << "YES\n";
		}
		else{
			cout << "NO\n";
		}
		while (!sb.empty()){
			sb.pop();
		}
		while (!sc.empty()){
			sc.pop();
		}
		f = 1;
	}
}