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

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

//conversion
//------------------------------------------
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();}

//debug
//-------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int n;
int m=10;
int** data;

void print_matrix(){

    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cout << data[i][j] << " ";
        }
        cout<<endl;
    }
}

bool dfs(int* row, int c, int head1, int head2){

    if(c+1 == m && (row[c] > head1 || row[c] > head2)){
        return true;
    }

    if(row[c] > head1){
        if(dfs(row, c+1, row[c], head2)){
            return true;
        }
    }

    if(row[c] > head2){
        if(dfs(row, c+1, head1, row[c])){
            return true;
        }
    }

    return false;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;

  data = (int**)malloc(sizeof(int*)*n);

  for(int i=0; i<n; i++){
      int* b = (int*)malloc(sizeof(int)*10);
      cin >> b[0] >> b[1] >> b[2] >> b[3] >> b[4] >> b[5] >> b[6] >> b[7] >> b[8] >> b[9];
      data[i] = b;

      bool res = dfs(data[i],0,0,0);
      if(res){
          cout << "YES" << endl;
      }else{
          cout << "NO" <<endl;
      }
  }

  for(int i=0; i<n; i++){
      free(data[i]);
  }
  free(data);

  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#include<cstdio>
#define MAXN 2555
#define INF 0x3f3f3f3f
#define v first
#define b second
using namespace std;
queue<int>q;
queue<int>p;
int s[15];
bool flag;
void dfs(int x)
{
   if(x==10)
   {
      flag=true;
      return ;
   }
   if(s[x]>q.front())
   {
      q.push(s[x]);
      dfs(x+1);
      q.pop();
   }
   if(s[x]>p.front())
   {
      p.push(s[x]);
      dfs(x+1);
      p.pop();
   }
   return ;
}
int main()
{
   int t;
   scanf("%d",&t);
   q.push(0);
   p.push(0);
   while(t--)
   {
      flag=false;
      for(int i=0;i<10;i++)
         scanf("%d",&s[i]);
      dfs(0);
      if(flag)
         cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
   }
   return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int a[10];
int n;

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

void solve(){
	rep(i,10) cin >> a[i];
	if(dfs(0,0,0)) cout << "YES" << endl;
	else cout << "NO" << endl;
	return;
}

int main(){
	cin >> n;
	rep(i,2){
		solve();
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  while (n--) {
    int a, b = 0, c = 0;
    bool f = true;
    for (int i = 0; i < 10; ++i) {
      cin >> a;
      if (b < a) b = a;
      else if (c < a) c = a;
      else f = false;
    }
    if (f) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

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

int main(){
  int n;
  int tmp[10];

  cin >> n;
  for(int i = 0 ; i < n ; i++){
    int cnt;
    for(int j = 0 ; j < 10 ; j++){
      cin >> tmp[j];
    }
    
    cnt = 0;

    for(int j = 0 ; j < 10 ; j++){
      if(!(tmp[j] < tmp[j+1])) cnt++;
    }
    
    //cout << cnt << endl;

    if(cnt <= 3) cout << "YES"<< endl;
    else cout <<"NO"<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>
using namespace std;

int arr[15],used[15];

void dfs(int pre,int cur)
{
    if(cur<10&&arr[pre]<arr[cur])
    {
        used[cur]=1;
        dfs(cur,cur+1);
    }
    else if(cur<10&&arr[pre]>=arr[cur])
        dfs(pre,cur+1);
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        bool judge=false;
        for(int i=0;i<10;i++)
            scanf("%d",&arr[i]);
        for(int i=0;i<10;i++)
        {
            memset(used,0,sizeof(used));
            used[i]=1;
            dfs(i,i+1);
            int pre=0;
            judge=false;
            for(int j=0;j<10;j++)
            {
                if(!used[j])
                {
                    if(pre>=arr[j])
                    {
                        judge=true;
                        break;
                    }
                    pre=arr[j];
                }
            }
            if(!judge)
            {
                printf("YES\n");
                break;
            }
        }
        if(judge) printf("NO\n");
    }
   return 0;
}

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

int ball[10];

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

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

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

	return false;
}


int main() {
	cin.tie(false);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;

	for(int i = 0; i < n; ++i) {
		for(int i = 0; i < 10; ++i)
			cin >> ball[i];

		cout << (dfs() ? "YES" : "NO") << endl;
	}

	return EXIT_SUCCESS;
}

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

int main(){
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		int a=0, b=0;
		for(int j=0; j<10; j++){
			int m;
			cin >> m;
			if(m > a){
				a = m;
			}else if(m > b){
				b = m;
			}else{
				a = 100;
			}
		}
		if(a==100){
			cout << "NO" << endl;
		}else{
			cout << "YES" << endl;
		}
	}
    return 0;
}

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

using namespace std;

vector<int> a;
stack<int> b, c;

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

	bool res1 = false, res2 = false;

	if (b.empty() || b.top() < a[i]) {
		b.push(a[i]);
		res1 = dfs(i + 1);
		b.pop();
	}

	if (c.empty() || c.top() < a[i]) {
		c.push(a[i]);
		res2 = dfs(i + 1);
		c.pop();
	}

	return res1 || res2;
}

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

	while (n--) {
		a.clear();
		while (b.size()) b.pop();
		while (c.size()) c.pop();

		for (int i = 0; i < 10; ++i) { int v; cin >> v; a.push_back(v); }

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