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 main(void)
{
  int a,b,ball[10],n,i,flag;
  scanf("%d",&n);
  while(n-->0)
  {
    a=-1;b=-1;
    for(i=0;i<9;i++)
      scanf("%d",&ball[i]);
    for(i=0;i<9;i++)
    {
      flag=0;
      if(ball[i]>a)
        flag=1;

      if(ball[i]>b)
      {
        if(flag==1)
        {
          if(ball[i]-a<ball[i]-b)
            a=ball[i];
          else
            b=ball[i];
        }else{
          b=ball[i];
        }
        flag=2;
      }
      if(flag==0)
      {
        printf("NO\n");
        break;
      }
      if(flag==1)
        a=ball[i];
    }
    if(flag!=0)
      printf("YES\n");
  }
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "iostream"
#include "cstdio"
using namespace std;

#define TEST 0
#if TEST
FILE *in = freopen("./Q/quest.txt", "r", stdin);
FILE *out = freopen("./A/ans.txt", "w", stdout);
#endif

int hantei(int left,int right,int *ball,int i){
	if (i == 10)return 1;
	int OK = 0;
	if (left < ball[i])OK=hantei(ball[i], right, ball, i + 1);
	if (right < ball[i])OK=hantei(left, ball[i], ball, i + 1);
	return OK;
}

int main(){

	int n,ball[10],left=0,right=0,FLAG=2;
	cin >> n;
	while (n--){
		int i = 0;
		for (auto&& x : ball)cin >> x;
		if (hantei(left, right, ball, i))cout << "YES" << endl;
		else cout << "NO" << endl;

	}

#if TEST
	fclose(in);
	fclose(out);
#endif
	return 0;

}

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

int balls[20];
int R, L;

bool dfs(int n) {
  if (n == 10) {
    return true;
  }
  if (R < balls[n]) {
    R = balls[n];
    if (dfs(n+1)) {
      return true;
    }
  }
  if (L < balls[n]) {
    L = balls[n];
    if (dfs(n+1)) {
      return true;
    }
  }
  return false;
}

int main(void) {
  int N;
  cin >> N;
  while (N--) {
    for (int i = 0; i < 10; i++) {
      cin >> balls[i];
    }
    R = balls[0];
    L = 0;

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

  return 0;
}

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

int n,len,ball[20],used[20];

int f()
{
	int t = -1;
	for (int i=1;i<=10;++i)
		if (!used[i])
		{
			if (ball[i] < t) return 0;
			t = ball[i];
		}
	t = -1;
	for (int i=1;i<=10;++i)
		if (used[i])
		{
			if (ball[i] < t) return 0;
			t = ball[i];	
		}
	return 1;
}

int dfs(int x,int l)
{
	if (l == len) return f();
	for (int i=x+1;i<=10;++i)
		if (!used[i])
		{
			used[i] = 1;
			if (dfs(i,l+1)) return 1;
			used[i] = 0;
		}
	return 0;
}

int main()
{
//	freopen("in.txt","r",stdin);
	cin>>n; 
	while (n--)
	{
		int flag = 0;
		for (int i=1;i<=10;++i) cin>>ball[i];
		for (int i=0;i<=5;++i)
		{
			memset(used,0,sizeof(used));
			len = i;
			if (dfs(0,0)) 
			{
				flag = 1;
				break;
			}
		}
		if (flag) cout<<"YES";
		else cout<<"NO";
		cout<<'\n';
	}
	return 0;
}

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

int main() {
	int n, x;
	cin >> n;
	for (int lop = 0, a = 0, b = 0; lop < n; lop++) {
		bool f = true;
		for (int i = 0; i < 10; i++) {
			cin >> x;
			if (f) {
				if (a < x&&b < x) {
					if (a < b) {
						b = x;
						continue;
					}
					a = x;
					continue;
				}
				if (a < x) {
					a = x;
					continue;
				}
				if (b < x) {
					b = x;
					continue;
				}
				f = false;
			}
		}
		cout << (f ? "YES" : "NO") << endl;
	}
	return 0;
}

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

using namespace std;

bool flag;
int a[10];

void dfs(int ap, int b, int c){
 
  if(!ap){
    flag = true;
    return;
  }
  else{
    if(a[10 - ap] > b){
      return dfs(ap - 1, a[10 - ap], c); 
    }
    else if(a[10 - ap] > c){
      return dfs(ap - 1, b, a[10 - ap]); 
    }
    else{
      return;
    }
  }

}

int main(){

  int n;

  cin >> n;

  for(int i = 0; i < n; ++i){
    
    flag = false;
    
    for(int j = 0; j < 10; ++j){
      cin >> a[j];
    }
    
    dfs(10, 0, 0);

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

  }

}

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

vector<int> data;
vector<int> tube_B;
vector<int> tube_C;

const int MAX = 10;

int dfs(int count){

    if (count == MAX) return 1;

    int ret = 0;

    int b = tube_B.size() - 1;
    int c = tube_C.size() - 1;

    if (data[count] > tube_B[b]){
        tube_B.push_back(data[count]);
        ret = max(ret, dfs(count + 1));
        tube_B.pop_back();
    }

    if (data[count] > tube_C[c]){
        tube_C.push_back(data[count]);
        ret = max(ret, dfs(count + 1));
        tube_C.pop_back();
    }

    return ret;
}

int main(void){

    int n;
    cin >> n;
    tube_B.push_back(-1);
    tube_C.push_back(-1);

    for (int i = 0; i < n; i++){
        for (int j = 0; j < 10; j++){
            int s;
            cin >> s;
            data.push_back(s);
        }

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

        data.erase(data.begin(), data.end());
        tube_B.erase(tube_B.begin(), tube_B.end());
        tube_C.erase(tube_C.begin(), tube_C.end());
    }


}

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

using namespace std;

int n, ball[10];

bool solve(int idx, int l, int r) {

    if(idx == 10) return true;

    bool ret = false;
    if(ball[idx] > l) ret = ret || solve(idx + 1, ball[idx], r);
    if(ball[idx] > r) ret = ret || solve(idx + 1, l, ball[idx]);
    return ret;

}

int main() {

    cin >> n;

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

}

C++: //C++14 (Clang 3.8.0)

#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 <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#define rp(i,a,b) for(int (i)=(int)(a);i<(int)(b);++i)

typedef long long ll;


using namespace std;
int main(){
    int N;
    cin>>N;
    
    for(int i=0;i<N;i++){
        stack<int> a,b;
        a.push(0);
        b.push(0);
        bool flag=true;
        for(int j=0;j<10;j++){
            int tm;
            cin>>tm;
            if(tm>a.top()) a.push(tm);
            else if(tm>b.top()) b.push(tm);
            else {flag=false;}
        }
        if(flag)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }

    return 0;
};