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>
#include <queue>
using namespace std;
int ball[10];
int dfs(int k,int B,int C)
{
    if(k == 9)
        return 1;
    if(ball[k] > B)
        return dfs(k + 1,ball[k],C);
    if(ball[k] > C)
        return dfs(k + 1,B,ball[k]);
    return 0;
}
int main(void)
{
    int n;
    cin>>n;
    while(n--){
        int i;
        queue<int> left,right;
        for(i = 0;i < 10;i++)
            cin>>ball[i];
        if(dfs(0,0,0))
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int ball[10];
		for(int i = 0; i < 10; i++)cin >> ball[i];
		int b = 0,c = 0;
		for(int i = 0; i < 10; i++){
			if(b > ball[i] && c > ball[i]){
				cout << "NO" << endl;
				goto no;
			}else if(b < ball[i] && c > ball[i])b = ball[i];
			else if(b > ball[i] && c < ball[i])c = ball[i];
			else if(b > c)b = ball[i];
			else c = ball[i];
		}
		cout << "YES" << endl;
		no:;
	}
}

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

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

void initial()
{
	for(int i=0;i<10;i++)
	{
		b[i]=-1;
        c[i]=-1;
	}
}
bool judge()
{
  int p=0,q=0,i;
  initial();
  b[0]=a[0];
  for(i=1;i<10;i++)
  {
	  if(a[i]>b[p])b[++p]=a[i];
	  else if(q==0)c[q++]=a[i];
	  else if(a[i]>c[q-1])c[q++]=a[i];
	  else 
	  {
		  return false;
		  break;
	  }
  }
  if(i==10)
	  return true;
}

int main()
{
	int num;
	cin>>num;
	while(num--)
	{
		for(int i=0;i<10;i++)
			cin>>a[i];
		puts(judge()?"YES":"NO");
	}
return 0;
}

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

using vi = vector<int>;
using vs = vector<string>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repback(i,n) for(int i=(int)n-1;i>=0;i--)
#define repa(i,a,n) for(int i=a;i<(int)(n);i++)
typedef pair<int, int> P;
typedef queue<int> qi;
typedef long long ll;
const ll INF = 1e7, MAX_N = 99, MAX_M = 1000, MAX_W = 100, MAX_H = 100;

int asc(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}
void clear(std::queue<int>& q)
{
    std::queue<int> empty;
    std::swap(q, empty);
}

int N;
int balls[10];
qi qa, qb;
bool possible = false;

void bfs(int i) {
    //完遂可能
    if (i == 10) {
        possible = true;
        return;
    }
    //Aに球をのせられる場合
    if (qa.empty() || qa.back() < balls[i]) {
        qa.push(balls[i]);
        bfs(i + 1);
    }
    //Bに球をのせられる場合
    if (qb.empty() || qb.back() < balls[i]) {
        qb.push(balls[i]);
        bfs(i + 1);
    }
    //完遂不可能
    else return;
}
int main() {
    //入力
    cin >> N;
    rep(p, N) {
        rep(k, 10) cin >> balls[k];
        possible = false;
        clear(qa); clear(qb);
        bfs(0);
        if (possible) cout << "YES" << endl;
        if (!possible) cout << "NO" << endl;
    }
    return 0;
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		int a[9]={};
		int b[9]={};
		int dat,o=1,s=1;
		for(int j=0;j<=10;j++){
			if(j==10){
				cout<<"YES"<<endl;
				break;
						}
			cin>>dat;
		 	if(j==0){
				a[0]=dat;
			}
			else if(dat>a[s-1]){
				a[s]=dat;
				s++;
			}
			else if(dat>b[o-1]){
				b[o]=dat;
				o++;}
			else if(dat<a[s-1] && dat<b[o-1]){
				cout<<"NO"<<endl;
			break;
			}
					}
	}
	return 0;
}

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

int main(){
	int ball[10];
	int cell[2][10]={0};
	int n,i,k,cell_1=1,cell_2=1,flag[1000]={0};
	
	scanf("%d",&n);
	
	for(k=0;k<n;k++){
		for(i=0;i<10;i++)scanf("%d",&ball[i]);
		
		cell[0][0]=ball[0];
		cell[1][0]=ball[1];

		for(i=2;i<10;i++){
			if(cell[0][cell_1-1] < ball[i]){
				cell[0][cell_1]=ball[i];
				cell_1++;
			}
			else if(cell[1][cell_2-1] < ball[i]){
				cell[1][cell_2]=ball[i];
				cell_2++;
			}
			else flag[k]=1;
		}	
	}
	for(i=0;i<n;i++){	
		if(flag[i]==0)printf("YES\n");
		else printf("NO\n");
	}
	
	return 0;
}

C++: #include <iostream>

const size = 10;

int num[size];

bool dfs(int beforeB, int beforeC, int depth) {
	if(depth == 10)
		return true;
	
	if(num[depth] > beforeB)
		return dfs(num[depth], beforeC, depth + 1);
	else if(num[depth] > beforeC)
		return dfs(beforeB, num[depth], depth + 1);
	else
		return false;
}

int main() {
	int n = 0;
	std::cin >> n;
	
	for(int i = 0; i < n; ++i) {
		for(auto&& x : num)
			std::cin >> x;
		
		std::cout << dfs(0, 0, 0) ? "YES" : "NO" << std::endl;
	}
}

C++: #include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>


using namespace std;

#define FOR(x) for(int i = 0; i < x; i++)

stack<short> x, y;
short a[10], n, j, i;

bool solve(short c, bool judge){
	if(c == 10) return true;
	if(x.top() < a[c]){
		x.push(a[c]);
		if(solve(c + 1, true)) return true;
	}
	if(y.top() < a[c]){
		y.push(a[c]);
		if(solve(c + 1, false)) return true;
	}
	if(judge) x.pop();
	else y.pop();
	return false;
}

int main(){
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		x.push(0);
		y.push(0);
		for(j = 0; j < 10; j++)
			scanf("%d", &a[j]);
		if(solve(0, true)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++: /*
 * Main.cpp
 *
 *  Created on:
 *      Author: KC
 */
/*
 ID: chancha4
 PROG: packrec
 LANG: C++
 */
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <math.h>
#include <vector>
#include <time.h>
#include<stack>
#include <set>
#include <limits>
#include<map>
#include<utility>

using namespace std;

int n = 10;
int e[11];

bool solve(int lv, int topa, int counta, int topb, int countb){
    bool boola;
    bool boolb;
    if(lv == n) return ((counta + countb) == n) ;

    if(topa < e[lv]) boola = solve(lv + 1, e[lv], counta + 1, topb, countb);
    else boola = false;

    if(topb < e[lv]) boolb = solve(lv + 1, topa , counta, e[lv], countb + 1);
    else boolb = false;

    return (boola || boolb);


}
int main(){
    int T;
    scanf("%d", &T);
    for(int i = 0; i < T; i++){
        for(int j = 0; j < 10; j++) scanf("%d", e + j);
        bool res = solve(0, 0, 0, 0, 0);
        if(res) puts("YES");
        else puts("NO");

    }
}

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

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

    while (n--) {
        int left = 0, right = 0;
        bool flag = true;
        for (int i = 10; i--;) {
            int x;
            cin >> x;
            if (x > left && right)
                left = x;
            else if (x > right)
                right = x;
            else {
                flag = false;
                break;
            }
            if (left < right)
                swap(left, right);
        }
        cout << (flag ? "YES" : "NO") << endl;
    }

    return 0;
}