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 <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

class Pipe
{
private:
	queue<int> pipe;
	vector<int> a, b;
public:
	Pipe( queue<int> input )
	{
		pipe = input;
	}

	void pushA()
	{
		a.push_back( pipe.front() );
		pipe.pop();
	}

	void pushB()
	{
		b.push_back( pipe.front() );
		pipe.pop();
	}

	bool empty()
	{
		return pipe.size() == 0;
	}

	bool sorted()
	{
		for ( unsigned int i = 0; i + 1 < a.size(); i++ )
		{
			if ( a[i + 1] < a[i] )
			{
				return false;
			}
		}

		for ( unsigned int i = 0; i + 1 < b.size(); i++ )
		{
			if ( b[i + 1] < b[i] )
			{
				return false;
			}
		}

		return true;
	}
};

bool dfs()
{
	int buffer;
	queue<int> que;
	for ( int i = 0; i < 10; i++ )
	{
		cin >> buffer;
		que.push( buffer );
	}

	Pipe init( que );
	stack<Pipe> st;
	st.push( init );

	while ( !st.empty() )
	{
		Pipe current = st.top();
		st.pop();

		if ( current.empty() )
		{
			if ( current.sorted() )
			{
				return true;
			}
			else
			{
				continue;
			}
		}
		
		Pipe next = current;
		next.pushA();
		st.push( next );

		next = current;
		next.pushB();
		st.push( next );
	}

	return false;
}

int main()
{
	int n;

	cin >> n;

	for ( int i = 0; i < n; i++ )
	{
		cout << ( dfs() ? "YES" : "NO" ) << endl;
	}
	
	return 0;
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a = -1, b = -1;
		int num;
		bool ans = true;
		for (int j = 0; j < 10; j++) {
			if (a > b)swap(a, b);
			cin >> num;
			if (num > b)b = num;
			else if (num > a)a = num;
			else ans = false;
		}
		cout << (ans ? "YES" : "NO") << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
	int ball;
	int n;
	while(cin >> n){
		bool flag = true;
		int B=0, C=0;
		for(int i=0; i<n; i++){
			for(int j=0; j<10; j++){
				cin >> ball;
				if(flag){
					if(B < ball) B=ball;
					else if(C < ball) C=ball;
					else flag=false;
				}
			}
			if(flag) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int n,left,right,x,ans;
	
	cin>>n;
	while(n--)
	{
		left=0,right=0,ans=1;
		
		for(int i=0;i<10;++i)
		{
			cin>>x;
			if(x>left&&x>right)
			{
				if(left>right)
					left=x;
				else
					right=x;		
			}	
			else	if(x>left)
			{
				left=x;
			}
			else 	if(x>right)
			{
				right=x;
			}
			else
			{
				ans=0;
				break;
			}
		}	
		if(ans)
			cout<<"YES\n";
		else
			cout<<"NO\n";	
	}
	
	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 < n;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>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
	int a,b;
	int n;
	int g;
	bool check;
	vector<int> ball(10);

	while(cin >> n){
		a = b = 11;
		check = true;
		rep(i,10){
			cin >> g;
			ball.push_back(g);
		}
		rep(i,10){
			if(a > ball.back()){
				a = ball.back();
				ball.erase( --ball.end() );
			}else if(b > ball.back()){
				b = ball.back();
				ball.erase( --ball.end() );
			}else{
				check = false;
			}
		}
		if(check) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

C++: #include <iostream>
#define MAX(a,b) ((a>b)?(a):(b))
using namespace std;

int main(void){
	int a,b;
	int n;
	int k[10];
	int i;
	cin>>n;
	while(n--){
		a=b=-1;
		for(i=0;i<10;i++) cin>>k[i];
		for(i=0;i<10;i++){
			if(a>k[i]&&b>k[i])break;
			if(k[i]>a&&k[i]>b){
				if(a>b)a=k[i];
				else b=k[i];
			}else if(k[i]>a)a=k[i];
			else if(k[i]>b)b=k[i];
		}
		if(i==10)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include<stdio.h>

int main(){

int n[11]={};
int m[11]={},p[11]={};
int N;
int P=0,M=0;
bool f=true;


scanf("%d",&N);
for(int j=0;j<N;j++)
{
for(int i=0;i<10;i++)
scanf("%d",&n[i]);

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

	if(M==0){m[M]=n[i];M++;}
	else if(m[M-1]<n[i]&&M>0){M++;m[M]=n[i];}

	else if(P==0){p[P]=n[i];P++;}
	else if(p[P-1]<n[i]&&P>0){P++;p[P]=n[i];}
	
	
else f=false;
}


if(f==true)printf("YES\n");
else if(f==false)printf("NO\n");
//for(int i=0;i<10;i++)
//	printf("%d %d\n",m[i],p[i]);

for(int i=0;i<10;i++)
{p[i]=0;m[i]=0;}

bool f=true;
P=0,M=0;


}
return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
  int n, num, right, left;
  bool flag;

  cin >> n;

  for(int i = 0; i < n; i++){
    right = 0;
    left = 0;
    flag = true;
    for(int j = 0; j < 10; j++){
      cin >> num;

      if(right < num){
        right = num;
      }else{
        left = num;
      }

      if(20 - (right + left) < 10 - (j + 1)) flag = false;
    }

    if(flag){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }

  return 0;
}

C++: #include <cstdio>

int n;

bool solve(int *balls, int i, int depth, int left, int right) {
    if (i == depth)
        return true;
    if (left < balls[i] 
            && solve(balls, i+1, depth, balls[i], right))
        return true;
    if (right < balls[i]
            && solve(balls, i+1, depth, left, balls[i]))
        return true;
    return false;
}

int main() {
    scanf(" %d", &n);
    for (int i = 0; i < n; i++) {
        int balls[10];
        for (int j = 0; j < 10; j++) {
            scanf(" %d", &balls[j]);
        }
        puts(solve(balls, 0, 10, 0, 0) ? "YES" : "NO");
    }
}