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 <cstdio>
using namespace std;

int n;
int has_put;
int a[10];

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

        has_put = 0;
        for (int bit=0; bit<1024; bit++) {
            int pre1 = -1;
            int pre2 = -1;
            int possible = 1;

            for (int i=0; i<10; i++) {
                if ((bit>>i)&1) {
                    if (a[i] < pre1) {
                        possible = 0;
                        break;
                    }
                    pre1 = a[i];
                } else {
                    if (a[i] < pre2) {
                        possible = 0;
                        break;
                    }
                    pre2 = a[i];
                }
            }

            if (possible) {
                puts("YES");
                has_put = 1;
                break;
            }
        }

        if (!has_put) {
            puts("NO");
        }
    }
}

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

int main() {
  int n;
  cin >> n;
  int t;
  int i, j;
  for (i = 0; i < n; i++) {
    queue<int> q;
    for (j = 0; j < 10; j++) {
      cin >> t;
      q.push(t);
    }
    stack<int> a, b;
    a.push(q.front());
    q.pop();
    b.push(0);
    while (q.size()) {
      if (a.top() < q.front()) {
        a.push(q.front());
      } else if (b.top() < q.front()) {
        b.push(q.front());
      } else {
        cout << "NO" << endl;
        break;
      }
      q.pop();
      if (q.size() == 0) {
        cout << "YES" << endl;
      }
    }
  }
  return 0;
}

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

int n,b[10];

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

	if(l<b[c])
	{
		if(dfs(b[c],r,c+1)) return true;
	}
	if(r<b[c])
	{
		if(dfs(l,b[c],c+1)) return true;
	}
	return false;
}


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

C++: #include<cstdio>

int main(void){
	int n,i,j;
	int a[1024][10];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<10;j++){
			scanf("%d",&a[i][j]);
		}
	}
	
	for(i=0;i<n;i++){
		int b[10],c[10];
		b[0]=a[i][0];
		bool x=true;
		int k=0,l=0;
		for(j=1;j<10;j++){
			if(a[i][j]>b[k]){
				k++;
				b[k]=a[i][j];
			}else {
				c[l]=a[i][j];
				l++;
			}
		}

		for(j=0;j<l-2;j++){
			if (c[j]>c[j+1]){
				x=false;
			}
			//if(c[j]>c[j+1]) break;
		}
		if(x==true){
			printf("Yes\n");
		} else{
			printf("No\n");
		}	
	}
	return 0;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

bool
f(vector<int>&ln, int idx, int x, int y) {
  if (idx == 10) return true;
  int z = ln[idx];
  return (x < z && f(ln, idx + 1, z, y)) || (y < z && f(ln, idx + 1, y, z));
}

int main() {

  int n; cin >> n;
  for (;n--;) {
    vector<int> ln(10);
    rep (i, 10) cin >> ln[i];
    bool bl = f(ln, 0, 0, 0);
    cout << (bl ? "YES" : "NO" ) <<endl;
  }

  return 0;
}

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

using namespace std;

int ball_db[10];

void solve()
{
    vector<int> left;
    vector<int> right;

    left.push_back(0);
    right.push_back(0);

    for (int i = 0; i < 10; ++i) {
        if (ball_db[i] > left.back()) {
            left.push_back(ball_db[i]);
        } else if (ball_db[i] > right.back()) {
            right.push_back(ball_db[i]);
        } else {
            cout << "NO" << endl;
            return;
        }
    }

    if (left.size() + right.size() == 10 + 2) {
        cout << "YES" << endl;
    }
}

int main()
{
    int data_num;

    cin >> data_num;

    for (int i = 0; i < data_num; ++i) {
        for (int j = 0; j < 10; ++j) {
            cin >> ball_db[j];
        }
        solve();
    }


    return 0;
}

C++: #include<iostream>
using namespace std;
int r[10],l[10];
int data[10];

bool solve(int n,int rt,int lt)
{
	if(n==10)
	{
		for(int i = 1; i <= rt ; ++i)
		{
			if(r[i-1]>r[i]) return false;
		}
		for(int i = 1; i <= lt ; ++i)
		{
			if(l[i-1]>l[i]) return false;
		}
		return true;
	}

	r[rt]=data[n];
	if(solve(n+1,rt+1,lt)) return true;
	l[lt]=data[n];
	if(solve(n+1,rt,lt+1)) return true;

	return false;
}

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

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

const int N = 10;
int a[N];
      
int main() {
  int Tc;
  cin >> Tc;
  while(Tc--) {
    for(int i = 0; i < N; ++i) cin >> a[i];
    string res = "NO";
    for(int b = 0; b < (1<<N); ++b) {
      int pre[2] = {-1,-1};
      for(int i = 0; i < N; ++i) {
	int t = ((b>>i)&1);
	if(pre[t] != -1 && pre[t] > a[i]) {
	  break;
	}
	pre[t] = a[i];
	if(i+1 == N) res = "YES";
      }
    }
    cout << res << endl;
  }
  return 0;
}

C++: include<cstdio>
include<iostream>
sing namespace std;
nt main()

   int T;
   scanf("%d",&T);
   while(T--)
   {
       int n1=0,n2=0,x,jd;
       for(int i=1;i<=10;++i)
       {
           scanf("%d",&x);
           if(x>n1){n1=x;continue;}
           if(x>n2){n2=x;continue;}
           jd=1;
       }
       if(jd) puts("NO");
       else   puts("YES");
   }

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

const int N = 15;
int arr[N];
bool flag;


void dfs(int left, int right, int cur){
    if (flag) return;

    if (cur == 10){
        flag = true;
        return;
    }

    if (left < arr[cur]){
        dfs(arr[cur], right, cur + 1);
    }
    if (right < arr[cur]){
        dfs(left, arr[cur], cur + 1);
    }
}

int main(){
    int t; cin >> t;
    while (t--){
        for (int i = 0; i < 10; ++ i) cin >> arr[i];
        flag = false;

        int left(0), right(0);

        dfs(left, right, 0);
        if (flag) cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}