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<cstdio>
int ball[11];
int temp[2][11];
bool dfs(int x)
{
	if(x>10)
		return 1;
	if(temp[0][0]==0||temp[0][temp[0][0]]<ball[x])
	{
		temp[0][++temp[0][0]]=ball[x];
		if(dfs(x+1))
			return 1;
	}
	if(temp[1][0]==0||temp[1][temp[1][0]]<ball[x])
	{
		temp[1][++temp[1][0]]=ball[x];
		if(dfs(x+1))
			return 1;
	}
	return 0;
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		for(int i=1;i<=10;i++)
			scanf("%d",ball+i);
		if(dfs(1))
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

C++: #include <cstdio>
int N,A[10];
bool dfs(int x,int B,int C) {
	bool ans=false;
	if(x==10) return true;
	if(B<A[x])ans=dfs(x+1,A[x],C);
	if(C<A[x])ans=ans||dfs(x+1,B,A[x]);
	return ans;
}
int main() {
	scanf("%d",&N);
	for(int i=0;i<N;i++) {
		for(int j=0;j<10;j++)
			scanf("%d",&A[j]);
		printf("%s\n",dfs(0,0,0)?"YES":"NO");
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
using namespace std;
int a[11];
int a1[11];
int pn=0;
int Flag;
void dfs(int i)
{
    if(Flag==1)
        return;

    if(a[i]>a[a1[pn]])
    {
        a1[++pn]=i;
        for(int m=i+1;m<=10;m++)
        {
            dfs(m);
        }
    }
    else
        return;
    int flag=0;
    for(int m=i+1;m<=10;m++)
    {
        if(a[m]>a[i])
            flag=1;
    }
    int flag2;
    if(flag==0||i==10)
    {
        int a2[11];
        int pm=0;
        for(int n=1;n<=10;n++)
        {
            flag2=0;
            for(int m=1;m<=pn;m++)
            {
                if(n==a1[m])
                   flag2=1;
            }
            if(!flag2)
            {
               a2[++pm]=n;
            }
        }
        int flag3=0;
        for(int m=1;m<pm;m++)
        {
            if(a[a2[m]]>a[a2[m+1]])
                flag3=1;
        }
        if(flag3==0)
        {
            Flag=1;
            return;
        }
        else
        {
            pn--;
            return;
        }
    }

}
int main()
{
    int n;
    
    scanf("%d",&n);
    getchar();
    a[0]=-1;
    a1[0]=0;
    for(int i=1;i<=n;i++)
    {
        Flag=0;
        pn=0;
        for(int j=1;j<=10;j++)
        {
            scanf("%d ",&a[j]);
        }
        dfs(1);
        if(Flag==0)
        {
            printf("NO\n");
        }
        else
            printf("YES\n");
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <ctime>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <cstring>
#define MAXN 210
using namespace std;

bool flag;
int arr[MAXN];

void dfs(int x1, int y1, int x2, int y2, int cnt){
    if(x2 < x1 || y2 < y1)
        return;
    if(cnt == 10) {
        flag = true;
        return;
    }
    dfs(x2, y1, arr[cnt], y2, cnt + 1);
    dfs(x1, y2, x2, arr[cnt], cnt + 1);
}

int main(){
    int T;
    cin >> T;
    while(T--){
        for(int i = 0; i < 10; ++i)
            cin >> arr[i];
        flag = false;
        dfs(0, 0, 0, 0, 0);
        if(flag)
            cout << "YES\n";
        else
            cout << "NO\n";
    }
    return 0;
}

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

bool flag;
int a[11], b[11], c[11];
int pa, pb, pc;

void dfs(int x){
	if (pc == 11 ){
		flag = true;
		return ;
	}
	if (flag == true)
		return ;
	
	if (a[pa] < x){
		a[++pa] = x;
		dfs(c[++pc]);
		pa--;
		pc--;
	}
	if (b[pb] < x){
		b[++pb] = x;
		dfs(c[++pc]);
		pb--;
		pc--;
	}
}
		
	
	
	
void solve(){
	flag = false;
	memset(a, 0, sizeof(a));
	memset(b, 0, sizeof(b));	
	pa = pb = pc = 1;
	
	dfs(c[pc]);
	if (flag){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
}
	

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 1; j <= 10; j++){
			cin >> c[j];
		}	

		solve();
	}
	
	return 0;
}

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

long long int gcd(long long int l, long long int r) {
	assert(l > 0 && r > 0);
	if (l > r)return gcd(r, l);
	else {
		const long long int num = r%l;
		if (num) {
			return gcd(l, num);
		}
		else {
			return l;
		}
	}
}
long long int lca(long long int l, long long int r) {
	return l / gcd(l, r)*r;
}
int getans(const int num, const int rest) {
	if (rest) {
		int ans = 0;
		for (int i = 0; i <= 9; ++i) {
			if (num >= i) {
				ans += getans(num - i, rest - 1);
			}
		}
		return ans;
	}
	else {
		return num == 0;
	}
}
int main() {
	int N;
	cin >> N;
	while (N--) {
		vector<int>nums(10);
		bool ok = false;
		for (int i = 0; i < 10; ++i)cin >> nums[i];
		for (int j = 0; j < 1024; ++j) {
			bitset<10>bs(j);
			vector<int>a, b;
			for (int k = 0; k < 10; ++k) {
				if (bs[k])a.emplace_back(nums[k]);
				else b.emplace_back(nums[k]);
			}
			if (is_sorted(a.begin(), a.end()) && is_sorted(b.begin(), b.end()))ok = true;


		}
		if (ok)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

int main()
{
	int n;
	cin>>n;
	while(n--)
	{
		int ball[11];
		bool flag = true;
		for(int i = 1;i <= 10;i++)
		{
			cin>>ball[i];
		}
		int left = -1,right = -1;
		for(int i = 1;i <= 10;i++)
		{
			if(ball[i] > left)
		    {
		    	left = ball[i];
		    	continue;
			}
			if(ball[i] > right)
			{
				right = ball[i];
				continue;
			}
			flag = false;
			break;
		}
		if(flag == true)
		{
			cout<<"YES"<<endl;
		}
		else
		{
			cout<<"NO"<<endl;
		}
	}
}

C++: #include<iostream>
#include <stack> 
using namespace std;
int ar[10];
stack<int> a,b;
bool dfs(int i)
{
	bool aflag = false,bflag = false;
	if(i!=10)
	{
		if(a.empty()||a.top()<ar[i])
		{
			a.push(ar[i]);
			aflag = dfs(i+1);
		}
		if(b.empty()||b.top()<ar[i])
		{
			b.push(ar[i]);
			bflag = dfs(i+1);
		}
		return aflag|bflag;
	}
}
int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		for(int i = 0;i<10;i++)
			cin >> ar[i]; 
		cout<<(dfs(0)?"YES":"NO")<<endl;
	}
 }

C++: #include<stdio.h>

#include<string.h>

int a[13],vis[13],flag;

void dfs(int x,int l,int r)

{

    int i;

    if(x==11)return; 

    if(flag)return ;

    if(a[x]>l)dfs(x+1,a[x],r);

    else  if(a[x]>r)dfs(x+1,l,a[x]);

    else  {flag=1;return;}

  

}

int main()

{

int T,i,j,k;

scanf("%d",&T);

while(T--)

{

flag=0;

for(i=1;i<=10;i++)

scanf("%d",&a[i]);

memset(vis,0,sizeof(vis));

dfs(1,0,0);

if(flag)printf("NO\n");

else printf("YES\n");

}

return 0;

}

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

int main(){
	int a[10],n,i;
	bool can;
	while(cin >> n){
		for(i=0;i<n;i++){
			for(int j = 0;j<10;j++){
				cin >> a[j];
			}
			for(int j = 1;j<=7;j+=2){
				if(a[j] < a[j+2] && a[j-1] < a[j+1]) can = true;
				else {
					can = false;
					break;
				}
			}
			if(can == true) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
	return 0;
}

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

int main() {
	int n;
	int balls[10];
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) { cin >> balls[j]; }
		int b = 0, c = 0; int drop_balls = 0;
		for (int j = 0; j < 10; j++) {
			if (b < balls[j]) { b = balls[j]; drop_balls = j;}
			else if (c < balls[j]) { c = balls[j]; drop_balls = j;}
			else {cout << "NO" << endl;break;}
		}
		if (drop_balls == 9)cout << "YES" << endl;	
	}
}