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() {
	cin.tie(0);
        ios::sync_with_stdio(false);
	
	int n; cin >> n;
	while(n--){
		int balls[10];
		for(int i = 0; i < 10; i++){
			cin >> balls[i];
		}
		
		bool sortable = false;
		for(int i = 0; i < (1 << 10); i++){
			int bit = i;
			bool ok = true;
			
			int top[2] = {0,0}; //top[0]: B, top[1]: C
			for(int j = 0; j < 10; j++){
				if(top[bit & 1] > balls[j]){
					ok = false; break;
				}
				top[bit & 1] = balls[j];
				bit >>= 1;
			}
			
			if(ok) {
				sortable = true; break;
			}
		}
		
		if(sortable) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

C++: #include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
int arr[10];
bool visited[10];

int main() {
    int n;
    scanf("%d", &n);
    for (int t = 0; t < n; t++) {
        for (int i = 0; i < 10; i++) scanf("%d", &arr[i]);
        memset(visited, 0, sizeof(visited));
        stack<int>st;
        st.push(arr[0]); visited[0] = true;
        for (int i = 1; i < 10; i++) {
            if (arr[i] > st.top()) { st.push(arr[i]); visited[i] = true; }
        }
        if (st.size() >= 9) printf("YES\n");
        else {
            int minv, mini;
            for (int i = 0; i < 10; i++) if (!visited[i]) { minv = arr[i], mini = i; break; }
            bool flag = true;
            for (int i = mini+1; i < 10; i++) {
                if (!visited[i] && arr[i] > minv) { minv = arr[i]; }
                else if (!visited[i] && arr[i] < minv) { flag = false; break; }
            }
            (flag) ? printf("YES\n") : printf("NO\n");
        }
    }
    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <stack>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n;
	cin >> n;
	
	rep(i, n)
	{
		queue<int> a;

		rep(i, 10)
		{
			int in;
			cin >> in;
			a.push(in);
		}


		stack<int> b, c;
		b.push(0);
		c.push(0);

		while(!a.empty())
		{
			// ツ湘ュツづ可つつづ個陛サツつェツ妥・ツつォツつ「
			if(b.top() < c.top()) swap(c, b);

			if(b.top() < a.front())
			{
				b.push(a.front());
				a.pop();
			}
			else if(c.top() < a.front())
			{
				c.push(a.front());
				a.pop();
			}
			else break;
		}

		cout << (a.empty() ? "YES" : "NO") << endl;
	}
}

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;
                                s++;
			}
			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 x[15],l[15],r[15];
int kase;
void dfs(int i,int j,int k)//i 是当前下落的球，j是左?的桶的第几个球，k 是右?放入
{
    if(i>10)//如果可以全部下落，肯定?足
    {
        kase=1;
        return;
    }
    if(kase)
    {
        return;
    }
    if(x[i]>l[j-1])//??落在左?
    {
        l[j]=x[i];dfs(i+1,j+1,k);
    }
    if(x[i]>r[k-1])//??落在右?
    {
        r[k]=x[i];dfs(i+1,j,k+1);
    }
}
int main()
{
    int t;
    //freopen("shuju.txt","r",stdin);
    scanf("%d",&t);
    while(t--)
    {
        for(int i=1;i<=10;++i)
        {
            scanf("%d",&x[i]);
        }
        kase=0;
        dfs(1,1,1);
        if(kase)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
    return 0;
}

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

using namespace std;

int main (int argc, char const* argv[])
{
	auto ary = vector<int>();
	while(!feof(stdin))
	{
		int n;
		scanf("%d ",&n);
		if(n == 0)
		{
			cout << ary[ary.size()-1] << endl;
			ary.pop_back();
		}
		else
		{
			ary.push_back(n);
		}
	}
	return 0;
}

C++: #include <iostream>
#include <stack>
#include <cstdio>
using namespace std;
stack<int>a;
stack<int>b;
int main()
{
    int n;
    scanf("%d",&n);
   	while(n--)
   	{
   		int x;
   		int flag = 1;
   		for(int i = 0; i < 10; i ++)
   		{
   			scanf("%d",&x);
   			if( a.empty() )
   				a.push(x);
   			else 
   				if(a.top() < x)
	   			{
	   				if( b.empty() )
	   					a.push(x);
	   				else if(b.top() < x)
	   				{
	   					if(a.top() < b.top())
	   						b.push(x);
	   					else a.push(x);
	   				}
	   				else
	   					a.push(x);
	   			}
	   			else
	   			{
	   				if(b.empty() || b.top() < x)
	   					b.push(x);
	   				else
	   					flag = 0;

   			}
   		}

   	   	if(flag) printf("YES\n");
   		else printf("NO\n");
   	}
    return 0;
}

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

int BALLNUM = 10;

	static int data[10];
class balldata
{
private:
	//static std::vector <int> data;
	//int ballnum;
public:
	balldata(int datanum);
	static void enter();
	static void answer();
	static bool check();
	static bool check(int num,int right,int left);
};




int main()
{
	balldata ball(BALLNUM);

int N;
	std::cin >> N;
	for (int i = 0; i < N; i++)
	{
		ball.enter();
		ball.answer();
	}
}


balldata::balldata(int datanum)
{
	//ballnum = datanum;
	//data.resize(datanum);
}



void balldata::enter()
{
	for (int i = 0; i < 10; i++)
	{
		std::cin >> data[i];
	}
	return;
}

bool balldata::check(int num,int right,int left)
{
	//if (num == data.size())return true;
	if (num == 10)return true;
	if (balldata::check(num + 1, right, data[num])&&left<data[num]){ return true; }
	if (balldata::check(num + 1, data[num], left)&&right<data[num]){ return true; }

	return false;
}
bool check()
{
	return balldata::check(0, 0, 0);
}

void balldata::answer()
{ 
	if (balldata::check(0, 0, 0))
	{
		std::cout << "YES" << std::endl;
	}
	else
	{
		std::cout << "NO" << std::endl;
	}
}