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>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;

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

#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find(all(v), i) != (v).end())
#define ERASE(v,i) (v).erase(remove(all(v), i), (v).end())
#define INDEX(v,i) (find(all(v), i) - (v).begin())
#define rep(i,n) for(int i = 0; i < (int)n; ++i)
#define debug(x) cerr << #x << " = " << (x) << endl;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

const int INF = 100000000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

int main() {
	int N; cin >> N;
	for(int rou = 0; rou < N; rou++) {
		vector<int> data(10);
		rep(i,10) cin >> data[i];
		bool ans = false;
		for(int i = 0; i < (1<<10); i++) {
			vector<int> b;
			vector<int> c;

			rep(j,10) {
				if(i & (1<<j)) {
					b.pb(data[j]);
				} else {
					c.pb(data[j]);
				}
			}

			bool f = true;
			int bp = 0;
			int cp = 0;
			for(int j = 0, n = b.size(); j < n; j++) {
				if(b[j] < bp) f = false;
				bp = b[j];
			}
			for(int j = 0, n = c.size(); j < n; j++) {
				if(c[j] < cp) f = false;
				cp = c[j];
			}
			if(f) {
				ans = true;
				break;
			}
		}
		cout << (ans ? "YES" : "NO") << endl;
	}
	return 0;
}

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

using namespace std;

int a[10];

bool dfs(int B, int C, int i)
{
    if(i == 10)
        return true;
    else if(B < a[i])
        return dfs(a[i], C, i + 1);
    else if(C < a[i])
        return dfs(B, a[i], i + 1);
    
    return false;
}

int main()
{
    int N;
    cin >> N;
    while(N--)
    {
        for(int i = 0; i < 10; i++)
            cin >> a[i];
        
        cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
    }
}

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

int main() {
    int n;
    cin >> n;
    while(n--) {
        int l = 0, r = 0;
        bool ok = true;
        for(int i=0; i<10; ++i) {
            int x;
            cin >> x;
            if(l < x && r < x) {
                if(l < r) {
                    r = x;
                } else {
                    l = x;
                }
            } else if(l < x) {
                l = x;
            } else if(r < x) {
                r = x;
            } else {
                ok = false;
            }
        }
        if(ok) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}

C++: #include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;

int main(){
	int b,c,m,n,s;
	cin>>m;
	for(int i=0;i<m;i++){
		b=0,c=-1,s=0;
		for(int j=0;j<10;j++){
			cin>>n;
			if(n>b&&n>c){
				if(b>c)b=n;
				else c=n;
			}
			else if(n>b)b=n;
			else if(n>c)c=n;
			else s=1;
		}
		if(s==0)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int ball[10];
bool can = false;

void search(int r,int l,int n){
  //  cout << n << endl;
  if(n>=10) can = true;
  if(r<ball[n]) search(ball[n],l,n+1);
  if(l<ball[n]) search(r,ball[n],n+1);

}
 
int main(){
  int n;
  cin >> n;
  REP(i,n){
	REP(i,10) cin >> ball[i];
	int right=0;
	int left=0;
	can = false;
	search(right,left,0);
	if(can) cout << "Yes" << endl;
	else cout << "No" << endl;
  }

}

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

int a[12];

bool binary(int left,int right,int i);

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

		if(binary(0,0,0))
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

bool binary(int left,int right,int i)
{
	if(i == 10) return true;
	if(right < a[i]) return binary(left,a[i],i+1);
	if(left < a[i]) return binary(a[i],right,i+1);
	return false;
}

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

stack<int> b,c;

int main()
{
    int ball,n;
    bool flag = true;
    scanf("%d", &n);
    for(int i=0;i<n;++i) {
        for(int j=0;j<10;++j) {
            scanf("%d", &ball);
            if (b.empty())           { b.push(ball); continue; }
            else if (b.top() < ball) { b.push(ball); continue; }
            else if (c.empty())      { c.push(ball); continue; }
            else if (c.top() < ball) { c.push(ball); continue; }
            else { flag=false; break;}
        }
        (flag) ? puts("YES") : puts("NO");
    }

    return 0;
}

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

using namespace std;

vector<int> minvec(vector<int> v1, vector<int> v2){
  if(v1.back() < v2.back()){
	return v1;
  }else{
	return v2;
  }
}

vector<int> maxvec(vector<int> v1, vector<int> v2){
  if(v1.back() < v2.back()){
	return v2;
  }else{
	return v1;
  }
}

int main(void){
  int n;
  int i,j;
  vector<int> q;
  //vector<int> out[2];
  int tmp;
  bool isok = true;
  int a=0, b=0;
  cin >> n;
  for(i=0;i<n;i++){
	for(j=0;j<10;j++){
	  cin >> tmp;
	  q.push_back(tmp);
	}

	for(j=0;j<10;j++){
	  if(q[j] > max(a, b)){
		max(a,b) == a ? a = q[j] : b = q[j];
	  }else if(q[j] < min(a,b)){
		cout << "NO" << endl;
		isok = false;
		break;
	  }else{
		min(a,b) == a ? a = q[j] : b = q[j];
	  }
	}

	if(isok) cout << "YES" << endl;
	isok = true;
	q.clear();
	a = 0; b = 0;
  }
  return 0;
}

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

using namespace std;

int t,n=10,a[10002],b[10002],c[10002];
bool flag;

void dfs(int dep,int db,int dc)
{
	if(!flag)return;
	if(dep==n)
	{
		flag=0;
		for(int i=1;i<db;++i)
			if(b[i]<b[i-1])
				flag=1;
		for(int i=1;i<dc;++i)
			if(c[i]<c[i-1])
				flag=1;
		return;
	}
	b[db]=a[dep];
	dfs(dep+1,db+1,dc);
	c[dc]=a[dep];
	dfs(dep+1,db,dc+1);
}
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		flag=1;
		for(int i=0;i<n;++i)
			scanf("%d",&a[i]);
		dfs(0,0,0);
		if(flag)
			printf("NO\n");
		else
			printf("YES\n");
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int N,temp;
	int b,tempb,tempc,ch;
	
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		tempb=0;
		tempc=0;
		ch=0;
		for(int j=0;j<10;j++){
			scanf("%d",&temp);
			if(tempb<temp)
			tempb=temp;
			else if(tempc<temp)
			tempc=temp;
			else{
				ch=1;
				break;
			}
		}
		if(ch==0)
		printf("YES\n");
		else
		printf("NO\n");
	}
}