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 <bits/stdc++.h>
using namespace std;

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

  for(int i=0; i<N; i++){
    vector<int> balls(10);
    for(int j=0; j<10; j++) cin >> balls[j];

    priority_queue<int> A, B;
    A.push(0); B.push(0);

    bool flag = true;
    for(int j=0; j<10; j++){
      if(A.top() > balls[j] && B.top() > balls[j]){
        if(flag) cout << "NO" << endl; 
        flag = false;
      } else if (A.top() < balls[j] && B.top() > balls[j]){
        A.push(balls[j]);
      } else if (A.top() > balls[j] && B.top() < balls[j]){
        B.push(balls[j]);
      } else {
        if(A.top() > B.top()){
          A.push(balls[j]);
        } else {
          B.push(balls[j]);
        }
      }
    }

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

C++: #include <iostream>
using namespace std;
const int N = 10;
int main(){
    int n;
    cin >> n;
    while(n--) {
        bool ans = true;
        int a, b=-1, c=-1;
        for(int i=1; i<=N; i++) {
            cin >> a;
            if(ans) {
                if(a > b)
                    b = a;
                else if(a > c)
                    c = a;
                else
                    ans = false;
       }
    }
    if(ans) puts("YES");
    else puts("NO");
}
}

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

using namespace std;

int main() {
	vector<int> left;
	vector<int> right;
	vector<int> all;

	bool flag = true;

	int n;
	cin >> n;
	if (n == 0) return -1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else  if (all.size() == n*j) {

						}
						else {
							flag = false;
						}
						
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}

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

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
using namespace std;
int balls[10];

bool dfs(int n, int left, int right) {
	if(n == 10) return true;
	if(balls[n] > left && dfs(n + 1, balls[n], right)) return true;
	if(balls[n] > right && dfs(n + 1, left, balls[n])) return true;
	return false;
}

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

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<(int)n;i++)
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rrep(i,n) for(int i = 1; i <= n; i++)
#define drep(i,n) for(int i = n; i >= 0; i--)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }

void chmax(int& a,int b){
	if(b > a){
		a=b;
	}
}
string j(){
	int a;
    int b=0,c=0;
    for(int i=0;i<10;i++){
        cin>>a;
        if(a>b){
            b=a;
        }else if(a>c){
            c=a;
        }else{
        	return "NO";
        }
    }
    return "YES";

}
int main(){
	int N;
	cin >> N;
	rep(i,N){
		cout << j() << endl;
	}
	return 0;
}

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

int main(void)
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        queue < int > b, c;
        bool flag = true;
        
        b.push(0);
        c.push(0);
        
        int tmp;
        for (int i = 0; i < 10; i++){
            scanf("%d", &tmp);
            if ((b.back() < tmp) && (c.back() < b.back())){
                b.push(tmp);
                if (i == 9) flag = true;
            }
            else if (c.back() < tmp){
                c.push(tmp);
                if (i == 9) flag = true;
            }
            else flag = false;
        }
        if (flag) printf("YES\n");
        else if (!flag) printf("NO\n");
    }
    
    return (0);
}

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

using namespace std;

bool Check(const int* input, int s, int left, int right) {
  if (s == 10) return true;
  bool ret = false;
  if (input[s] >= left) {
    ret = Check(input, s + 1, input[s], right);
    if (ret) return true;
  } else if (input[s] >= right) {
    ret = Check(input, s + 1, left, input[s]);
    if (ret) return true;
  }
  return false;
}

int main() {
  int input[10];
  int left, right;
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 10; ++j) {
      cin >> input[j];
    }
    if (Check(input, 0, INT_MIN, INT_MIN)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}

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

int p=0,nr=0,nl=0;
int a[10]={};
vector<int> r,l;

int f(int nr,int nl,int p){
	//cout<<"a[p]="<<a[p]<<" nr="<<nr<<" nl="<<nl<<" p="<<p<<endl;;
	if(a[p]>nr){
		r.push_back(a[p]);
		nr=a[p];
		if(p==9){
			return 1;
		}
		p++;
		if(f(nr,nl,p)==1){
			return 1;
		}
		else if(f(nr,nl,p)==-1){
			if(nr>nl){
				p--;
				r.pop_back();
			}
			else if(nl>nr){
				p--;
				l.pop_back();
			}
		}
	}
	if(a[p]>nl){
		l.push_back(a[p]);
		nl=a[p];
		if(p==9){
			return 1;
		}
		p++;
		if(f(nr,nl,p)==1){
			return 1;
		}
	}
	return -1;
	}

int main(){
	int i,j,n;
	cin>>n;
	for(i=0;i<n;i++){
		for(j=0;j<10;j++){
			cin>>a[j];
		}
		p=0;
		if(f(nr,nl,p)==1){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}
return 0;
}