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++: //<<???????¨????????????????>>?¬¬??????????¢?
//DFS
#include <iostream>
#include <stdio.h>
using namespace std;

int Num[10];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        bool flag=false;
        for(int k=0;k<10;k++)
            scanf("%d",&Num[k]);
        for(int a=0;a<8;a++)
        {
            for(int b=a+1;b<9;b++)
            {
                for(int c=b+1;c<10;c++)
                {
                    if(Num[a]>Num[b]&&Num[b]>Num[c])
                    {
                        flag=true;
                    }
                }
            }
        }
        if(flag) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;

int pow(int a,int n){
	if(n <= 0){
		return 1;
	}
	return a * pow(a,n - 1);
}

int main(){
	int n;
	int a[10];
	int ans1 = 0;
	int ans2 = 0;
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			scanf("%d",&a[j]);
		}
		for(int j = 0; j < 10; j++){
			if(ans1 >= ans2 && ans1 < a[j]){
				ans1 = a[j];
			}else if(ans2 > ans1 && ans2 < a[j]){
				ans2 = a[j];
			}else if(ans1 < a[j]){
				ans1 = a[j];
			}else if(ans2 < a[j]){
				ans2 = a[j];
			}else{
				printf("NO\n");
				break;
			}																													
			if(j == 9){
				printf("YES\n");
			}
		}
	}
	///////////////////////////////////
	//Sleep(200000);///////////////////// 提出するときは必ず外す！
	///////////////////////////////////
	return 0;

}

C++: /*
AOJ 0033 Ball

?¢???????????§??????????????????¢???????§???§?\?????????????A??£?????\???????????????????????????????????????DE?????¶??????B?£???????C?£??????????
??°??????1-10??????????????????????????????A??£?????\???????????????????§???§??¶??????????????\?????\???B?£???????C?£???????????????????????????????????¢????

?????\????¬¬???????????\??°????????°N?????\?????\N??????N???????????°??????????????°?????????10?????´??°?????£??¨???????????\?????????

???????????????????????°????????\?????\?????¨?????????YES?????\????????¨?????????NO
 */
#include <assert.h>
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

#include <algorithm>
#include <complex>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define SZ(a) (int)(a).size()
#define FOR(i,a,b) for (int i=(a); i<=(b); ++i)
#define REP(i,n) for (int i=0; i<(n); ++i)
#define ALL(c) c.begin(), c.end()
#define CLR(c,n) memset(c, n, sizeof(c))
#define TR(it, c) for(typeof(c.begin()) it = c.begin();it != c.end(); ++it)
#define CONTAIN(it, c) (c.find(it) != c.end())
typedef vector<int> VI;
typedef pair<int, int> PII;
template <class T> void checkmin(T &a, T b) { if (b<a) a=b; }
template <class T> void checkmax(T &a, T b) { if (b>a) a=b; }

int x[10];

bool check(int mask) {
  int lb = 0;
  REP(i, 10) if (mask & (1<<i)) {
    if (x[i] < lb) return false;
    lb = x[i];
  }
  return true;
}

bool go(void) {
  REP(i, 512) if (check(i) && check(1023-i)) return true;
  return false;
}

int main(int argc, char *argv[]) {
  int n;
  for (scanf("%d", &n); n; --n) {
    REP(i, 10) scanf("%d", &x[i]);
    puts(go()? "YES" : "NO");
  }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=100,inf=0x3f3f3f3f;
int n,a[maxn],b[maxn],c[maxn],ok=0;
bool dfs(int x,int y,int t){
	if(t==11) {
		ok=1;
	}
	if(a[t]>b[x-1]){
		b[x]=a[t];
		dfs(x+1,y,t+1);
	}
	if(a[t]>c[y-1]){
		c[y]=a[t];
		dfs(x,y+1,t+1);
	}

}
int main()
{
	//freopen("read.txt", "r", stdin);
	cin>>n;
	while(n--){
		for(int i=1;i<=10;i++)cin>>a[i];
		ok=0;
		dfs(1,1,1);
		if(ok==1)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	//fclose(stdin);
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include<stack>

using namespace std;
int t[11];
stack<int> a;
stack<int> b;
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
       while(!a.empty())
        a.pop();
       while(!b.empty())
        b.pop();
        int flag=0;
        memset(t,0,sizeof(0));
        for(int i=0;i<10;i++)
        {
            scanf("%d",&t[i]);
        }
       // sort(t,t+10,cmp);
        a.push(t[0]);
        b.push(0);
        for(int i=1;i<10;i++)
        {
            if(t[i]>a.top()&&t[i]<=b.top())
                a.push(t[i]);
            else if(t[i]<=a.top()&&t[i]>b.top())
                b.push(t[i]);
             else if(t[i]>a.top()&&t[i]>b.top())
             {
                 if(a.top()>b.top())
                  a.push(t[i]);
                 else
                    b.push(t[i]);
                    
             }
               
                else if(t[i]<=a.top()&&t[i]<=b.top())
              {
                  flag=1;
                  break;
              }
        }
        if(flag)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;



    }
}

C++: #include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n; cin >> n;
  for (int _ = 0; _ < n; ++_) {
    V<> a(10); for (int i = 0; i < 10; ++i) cin >> a[i];
    bool ok = false;
    for (int bit = 0; bit < 1 << 10; ++bit) {
      V<> b, c;
      for (int i = 0; i < 10; ++i) if (bit & 1 << i) {
        b.push_back(a[i]);
      } else {
        c.push_back(a[i]);
      }
      if (is_sorted(begin(b), end(b)) and is_sorted(begin(c), end(c))) {
        ok = true;
        break;
      }
    }
    cout << (ok ? "YES" : "NO") << '\n';
  }
}