Go: package main

import "fmt"

func isOrdered(a []int) bool {
	if len(a) <= 1 {
		return true
	}
	for i := 0; i+1 < len(a); i++ {
		if a[i] > a[i+1] {
			return false
		}
	}
	return true
}

func main() {
	// ボールの数がせいぜい10個しかないので、全てのボールの落とし方を全探索することが可能
	// Bit全探索を行う。右から見てj番目のビットが立っているときには左側の筒、立っていない時は右側の筒にいれる物とする。
	// 全てのボールを落とし終わった後に、それぞれの筒で昇順に並んでいるか調べることにする。
	var t int
	fmt.Scan(&t)
	ans := make([]bool, t)
	for i := 0; i < t; i++ {
		balls := make([]int, 10)
		for i := range balls {
			fmt.Scan(&balls[i])
		}
		ans[i] = false
		for bits := 0; bits < (1 << uint(10)); bits++ {
			pipeB := make([]int, 0)
			pipeC := make([]int, 0)
			for j := 0; j < 10; j++ {
				if (bits & (1 << uint(j))) != 0 {
					pipeB = append(pipeB, balls[j])
				} else {
					pipeC = append(pipeC, balls[j])
				}
			}
			if isOrdered(pipeB) && isOrdered(pipeC) {
				// fmt.Printf("test case %d - OK pattern - pipeB %v, pipec %v\n", i, pipeB, pipeC)
				ans[i] = true
				break
			}
		}
	}
	for i := range ans {
		if ans[i] {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <set>
#include <stack>
#include <string>
//#include <unordered_map>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define fst first
#define snd second
#define MP make_pair //incase c++11 or later is not available

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;

/*------------------------------------------------------------------------------*/

int main(){
  int P;
  scanf("%d\n", &P);
  VI tp(P);
  set<int> topics;
  REP(i, 0, P){
    scanf("%d ", &tp[i]);
    topics.insert(tp[i]);
  }

  int kinds = topics.size();
  map<int, int> sub;
  int num = 0;
  int lb = 0, ub = 0;
  int res = INF;

  sub[tp[0]]++;
  num++;

  while(lb < P){
    if(kinds > num){
      ub++;
      if(sub[tp[ub]] == 0){
        num++;
      }
      sub[tp[ub]]++;
    }
    if(num == kinds){
      res = min(INF, ub-lb+1);
    }
    if(kinds <= num){
      if(sub[tp[lb]] == 1){
        num--;
      }
      sub[tp[lb]]--;
      lb++;
    }
  }
  printf("%d\n", res);

  return 0;
}

C++: #include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <stdio.h>

using namespace std;

vector<int> ball(10);

int dfs(int cnt, int l, int r){ 
    ++cnt;
    if(cnt == 10) return 1;
    if(ball[cnt] > r){ 
        if(dfs(cnt,l,ball[cnt])) return 1;
    }   
    else if(ball[cnt] > l){ 
        if(dfs(cnt,ball[cnt],r)) return 1;
    }   
    return 0;
}
int main(int argc, void *argv[]){
    int n;
    int tmp;
    
    scanf("%d", &n);
    while(n--){
        for(int i=0;i<10;i++){
            scanf("%d",&tmp);
            ball[i] = tmp;
        }   
        if(dfs(-1,0,0)) printf("YES\n"); else printf("NO\n");
    }   
}

C++: #include<iostream>
using namespace std;
int main(void)
{
    int bo[11],n,B[11],C[11],b1=0,c1=0,A=0,k=0,l=1;
    cin>>n;
    for(int i=0;i<n;i++){
            C[0]=11;k=0;l=1;B[0]=0;b1=0;c1=0;
        for(int j=0;j<10;j++){
            cin>>bo[j];
        }
        for(int j=0;;j++){
                cout<<bo[j]<<" ";
            if(j==0)B[0]=bo[0];
        if(B[l]<bo[j]){
            b1=1;
            B[l]=bo[l];
            l++;
            cout<<"1\n";
        }else if(C[0]==11){
            C[0]=bo[j];
            k++;
            cout<<"2\n";
        }else if(C[k-1]<bo[j]){
            c1=1;
            C[k]=bo[j];
            cout<<"3\n";
        }else{
            B[l+1]=bo[j];
            l++;
            cout<<"4\n";
        }
        if(j==9||(b1==1&&c1==1))break;
    }
    if(b1==1&&c1==1)cout<<"YES\n";
    else cout<<"NO\n";
    for(int j=0;j<10;j++){
        B[j]=0;C[j]=0;
    }

}
}

C++: #include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
 
using namespace std;
 
int s[10]={0};
 
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        for(int i=0;i<10;i++)
            scanf("%d",&s[i]);
        int a=0,b=0;
        bool flag=0;
        for(int i=0;i<10;i++)
        {
            if(s[i]<a&&s[i]<b)
            {
                flag=1;
                break;
            }
            else if(s[i]<a&&s[i]>b)b=s[i];
            else if(s[i]>a&&s[i]<b)a=s[i];
            else
            {
                a=a>b?s[i]:a;
                b=a<b?s[i]:b;
                if(a==b)a=s[i];
            }
        }
        if(flag)printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
int T,a[15],dp[15];
int main(){
	scanf("%d",&T);
	while(T--){
		memset(dp,0,sizeof(dp));
		for(int i=1;i<=10;i++) scanf("%d",&a[i]);
		for(int i=1;i<=10;i++){
			*lower_bound(dp+1,dp+11,a[i],greater<int>()) = a[i];
		}
		if(dp[3] != 0) puts("NO");
		else puts("YES");
	}
	return 0;
}

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

using namespace std;



int main()
{
        int num = 0, tmp_right, tmp_left, ispush = 0, i, j;
        std::array< int, 10 > ar;
        std::vector< int > right, left;
        cin >> num;

        for ( j = 0 ; j < num ; j = j + 1 )
        {
                for ( i = 0 ; i < 10 ; i = i + 1 )
                {
                        cin >> ar[i];
                        ispush = 0;
                        if ( right.size() == 0 )
                        {
                                ispush = 1;
                                right.push_back( ar[i] );
                        }
                        else if ( right.size() != 0 )
                        {
                                tmp_right = right.back();
                                if ( tmp_right < ar[i] )
                                {
                                        right.push_back( ar[i] );
                                        ispush = 1;
                                }
                        }

                        if ( ispush == 0 )
                        {
                                if ( left.size() == 0 )
                                {
                                        ispush = 1;
                                        left.push_back( ar[i] );
                                }
                                else if ( left.size() != 0 )
                                {
                                        tmp_left = left.back();
                                        if ( tmp_left < ar[i] )
                                        {
                                                ispush = 1;
                                                left.push_back( ar[i] );
                                        }
                                }
                        }

                        if ( ispush == 0 )
                        {
                                cout << "NO" << endl;
                                break;
                        }
                        else
                        {
                                ispush = 0;
                        }
//                      cout << i << endl;
                        if ( i == 9 )
                        {
                                cout << "YES" << endl;
                        }


                }
                right.clear();
                left.clear();

        }


        return 0;
}