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<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
  int ball[11],n,a[11],b[11];
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin >> ball[j];
    }
    int a_num,b_num;
    a_num = b_num = 0;
    for(int j=0;j<10;j++){
      if(j == 0){
	a[a_num] = ball[j];
	a_num++;
      }else if(ball[j]>a[a_num-1] || ball[j]>b[b_num-1]){
	// bの方が差が小さいとき
	if(ball[j]-a[a_num-1] > ball[j]-b[b_num-1]){
	  b[b_num] = ball[j];
	  b_num++;
	}else {
	  a[a_num] = ball[j];
	  a_num++;
	}
      }
    }
    if(a_num+b_num==10)cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

C++: #include <cstdio>

int main(){
  int n;
  scanf("%d",&n);
  while(n--){
    int a=0,b=0,m;
    for(int i=0; i<10; i++){
      scanf("%d",&m);
      if(a<m)
	a=m;
      else if(b<m)
	b=m;
      else{
	printf("NO\n");
	while(getchar()!='\n');
	goto hoge;
      }

      if(a<b){
	int c; 
	c=a;a=b;b=c;
      }
    }
    printf("YES\n");
  hoge: ;
  }
}

C++: #include <stdio.h>

int main(void)
{
	int tubeM[10];
	int tube1[10], tube2[10];
	int i, j, k;
	int n;
	int ans;
	
	for (i = 0; i < 10; i++){
		tube2[i] = 0;
	}
	
	scanf("%d", &n);
	
	while(n){
		for (i = 0; i < 10; i++){
			scanf("%d", &tubeM[i]);
		}
		
		tube1[0] = tubeM[0];
		for (i = 1, j = 0, k = 0; i < 10; i++){
			if (tubeM[i] > tube1[j]){
				tube1[j + 1] = tubeM[i];
				j++;
			}
			else {
				tube2[k] = tubeM[i];
				k++;
			}
		}
		
		ans = 0;
		for (i = 1; tube2[i] != 0; i++){
			if (tube2[i - 1] > tube2[i]){
				ans = 1;
				break;
			}
		}
		
		if (ans == 0){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
		
		n--;
	}
	
	return (0);
}

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

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("%lld", &x); return (x); }

int main()
{
	int n;
	int containerTop[2];
	bool flag;
	n = in();
	loop(i, 0, n)
	{
		containerTop[0] = containerTop[1] = -1;
		flag = true;
		
		loop(j, 0, 10)
		{
			int ball = in();
			if( containerTop[0] < ball )
			{
				containerTop[0] = ball;
			}
			else if( containerTop[1] < ball )
			{
				containerTop[1] = ball;
			}
			else
			{
				flag = false;
			}
		}
		printf("%s\n", flag ? "YES" : "NO");
	}
	return (0);
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
  int n; cin >> n;
  while (n--) {
    vector<int> a(10); for (int i = 0; i < 10; ++i) cin >> a[i];
    stack<int, deque<int>> s0({a[0]}), s1({0});
    for (int i = 1; i < 10; ++i) {
      int m = 10, mpos = -1;
      if (s0.top() < a[i]) {
        if (a[i] - s0.top() < m) {
          m = a[i] - s0.top();
          mpos = 0;
        }
      }
      if (s1.top() < a[i]) {
        if (a[i] - s1.top() < m) {
          m = a[i] - s1.top();
          mpos = 1;
        }
      }
      if (mpos == -1) {
        cout << "NO" << endl;
        break;
      }
      ( (mpos) ? s1 : s0 ).push(a[i]);
      if (i == 9) cout << "YES" << endl;
    }
  }
  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;
queue<int>q;
queue<int>p;
int s[15];
bool flag;
void dfs(int x)
{
   if(x==10)
   {
      flag=true;
      return ;
   }
   if(s[x]>q.front())
   {
      q.push(s[x]);
      dfs(x+1);
      q.pop();
   }
   if(s[x]>p.front())
   {
      p.push(s[x]);
      dfs(x+1);
      p.pop();
   }
   return ;
}
int main()
{
   int t;
   scanf("%d",&t);
   while(t--)
   {
      flag=false;
      for(int i=0;i<10;i++)
         scanf("%d",&s[i]);
      q.push(0);
      p.push(0);
      dfs(0);
      if(flag)
         cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
   }
   return 0;
}

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

int main()
{
    int n;
    int a[10];

    cin >> n;

    while( n-- )
    {
        stack<int> b, c;
        b.push(0);
        c.push(0);

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

        for( int i = 0; i < 10; i++ )
        {
            if( b.top() == 0 || c.top() == 0 )
            {
                if( a[i] > b.top() )
                    b.push(a[i]);
                else
                    c.push(a[i]);
            }
            else if( b.top() > c.top() )
            {
                if( a[i] > b.top() )
                    b.push(a[i]);
                else
                {
                    if( a[i] > c.top() )
                        c.push(a[i]);
                    else
                    {
                        cout << "NO" << endl;
                        break;
                    }
                }
            }
            else
            {
                if( a[i] > c.top() )
                    c.push(a[i]);
                else
                {
                    if( a[i] > b.top() )
                        b.push(a[i]);
                    else
                    {
                        cout << "NO" << endl;
                        break;
                    }
                }
            }
        }
        if( b.size() + c.size() == 12 )     //初期値0が2つのスタックに入っている。
            cout << "YES" << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

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

int n;
int a[11];

bool rec(int idx, int l, int r) {
   if (idx == 10) return true;

   bool x = false, y = false;
   int val = a[idx];
   if (l < val) x = rec(idx+1, val, r);
   if (r < val) y = rec(idx+1, l, val);

   return x || y;
}

int main() {
   cin >> n;
   while (n--) {
      rep (i, 10) cin >> a[i];
      puts(rec(0, -1, -1)?"YES":"NO");
   }

   return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

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

	rep(i,0,n){
		int x=0,y=0;
		bool f = 1;
		rep(j,0,10){
			int b;
			cin >> b;
			if( b - x > 0 && b - x <= b - y )
				x = b;
			else if( b - y > 0 )
				y = b;
			else{
				NO;
				f = 0;
				break;
			}
			//cout << x << " " << y << endl;
		}

		if(f)
			YES;
	}
	
	ret 0;
}