Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	for i := 0; i < n; i++ {
		a := -1
		b := -1
		ans := true
		// それぞれの筒の一番上にあるたまの数字に着目すればよい
		for j := 0; j < 10; j++ {
			x := nextInt()
			if x > a {
				a = x
			} else if x > b {
				b = x
			} else {
				ans = false
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

int main() {
	int n1,n2,num,temp,flg=1;
	cin>>num;
	while(num--){
		cin>>n1; cin>>n2;
		for(int i=0;i<8;i++){
			cin>>temp;
			if(temp-n1<0&&temp-n2<0) flg=0;
			if(temp-n1>temp-n2) n2=temp;
			else if(temp-n2>temp-n1) n1=temp;
		}if(flg==1) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}return 0;
}

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

using namespace std;
 
 
int data[10];
 
bool searchB (int a){
    vector<int >sea;
 
    for(int i=0;i<10;i++){
        if(a>>i & 1)sea.push_back(data[i]);
    }
    if(sea.size()>1){
    for(int i=0;i<sea.size()-1;i++){
        if(sea[i]>sea[i+1])return false;
    }
    }
    return true;
}
 
int main(){
 
    int n=0;
    cin>>n;
 
    for(int i=0;i<n;i++){
         
 
    for(int j=0;j<10;j++){
        cin>>data[j];
    }
    bool suc=false;
    for(int i=0;i<1024;i++){
        if(searchB(i) && searchB(~i)){
            cout<<"YES"<<endl;
            suc=true;
            break;
        }
    }
    if(!suc)cout<<"NO"<<endl;
    }
    return 0;
}

C++: /*If I get TLE , it is good.If I get AC,it's NICE !*/
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int MAXN=1e7+10;
const ll mod=1e9+7;
using namespace std;
typedef long long ll;
int a[11];

bool judge()
{
    for(int i=2;i<=5;i++)
    {
        if(a[i]<a[i-1]) return false;
    }
    for(int i=7;i<=10;i++)
    {
        if(a[i]<a[i-1]) return false;
    }
    return true;
}

int main(void)
{
    int t;
    cin >> t;
    while(t--)
    {
        int flag=0;
        for(int i=1;i<=10;i++)
            scanf("%d",&a[i]);
        do
        {
            if(judge())
            {
                flag=1;
                break;
            }
        }while(next_permutation(a+1,a+1+10));
        if(flag)    printf("YES\n");
        else    printf("NO\n");
    }
}

C++: #include <iostream>

using namespace std;

bool recursive(int left, int right, int* list, int index)
{
	int next = list[index];

	if(index == 9)
	{
		if(next <= left && next <= right)
			return false;
		return true;
	}

	if(left < next)
		if(recursive(next, right, list, index+1))
			return true;
	if(right < next)
		if(recursive(left, next, list, index+1))
			return true;

	return false;
}

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

	while( n-- > 0 )
	{
		int list[10];
		for(auto& n : list)
			cin >> n;

		if( recursive(0, 0, list, 0) )
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int a[10];
bool ok = false;

// これから入れるボールのindex，左の筒の一番上のボール，右の筒の一番上のボール
void dfs(int idx, int l, int r) {
  if (idx == 10) {
    ok = true;
    return;
  }
  int val = a[idx];
  if (l < val) dfs(idx + 1, val, r);  // 左の筒に入れる場合
  if (r < val) dfs(idx + 1, l, val);  // 右の筒に入れる場合
}

int main() {
  int n;
  cin >> n;
  REP(i, n) {
    REP(i, 10) cin >> a[i];
    ok = false;
    dfs(0, -1, -1);
    cout << (ok ? "YES" : "NO") << endl;
  }
  return 0;
}

C++: #include <cstdio>

using namespace std;

int a[10];

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

	if (l < a[i] && dfs(i + 1, a[i], r)) return true;
	if (r < a[i] && dfs(i + 1, l, a[i])) return true;

	return false;
}

int main()
{
	int n; scanf("%d", &n);

	while (n--) {
        for (int i = 0; i < 10; ++i) scanf("%d", &a[i]);
        printf("%s\n", (dfs(0, 0, 0) ? "YES" : "NO"));
	}
}

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

int main(){
	int a[10],n,i;
	bool can;
	while(cin >> n && n){
		for(i=0;i<n;i++){
                        can = false;
			for(int j = 0;j<10;j++){
				cin >> a[j];
			}
			for(int j = 1;j<=7;j+=2){
				if(a[j] < a[j+2] && a[j-1] < a[j+1]) can = true;
				else {
					can = false;
					break;
				}
			}
			if(can == true) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,r,n) for(int i=r;i<(int)n;i++)
using namespace std;
int in() {int x; cin >> x; return x;}

int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		bool ans = true;
		int r = -1, l = -2;

		for (int i = 0; i < 10; i++)
		{
			int x;
			cin >> x;
			if (r < l)swap(r, l);

			if (l > x)
			{
				ans = false;
			}

			if(r < x)r=x;
			else l=x;


			if (r < l)swap(r, l);
		}


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


	return 0;

}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <stack>

#define REP(i,n) for(int (i) = 0;(i) < (n) ; ++(i))
#define REPA(a,i,n) for(int (i) = (a) ; (i) < (n) ; ++(i))
#if defined(_MSC_VER)||__cplusplus > 199711L
#define AUTO(r,v) auto r = (v)
#else
#define AUTO(r,v) typeof(v) r = (v)
#endif
#define ALL(c) (c).begin() , (c).end()
#define EACH(it,c) for(AUTO(it,(c).begin());it != (c).end();++it)
#define LL long long 
#define INF  99999999;
#define QUICK_CIN ios::sync_with_stdio(false); cin.tie(0);
using namespace std;

int balls[10];

bool is_b[10];

bool check(){
	int b(-1), c(-1);

	REP(i, 10){
		if (is_b[i]){
			if (b > balls[i])
				return false;
			b = balls[i];
		}
		else{
			if (c > balls[i])
				return false;
			c = balls[i];
		}
	}
	return true;
}

bool DFS(int i){
	if (i == 10)
		return check();

	bool ret(false);

	ret |= DFS(i + 1);

	is_b[i] = true;

	ret |= DFS(i + 1);

	is_b[i] = false;

	return ret;
}

int main(){
	QUICK_CIN;

	int n;
	cin >> n;

	REP(i, n){
		REP(j, 10){
			cin >> balls[j];
		}
		cout << (DFS(0) ? "YES" : "NO") << endl;
		fill(is_b, is_b + 10, false);
	}

	return 0;
}

C++: a

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

int main() {
  int N;
  cin >> N;
  for (int a = 0; a < N; ++a) {
    vector<int> A(10);
    for (int i = 0; i < 10; ++i)
      cin >> A[i];

    bool flag = false;
    for (int bit = 0; bit < 1 << 10; ++bit) {
      vector<int> B1(10), B2(10);
      int B1_size = 0, B2_size = 0;
      for (int i = 0; i < 10; ++i)
        if (bit & 1 << i)
          B1[B1_size] = A[i], ++B1_size;
        else
          B2[B2_size] = A[i], ++B2_size;

      vector<int> B1_s = B1, B2_s = B2;
      sort(B1_s.begin(), B1_s.begin() + B1_size),
          sort(B2_s.begin(), B2_s.begin() + B2_size);

      if (B1 == B1_s && B2 == B2_s)
        flag = true;
    }

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