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    <stack>

using namespace std;

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

    for(int att = 0; att < n; att++) {
        int balls[10];      // ボールのリスト
        stack<int> r, l;    // 筒の状態をプールするstack
        bool isOK = true;   // 分配可能フラグ
        
        for(auto b : balls) {
            cin >> b;
            
            if(!isOK) continue;
            if      (r.empty() || r.top() < b)  { r.push(b); }
            else if (l.empty() || l.top() < b)  { l.push(b); }
            else                                { isOK = !isOK; }
        }
        cout << (isOK ? "YES" : "NO") << endl;
    }
    
    return 0;
}

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

int a[10];
bool flag;

void dfs(int n, int l, int r){
	if(n == 10){
		flag = true;
		return;
	}

	if(a[n] > l){
		dfs(n+1, a[n], r);
	}
	if(a[n] > r){
		dfs(n+1, l, a[n]);
	}

	return;
}

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

	return 0;
}

C++: #include <iostream>
using namespace std;
int main (){
       int N,a[20]={0},b[20]={0},t;
       cin>>N;
       for(int j=0;j<N;j++){
       int ac=0,bc=0;
       for(int i=0;i<10;i++){
              cin>>t;
              if(a[ac]<t){
                 a[ac+1]=t;
                 ac++;
               }
               else if(b[bc]<t){
                  b[bc+1]=t;
                  bc++;
                }
       
                else break;
           
           }
           if(ac+bc==10){
                 cout<<"YES"<<endl;
            }
           else cout<<"NO"<<endl;
           }
return 0;
}

C++: #include <stdio.h>
#include <stdbool.h>
int balls[10];
int left[10],right[10],l=0,r=0,det;
void solve();
void dfs(int depth);
bool check();
int main(void){
	int times;
	scanf("%d",&times);
	for(int i=0;i<times;i++){
		for(int j=0;j<10;j++)
			scanf("%d",&balls[j]);
		solve();
	}
	return 0; 
}

void solve(){
	det=0;
	dfs(0);
	if(det)	puts("YES");
	else	puts("NO");
}

void dfs(int depth){
//	if(det)	return;
	if(depth==9){
		if(check())	det=1;
		return;
	}
	left[l++]=balls[depth++];
	dfs(depth);
	l--;depth--;
	right[r++]=balls[depth++];
	dfs(depth);
	r--;depth--;
}

bool check(){
	bool m=1,n=1;
	for(int i=0;i<l-1;i++)
		if(left[i]>left[i+1]){
			m=0;
			break;
		}
	for(int i=0;i<r-1;i++)
		if(right[i]>right[i+1]){
			n=0;
			break;
		}
	return m&&n;
}

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

using namespace std;

int B[10];

bool solve() {
    vector<int> a, b;
    a.push_back(0);
    b.push_back(0);
    for (int i = 0; i < 10; i++) {
        if (a.back() < B[i]) {
            a.push_back(B[i]);
        } else if (b.back() < B[i]) {
            b.push_back(B[i]);
        } else {
            return false;
        }
    }
    return true;
}

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> B[j];
        }
        cout << (solve() ? "YES" : "NO") << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <array>
#include <stack>

int main()
{
	std::vector<int> a;
	std::vector<int> b;

	int n = 0;
	std::cin >> n;

	while (n--)
	{
		bool is_failure = false;

		int datas[10] = { 0 };
		std::cin >> datas[0] >> datas[1] >> datas[2] >> datas[3] >> datas[4] >> datas[5] >> datas[6] >> datas[7] >> datas[8] >> datas[9];

		std::stack<int> stack_a{};
		std::stack<int> stack_b{};

		for (auto data : datas)
		{
			if (stack_a.empty())
			{
				stack_a.push(data);
				continue;
			}

			if (stack_a.top() < data)
			{
				stack_a.push(data);
				continue;
			}

			if (stack_b.empty())
			{
				stack_b.push(data);
				continue;
			}

			if (stack_b.top() < data)
			{
				stack_b.push(data);
				continue;
			}

			is_failure = true;
			break;
		}

		if (false == is_failure)
		{
			std::cout << "YES" << std::endl;
		}
		else
		{
			std::cout << "NO" << std::endl;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include "stdio.h"
#include <string>
int si[10];
bool stack(int left, int right, int i){
	if (i == 9){
		if (left < si[i] || right < si[i]){
			return true;
		}
		else return false;
	}
	else if (left <= si[i]){
		return stack(si[i], right, i + 1);
	}
	else if (right <= si[i]){
		return stack(left, si[i], i + 1);
	}
	else return false;
}
int main(){
	int n;
	std::cin >> n;
	for (int e = 0; e<n; e++){
		for (int ai = 0; ai<10; ai++){
			std::cin >> si[ai];
		}
		if (stack(0, 0, 0) == true){
			std::cout << "YES\n";
		}
		else {
			std::cout << "NO\n";
		}
	}
}

C++: #include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int T;
int t[10];

bool solve(){
  int left=0,right=0;
  rep(i,10){
    if(t[i] < left && t[i] < right) return false;
    if(t[i] > left){
      if(t[i] > right && left < right){
        right = t[i];
      }
      else{
        left = t[i];
      }
    }
    else{
      right = t[i];
    }
  }
  return true;
}

int main(){
  cin>>T;
  while(T--){
    rep(i,10){
      cin>>t[i];
    }
    cout<<(solve() ? "YES" : "NO")<<endl;
  }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n,a,b,c;
	bool f;
	cin>>n;
	for(int i=0;i<n;i++){
		f=true;b=0;c=0;
		for(int j=0;j<10;j++){
			cin>>a;
			if(b>a&&c>a){
				f=false;
				break;
			}else if(b<a && c<a){
				if(b>=c)b=a;
				else c=a;
			}else if(b<a){
				b=a;
			}else if(c<a){
				c=a;
			}
		}
		if(f)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

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

using namespace std;

int main(){

	int n;
	cin>>n;

	int B=0,C=0;
	for(int i = 0; i < n; i++){
		bool f=false;
		vector<int> numList;
		for(int j = 0; j < 10; j++){
			int t;
			cin>>t;
			numList.push_back(t);
		}

		for(int j = 0; j < 10; j++){
			int num=numList[j];
			if(num>B&&num>C){
				if(num-B>num-C){
					C=num;
				}
				else
					B=num;
			}
			else if(num>B){
				B=num;
			}
			else if(num>C)
				C=num;
			else{
				f=true;
				cout<<"NO"<<endl;
				break;
			}
		}
		if(!f)
			cout<<"YES"<<endl;
	}

	return 0;
}

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

int main()
{
    int N;
    scanf("%d",&N);
    for(int i=0;i<N;++N) {
        int ball[10],index=0;
        for(int i=0;i<10;++i) {
            scanf("%d",&ball[i]);
        }
        while(index+2 <= 9) {
            if(ball[index] < ball[index+1]) {
                ++index;
                continue;
            } else if (ball[index] < ball[index+2]) {
                ++index;
                continue;
            } else {
                puts("NO");
                return -1;
            }
        }
        puts("YES");
        return 0;
    }
}