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 n,a,b=0,c=0;
  int i,j;
  int flag=0;
  cin >> n;
  for(i=0;i<n;i++){
    for(j=0;j<10;j++){
      cin >> a;
      if(b<a){
	b=a;
      }
      else if(c<a){
	c=a;
      }
      else{
	flag=1;
      }
    }
    if(flag==0)cout << "YES" << endl;
    if(flag==1)cout << "NO" << endl;
    b=0,c=0;
    flag=0;
  }
}

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

int a[10];
bool flag;
vector< int > l;
vector< int > r;
void dfs(int dep)
{
	if (flag) return;
	if(dep == 10) {
		flag = true;
		return;
	}
	if (l.size() == 0 || l.back() < a[dep]) {
		l.push_back(a[dep]);	
		dfs(dep + 1);
	}
	if (r.size() == 0 || r.back() < a[dep]) {
		r.push_back(a[dep]);
		dfs(dep + 1);
	}
}
int main()
{
	int t;
	cin >> t;
	for (int cas = 0; cas < t; cas++) {
		for (int i = 0; i < 10; i++) { cin >> a[i]; }
		flag = false;
		dfs(0);
		if (flag) cout << "YES\n";
		else cout << "NO\n";
	}
	return 0;
}

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

using namespace std;

int  s[10];

int main()
{
	//freopen("in.txt", "r", stdin);

	int case_t, case_num;
	scanf("%d", &case_num);
	for (case_t=1; case_t<=case_num; case_t++) {
		int i;
		for (i=0; i<10; i++)
			scanf("%d", &s[i]);

		int min1 = -1, min2 = -1;

		for (i=0; i<10; i++) {
			if (s[i]<min1 && s[i]<min2)
				break;
			if (s[i]>min1 && s[i]>min2) {
				if (min1 < min2)
					min2 = s[i];
				else
					min1 = s[i];
			}
			else if (s[i]>min1)
				min1 = s[i];
			else
				min2 = s[i];

		}
		if (i<10) printf("NO\n");
		else printf("YES\n");


	}

	return 0;
}

C++: #include<stdio.h>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

bool flag = true;

void solve(queue<int> left, queue<int> right, queue<int> all) {
	if (all.size() > 0) {
		if (left.size() > 0) {
			if (all.front() > left.back()) {
				left.push(all.front());
				all.pop();
				solve(left, right, all);
			}
			else {
				if (right.size() > 0) {
					if (all.front() > right.back()) {
						right.push(all.front());
						all.pop();
						solve(left, right, all);
					}
					else if(all.size() == 0){
					
					}
					else {
						flag = false;
					}
				}
				else {
					right.push(all.front());
					all.pop();
					solve(left, right, all);
				}
			}
		}
		else {
			left.push(all.front());
			all.pop();
			solve(left, right, all);
		}
	}
}

int main() {

	int n;
	cin >> n;
	for (; n > 0; n--) {
		queue<int> all;
		queue<int> left;
		queue<int> right;
		for (int i = 0; i < 10; i++) {
			int temp;
			cin >> temp;
			all.push(temp);
		}
		solve(left, right, all);
		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}



	
				   
}

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

int N;


int main()
{
	//freopen("in","r",stdin);
	scanf("%d",&N);
	while(N--){
		int tmp;
		bool sol=true;
		stack<int> B,C;
		for(int i=0;i<NUM;i++){
			
			scanf("%d",&tmp);
			if(B.empty())
				B.push(tmp);
			else if(tmp>B.top())
				B.push(tmp);
			else if(C.empty())
				C.push(tmp);
			else if(tmp>C.top())
				C.push(tmp);
			else
				sol = false;
		}
		if(sol)
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}

C++: #include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

vector<int> v(10);

int l,r;
int flag;

void dfs(int d){

    if(d==10){
        flag=1;
        return;
    }

    if(flag) return;

    int x = v[d];

    if(x>l){

        int tmp = l;
        l=x;
        dfs(d+1);
        l=tmp;

    }

    if(flag) return;

    if(x>r){

        int tmp = r;
        r=x;
        dfs(d+1);
        r = tmp;

    }

}

int main(){

    int N;

    cin >> N;

    for(int t=0;t<N;++t){

        for(int i=0;i<10;++i)cin >> v[i];

        l = r = flag = 0;

        dfs(0);

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

    }

    return 0;

}

C++: #include<iostream>
using namespace std;
int main(void)
{
int n;
cin>>n;

for(int i=0;i<n;i++)
{
	int a[10]={0};
	for(int j=0;j<10;j++)
	{
	int x;
	cin>>x;
	a[j]=x;
	}
	int b=a[0],c=a[0],k;
		for(k=1;k<10;k++)
		{
			if(b<a[k])b=a[k];
			else if(c<a[k])c=a[k];
			else 
			{
			cout<<"NO"<<endl;
			break;
			}
		}
		if(k==10)cout<<"YES"<<endl;
	/*for(int i=0;i<10;i++)
	{
	cout<<b[i]<<" ";

	}
	cout<<endl;
	for(int i=0;i<10;i++)
	{
	cout<<c[i]<<" ";
	}
	for(int i=0;i<10-1;i++)
	{
		if(b[i]>b[i+1] && b[i+1]!=0 || c[i]>c[i+1] && c[i+1]!=0)
		{
		cout<<"NO"<<endl;
		break;
		}
	else 
		{
		cout<<"YES"<<endl;
		break;
		}
	}*/
}
return 0;
}

C++: #include<algorithm>
#include<stdio.h>
#include<vector>
#include<queue>

using namespace std;

int A[13] = { 0 };

bool solve(int a, int b,int c) {
	if (++c == 10)
		return true;
	else {
		bool r = false;
		if (a < A[c])
			r = solve(A[c], b, c);
		if (b < A[c] && r == false)
			r = solve(a,A[c], c);
		
		return r;
	}
}

int main(void) {
	A[10] = A[11] = A[12] = 100;
	int n = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++)
			scanf("%d", &A[j]);
		if (solve(A[0], 0, 0))
			printf("YES\n");
		else
			printf("NO\n");
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

bool flag;
int a[10], b[10], c[10];

void dfs(int ap, int bp, int cp){
  
  // cout << ap << ' ' << bp << ' ' << cp << endl;

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

  if(ap < 2){
    if(ap){
      b[0] = a[ap];
      dfs(ap + 1, bp + 1, cp);
      b[bp] = 0;
    }
    else{
      c[0] = a[ap];
      dfs(ap + 1, bp, cp + 1);
      c[cp] = 0;
    }
  }
  else{

    if(a[ap] > b[bp - 1]){
      b[bp] = a[ap];
      dfs(ap + 1, bp + 1, cp);
      b[bp] = 0;
    }
    
    if(a[ap] > c[cp - 1]){
      c[cp] = a[ap];
      dfs(ap + 1, bp, cp + 1);
      c[cp] = 0;
    }

  }

  return;

}

int main(){

  int n;

  cin >> n;

  for(int i = 0; i < n; ++i){
    
    flag = false;

    for(int j = 0; j < 10; ++j){
      b[j] = 0;
      c[j] = 0;
    }
    
    for(int j = 0; j < 10; ++j){
      cin >> a[j];
    }
    
    dfs(0, 0, 0);

    cout << (flag ? "YES" : "NO") << endl;

  }

}

C++: #include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
int a[10];
for(int j=0;j<10;j++)scanf("%d",&a[i]);
bool ans=true;
for(int j=0;j<10;j++){
for(int k=j+1;k<10;k++){
for(int l=k+1;l<10;l++){
if(a[j]>a[k]&&a[k]>a[l])ans=false;
}
}
}
if(ans)printf("YES\n");
else printf("NO\n");
}
return 0;
}

C++: #include <cstdio>

using namespace std;

int ball[10];

bool dfs(int left, int right, int n) {
  if (n == 10) return true;
  return ((left < ball[n]) && dfs(ball[n], right, n + 1)) ||
    ((right < ball[n]) && dfs(left, ball[n], n + 1));
}

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

  while (n--) {
    for (int i = 0; i < 10; ++i) {
      scanf("%d", &ball[i]);
    }

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