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 d[10];

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

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++)cin>>d[j];
        if(dfs(-1, -1, 0))cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

bool flag;
void Search(int a[], int pos, int b, int c)
{
	if(pos == 10)
	{
		flag = true;
	}
	if(b > a[pos] && c > a[pos])
	{
		return;
	}
	if(b < a[pos])
	{
		Search(a, pos + 1, a[pos], c);
	}
	if(c < a[pos])
	{
		Search(a, pos + 1, b, a[pos]);
	}
}

void solve()
{
	int N;
	cin >> N;
	while(N--)
	{
		flag = false;
		int A[10];
		for(int i = 0; i < 10; ++i)
		{
			cin >> A[i];
		}
		int B = 0, C = 0;
		Search(A, 0, B, C);
		if(flag)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
int N, acnt, bcnt;
int x[10], A[10], B[10];

bool dfs(int cnt) {
    if (cnt == 10) return true;
    // Aに入れる
    if (A[acnt] < x[cnt]) {
        A[++acnt] = x[cnt];
        return dfs(cnt+1);
    }
    // Bに入れる
    else if (B[acnt] < x[cnt]) {
        B[++bcnt] = x[cnt];
        return dfs(cnt+1);
    }
    return false;
}

int main(void) {
    cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 10; j++) {
            A[j] = 0; B[j] = 0;
        }
        acnt = 0; bcnt = 0;
        for (int j = 0; j < 10; j++) cin >> x[j];
        if (dfs(0)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

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

stack<int> array1,array2;
int Balls[10];

bool DFS(int number,stack<int> s1,stack<int> s2){
  if(number > 9) return true;
  if(s1.top() < Balls[number]){
    s1.push(Balls[number]);
    if(DFS(number+1,s1,s2)){
      return true;
    }
    s1.pop();
  }
  if(s2.top() < Balls[number]){
    s2.push(Balls[number]);
    if(DFS(number+1,s1,s2)){
      return true;
    }
    s2.pop();
  }
  return false;
  /*if(number > 9) return;
  if(firstarray){
    if(array1.top() < Balls[number]){
      array1.push(Balls[number]);
      DFS(number+1,false);
      DFS(number+1,true);
    }
    else if(second){
      return;
    }
    else{
      DFS(number,false,true);
    }
  }
  else{
    if(array2.top() < Balls[number]){
      array2.push(Balls[number]);
      DFS(number+1,false);
      DFS(number+1,true);
    }
    else if(second){
      return;
    }
    else{
      DFS(number,true,true);
    }
  }*/
}

int main(){

    int N;

    cin >> N;

    for(int i=0;i<N;i++){
      for(int i=0;i<10;i++){
        cin >> Balls[i];
      }
      array1.push(0);
      array2.push(0);

      if(DFS(0,array1,array2)){
        cout << "YES" << endl;
      }
      else{
        cout << "NO" << endl;
      }
      while (!array1.empty()) {
        array1.pop();
      }
      while (!array2.empty()) {
        array2.pop();
      }
    }
    return 0;
}

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

using namespace std;


int q;
int Ball[10];
bool flag;
vector<string> log;

bool is_satisfies(vector<int> a) {
    vector<int> copy = a;
    sort(a.begin(), a.end());
    return a == copy;
}

void bfs(int i, vector<int> B, vector<int> C) {
    if (i == 9) {
        if (is_satisfies(B) && is_satisfies(C))
            flag = true;
        else
            flag = flag == true ? true : false;
    } else {
        vector<int> temp;

        temp = B;
        temp.push_back(Ball[i]);
        bfs(i + 1, temp, C);

        temp = C;
        temp.push_back(Ball[i]);
        bfs(i + 1, B, temp);
    }
}

void solve() {
    vector<int> B, C;
    flag = false;

    bfs(0, B, C);

    if (flag)
        log.push_back("YES");
    else
        log.push_back("NO");
}

int main() {
    cin >> q;
    for (int i = 0; i < q; ++i) {
        for (int j = 0; j < 10; ++j)
            scanf("%d", &Ball[j]);

        solve();
    }

    for (int i = 0; i < log.size(); ++i) {
        cout << log[i] << endl;
    }
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;

int pow(int a,int n){
	if(n <= 0){
		return 1;
	}
	return a * pow(a,n - 1);
}

int main(){
	int n;
	int a[10];
	int ans1 = 0;
	int ans2 = 0;
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		ans1 = 0;
		ans2 = 0;
		for(int j = 0; j < 10; j++){
			scanf("%d",&a[j]);
		}
		for(int j = 0; j < 10; j++){
			if(ans1 >= ans2 && ans1 < a[j]){
				ans1 = a[j];
			}else if(ans2 > ans1 && ans2 < a[j]){
				ans2 = a[j];
			}else if(ans1 < a[j]){
				ans1 = a[j];
			}else if(ans2 < a[j]){
				ans2 = a[j];
			}else{
				printf("NO\n");
				break;
			}
			if(j == 9){
				printf("YES\n");
			}
		}
	}
	///////////////////////////////////
	//Sleep(200000);///////////////////// 提出するときは必ず外す！
	///////////////////////////////////
	return 0;

}

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

#define size 10

bool dfs(int a[],int i,int b,int c){
  if(i==0)return 1;

  bool flag=0;

  if(a[size-i]>b){
    flag += dfs(a,i-1,a[size-i],c);
  }
  if(a[size-i]>c){
    flag += dfs(a,i-1,b,a[size-i]);
  }

  return flag;
}

int main(){
  int n;
  cin >> n;
  while(n>0){
    int a[size];

    for(int i=0; i<size; i++){
      cin >> a[i];
    }

    if(dfs(a,size,0,0)){
      cout << "YES\n";
    }else{
      cout << "NO\n";
    }

    n--;
  }

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
 
#define REP(i,b,n) for(int i=b;i<n;++i)
#define REPR(i,b,n) for(int i=n-1;i>=b;--i)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n>>b) & 1)
#define PI acos(-1.0)

using namespace std;

static const double EPS = 1e-9;
typedef pair<int, int> pii;
typedef long long ll;

int ball[10];

bool issorted(vector<int> v){

	if(v.size() < 2)
		return true;
	
	for(int i = 0 ; i < v.size()-1; ++i){
	
		if(v[i] > v[i+1])
			return false;
	}
	
	return true;
}

string solve(){
	
	for(int i=0; i < (1<<10); ++i){
		
		vector<int> lft, rgt;
		
		for(int j=0; j<10; ++j){
			
			if(BIT(i,j))
				lft.push_back(ball[j]);
			else
				rgt.push_back(ball[j]);
		}
		
		if(issorted(lft)&& issorted(rgt)){
			return "YES";
		}
	}
	
	return "NO";
}		

int main(){
		
	int n;
	cin >> n;
	
	for(int k=0; k<n; ++k){
	
		for(int i=0; i<10; ++i){
			cin >> ball[i];
		}
		
		cout << solve() << endl;
	}
	
	return 0;
}