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 n1,n2,num,temp,flg=1;
	cin>>num;
	while(num--){
		cin>>n1;
		for(int i=0;i<9;i++){
			cin>>temp;
			if(temp<n1&&temp<n2) flg=0;
			if(temp>n1) n2=temp;
			else if(temp>n2) n1=temp;
		}if(flg==1) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}return 0;
}

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

using namespace std;

int ball[10];
int B[10];
int C[10];
int D[2] = {0,1};
int j,k;
int ans;

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

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

    bfs(0);

    if(ans == 1)cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

void bfs(int n)
{
  if(n == 1){
    ans = 1;
    return ;
  }
  for(int i = 0;i < 2;i++){
    if(D[i] == 0){
      B[j] = ball[n];
      n++;
      if(B[j] < B[j-1])	return ;
      j++;
      bfs(n);
    }
    else{
      C[k] = ball[n];
      n++;
      if(C[k] < C[k-1])return ;
      k++;
      bfs(n);
    }
    return ;
  }
}

C++: #include <iostream>

using namespace std;

int main()
{
	int N;
	cin >> N;
	
	int input[10];
	
	for (int i=0; i<N; i++) {
		for (int j=0; j<10; j++) cin >> input[j];
		
		int a[11] = {0};
		int b[11] = {0};
		
		bool success = true;
		
		for (int j=0, a_top=1, b_top=1; j<10; j++) {
			if (a[a_top-1] < input[j]) a[a_top++] = input[j];
			else if (b[b_top-1] < input[j]) b[b_top++] = input[j];
			else { success = false; break; }
		}
		if (success) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int num[2] = {0};
		int flag = 1;
		for (int j = 0; j < 10; j++) {
			int k;
			cin >> k;
			if (num[0] < k && num[1] < k) {
				num[num[0] < num[1]] = k;
			}
			else if (num[0] < k && num[1] >= k) {
				num[0] = k;
			}
			else if (num[0] >= k && num[1] < k) {
				num[1] = k;
			}
			else {
				flag = 0;
			}
		}
		if (flag) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string.h>

using namespace std;

int ball_list[10];
int right_list[10];
int left_list[10];

bool flag;

void dfs(int right, int left){
  int count = right + left;

  if(count == 10){
    flag = true;
  }else{
    if(right == 0 || right_list[right-1] < ball_list[count]){
      if(right == 0){
        right_list[0] = ball_list[count];
      }else{
        right_list[right] = ball_list[count];
      }
      dfs(right+1, left);
    }
    if(left == 0 || left_list[left-1] < ball_list[count]){
      if(left == 0){
        left_list[0] = ball_list[count];
      }else{
        left_list[left] = ball_list[count];
      }
      dfs(right, left+1);
    }
  }
}

int main(){
  int n;

  cin >> n;

  for(int i = 0; i < n; i++){
    flag = false;
    memset(right_list, 0, sizeof(right_list));
    memset(left_list, 0, sizeof(left_list));

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

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

  return 0;
}

C++: #include <stdio.h>

int n;
int data[10];
int ans[100];

bool solve(int i, int l, int r){
  if(i==10)
    return true;
  if(data[i] > l)
    return solve(i+1,data[i],r);
  if(data[i] > r)
    return solve(i+1,l,data[i]);
  return false;
}
int main(){
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 10; j++){
      scanf("%d", &data[j]);
      if(solve(0,0,0)){
        ans[i] = 1;
      }else{
        ans[i] = 0;
      }
    }
  }
  for(int i = 0; i < n; i++){
    if(ans[i])
      printf("YES\n");
    else
      printf("NO\n");
  }
}

C++: #include<cstdio>
#include<cstring>
int in[12],a[12],b[12];
int dfs(int *a, int cur_a, int *b, int cur_b, int cur)
{
    if(cur == 10) return 1;
    int yes = 0;
    if(cur_a < 9 && (!cur_a || in[cur] > a[cur_a-1])){
        a[cur_a] = in[cur];
        if(dfs(a,cur_a+1,b,cur_b,cur+1)) return 1;
    }
    if(cur_b < 9 && (!cur_b || in[cur] > b[cur_b-1])){
        b[cur_a] = in[cur];
        if(dfs(a,cur_a,b,cur_b+1,cur+1)) return 1;
    }
    return 0;
}
int main()
{
    int n;
    scanf("%d",&n);
    while(n--){
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for(int i = 0; i < 10; i++)
            scanf("%d",&in[i]);
        if(dfs(a,0,b,0,0)) printf("YES\n");
        else printf("NO\n");
    }
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){
	vector<int> pile1;
	vector<int> pile2;
	int n;
	cin>>n;
	int num[10];
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			cin>>num[j];
		}
		pile1.push_back(num[0]);
		for(int k=1;k<10;k++){
			int a = pile1[pile1.size()-1];
			if(pile2.size() != 0){
				int b = pile2[pile2.size()-1];
				if(num[k]>a) pile1.push_back(num[k]);
				else if(num[k]>b) pile2.push_back(num[k]);
				else{
					cout<<"NO"<<endl;
					break;
				}
			}else{
				if(num[k]>a) pile1.push_back(num[k]);
				else pile2.push_back(num[k]); 
			}
			if(k==9) cout<<"YES"<<endl;
		}
	}
	return 0;
}

C++: #include <cstdio>
int a;
int main(void){
    int n;
    scanf("%d",&n);

    for(int i=1;i<=n;i++){
        int b=-1,c=-1;
        bool flag=0;
        for(int j=1;j<=10;j++){
            scanf("%d",&a);
            if(b<a&&c<a&&!flag){
                if(b<c){
                    c=a;
                }
                else{
                    b=a;
                }
            }
            else if(b<a&&c>a&&!flag){
                b=a;
            }
            else if(b>a&&c<a&&!flag){
                c=a;
            }
            else{
                    flag=1;
                continue;
            }
        }
        if(flag) printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}

C++: #include<stdio.h>

int b=0,c=0;

int unname(int *ball,int i)
{
	if(i==10) return 1;
	if(c<ball[i]){
		c=ball[i];
		i++;
		return unname(ball,i);
	}
	if(b<ball[i]){
		b=ball[i];
		i++;
		return unname(ball,i);
	}
	return 0;
}

int main()
{
	int ball[10],n;
	int result,i;
	scanf("%d",&n);
	for(int j=0;j<n;j++)
	{
		for(i=0;i<10;i++)
		{
			scanf("%d",&ball[i]);
		}
		i=0;
		result=unname(ball,i);
		if(result==1) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}