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 <vector>
using namespace std;

#define V vector<int> {0}

int main() {
	int n, x, z;
	cin >> n;

	for (int i = 0; i < n; i++) {
		vector< vector<int> > v = { V, V, V };
		z = 1;
		for (int j = 0; j < 10; j++) {
			cin >> x;
			for (int k = 0; k < z; k++) {
				if (v[k].back() < x) {
					v[k].push_back(x);
					break;
				}

				if (k == z - 1) {
					v[z].push_back(x);
					z++;
					break;
				}
			}

			if (z == 3) {
				x = -1;
				break;
			}
		}

		if (x == -1) {
			cout << "NO";
		}
		else {
			cout << "YES";
		}
		cout << endl;
	}
	return 0;
}

C++: using System;
using System.Collections.Generic;
class _0033
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            string[] data = Console.ReadLine().Split();
            Console.WriteLine(Judge(data) ? "YES" : "NO");
        }
    }
    public static bool Judge(string[] data)
    {
        int right = 0;
        int left = 0;
        for (int i = 0; i < data.Length; i++)
        {
            if (right < int.Parse(data[i])) right = int.Parse(data[i]);
            else if (left < int.Parse(data[i])) left = int.Parse(data[i]);
            else return false;
        }
        return true;
    }
}

C++: #include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
//思路：先dfs出一个??数?A，剩下的?成一个数?B，判断B数?是否??即可。
using namespace std;
int t[11];
int v[11];
void dfs(int x,int y)
{
    if(t[x]<t[y]&&y<10)
    {
        v[y]=1;
        dfs(y,y+1);
    }
    else if(t[x]>t[y]&&y<10)
    {
        dfs(x,y+1);
    }
}
int main()
{
    int n,flag=0;
    scanf("%d",&n);
    while(n--)
    {
        memset(t,0,sizeof(t));

        //初始化
        for(int i=0;i<10;i++)
            scanf("%d",&t[i]);
        for(int i=0;i<10;i++)//i<9??
        {
            memset(v,0,sizeof(v));
              v[i]=1;
             dfs(i,i+1);
          int aa=0;flag=0;
             for(int i=0;i<10;i++)
            {
                if(v[i]==0)
                {
                      if(aa>t[i])
                      {
                          flag=1;
                          break;
                      }
                      else
                        aa=t[i];
                }

            }
            if(flag==0)
            {
                cout<<"YES"<<endl;
                break;
            }

        }
            if(flag==1)
                cout<<"NO"<<endl;






    }
}

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

int main(){

	int a, b, n, m, ball[10];
	
	cin >> n;
	
	while(cin >> ball[0]){
		for(int i=1; i<10; i++){
			cin >> ball[i];
		}
		
		a = 0;
		b = 0;
		for(int i=0; i<10; i++){
			if(ball[i] < a && ball[i] < b){
				cout << "NO" << endl;
				break;
			}
			else if(a < ball[i] && ball[i] < b){
				a = ball[i];
			}
			else{
				b = ball[i];
			}
			
			if(i == 9) cout << "YES" << endl;
		}
	}

	return 0;

}

C++: #include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
int a[10];
bool ans;
void dfs(int i,int r,int l){
	if(i==10){
		ans=1;
		return;
	}
	if(a[i]<r&&a[i]<l)return;
	if(ans)return;
	if(r<a[i])dfs(i+1,a[i],l);
	if(l<a[i])dfs(i+1,r,a[i]);

}
int main(){
	int t;
	cin>>t;
	while(t--){
		ans=0;
		for(int i=0;i<10;i++)cin>>a[i];
		dfs(0,0,0);
		if(ans)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

C++: #include<stdio.h>

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

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

C++: #include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <string>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <vector>
#include <cstdlib>
#include <stack>
#include <time.h>
using namespace std;
typedef long long LL;
const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1.0); //M_PI;
const int maxn = 100001;
int a[maxn];
int vis[maxn];

void dfs(int cur , int next , int n)
{
    if(cur >= n || next >= n) return ;
    else{
        if(a[cur] < a[next]){
             vis[next] = 1;
             dfs(next , next + 1 , n);
        }
        else{
            dfs(cur , next + 1 , n);
        }
    }
}

int main()
{
    #ifdef DoubleQ
    freopen("in.txt" , "r" , stdin);
    #endif
    int n;
    cin >> n;
    while(n --){
        for(int i = 0 ; i < n ; i ++){
            cin >> a[i];
        }
        int flag = 0;
        int y = 0;
        for(int i = 0 ; i < n ; i ++){
            memset(vis , 0 , sizeof(vis));
            vis[i] = 1;
            dfs(i , i + 1 , n);
            int tp = -1;
            flag = 0;
            for(int j = 0 ; j < n ; j ++){
                if(vis[j] == 0){
                    if(a[j] >= tp){
                        tp = a[j];
                    }
                    else{
                        flag = 1;
                        break;
                    }
                }
            }
            if(flag == 0)
            {
                y = 1;
                cout << "YES" << endl;
                break;
            }
        }
        if(y == 0) cout << "NO" << endl;
    }
}

C++: //AOJ0033
/*
Sample Input
2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
Output for the Sample Input
YES
NO*/
#include <bits/stdc++.h>
using namespace std;
int a[15],l[15],r[15];
bool wyh;
void dfs(int i,int j, int k){
	if(i>10){
		wyh=true;
		return;
	}
	//if(wyh)return ;
	if(a[i]>l[j-1]){
		l[j]=a[i];
		dfs(i+1,j+1,k);
	}
	if(a[i]>r[k-1]){
		r[k]=a[i];
		dfs(i+1,j,k+1);
	}
	//return false;
}
int main(){
	ios::sync_with_stdio(false);
	int t;
	cin>>t;
	while(t--){
		for(int i=1;i<=10;i++){
			cin>>a[i];
		}
		wyh=false;
		dfs(1,1,1);
		if(wyh)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#include<cstdio>
#define MAXN 2555
#define INF 0x3f3f3f3f
#define v first
#define b second
using namespace std;
stack<int>q;
stack<int>p;
int s[15];
bool flag;
void dfs(int x)
{
   if(x==10)
   {
      flag=true;
      return ;
   }
   if(s[x]>q.top())
   {
      q.push(s[x]);
      dfs(x+1);
      q.pop();
   }
   if(s[x]>p.top())
   {
      p.push(s[x]);
      dfs(x+1);
      p.pop();
   }
   return ;
}
int main()
{
   int t;
   scanf("%d",&t);
   q.push(0);
   p.push(0);
   while(t--)
   {
      flag=false;
      for(int i=0;i<10;i++)
         scanf("%d",&s[i]);
      dfs(0);
      if(flag)
         cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
   }
   return 0;
}