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<stdio.h>

int main(){

int n[11]={};
int m[11]={},p[11]={};
int N;
int P=0,M=0;
bool f=true;


scanf("%d",&N);
for(int j=0;j<N;j++)
{
for(int i=0;i<10;i++)
scanf("%d",&n[i]);

for(int i=0;i<10;i++){

	if(M==0){m[M]=n[i];M++;}
	else if(m[M-1]<n[i]&&M>0){M++;m[M]=n[i];}

	else if(P==0){p[P]=n[i];P++;}
	else if(p[P-1]<n[i]&&P>0){P++;p[P]=n[i];}
	
	
else f=false;
}


if(f==true)printf("YES\n");
else if(f==false)printf("NO\n");
//for(int i=0;i<10;i++)
//	printf("%d %d\n",m[i],p[i]);

for(int i=0;i<10;i++)
{p[i]=0;m[i]=0;}

bool f=true;
P=0,M=0;


}
return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
  int n, num, right, left;
  bool flag;

  cin >> n;

  for(int i = 0; i < n; i++){
    right = 0;
    left = 0;
    flag = true;
    for(int j = 0; j < 10; j++){
      cin >> num;

      if(right < num){
        right = num;
      }else{
        left = num;
      }

      if(20 - (right + left) < 10 - (j + 1)) flag = false;
    }

    if(flag){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }

  return 0;
}

C++: #include <cstdio>

int n;

bool solve(int *balls, int i, int depth, int left, int right) {
    if (i == depth)
        return true;
    if (left < balls[i] 
            && solve(balls, i+1, depth, balls[i], right))
        return true;
    if (right < balls[i]
            && solve(balls, i+1, depth, left, balls[i]))
        return true;
    return false;
}

int main() {
    scanf(" %d", &n);
    for (int i = 0; i < n; i++) {
        int balls[10];
        for (int j = 0; j < 10; j++) {
            scanf(" %d", &balls[j]);
        }
        puts(solve(balls, 0, 10, 0, 0) ? "YES" : "NO");
    }
}

C++: #include<cstdio>
int n, a[10];
int b[11] = { }, c[11] =

{
};

bool
dfs (int l, int r)
{
  if (l + r == 9)
    return true;
  if (b[l] < a[l + r])
    {
      b[l + 1] = a[l + r];
      return dfs (l + 1, r);
    }
  else if (c[r] < a[l + r])
    {
      c[r + 1] = a[l + r];
      return dfs (l, r + 1);
    }
  return false;
}

int
main (void)
{
  scanf ("%d", &n);
  for (int i = 0; i < n; i++)
    {
      for (int j = 0; j < 10; j++) {
	scanf ("%d", &a[j]);
        b[j+1] = 0;
        c[j+1] = 0;
      }
      if (dfs (0, 0))
	puts ("YES");
      else
	puts ("NO");
    }
  return 0;
}

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

bool dfs(vector<int>& balls,int i, int left, int right){
    if(i >= balls.size()) return true;

    bool l = true, r = true;
    if(left > balls[i]) l = false;
    if(right > balls[i]) r = false;

    if(!l && !r) return false;

    bool ok = false;

    if(l) ok |= dfs(balls, i+1, balls[i], right);
    if(r) ok |= dfs(balls, i+1, left, balls[i]);

    return ok;
}
int main(){
    int N;
    cin >> N;
    
    for(int i=0;i<N;i++){
        vector<int> balls(10);
        for(int j=0;j<10;j++) cin >> balls[j];

        bool ans = dfs(balls, 0, 0, 0);

        if(ans) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

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

int Balls[10];

bool fork(int balls[], int i, int b, int c) {
    if (i == 10) return true;
    if (b > balls[i] && c > balls[i]) return false;
    if (b < balls[i]) fork(balls, i + 1, balls[i], c);
    if (c < balls[i]) fork(balls, i + 1, b, balls[i]);
}


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

    }
        return 0;
}

C++: #include<iostream>
using namespace std;
int x[10];
int func(int n,int r,int l){
    if(n == 10)return 1;
    if(x[n]>r){
        if(func(n+1,x[n],l))return 1;
    }
    if(x[n]>l){
        if(func(n+1,r,x[n]))return 1;
    }
    return 0;
}
int main(){
	int k;
	cin>>k;
	while(k-->0){
		for(int i=0;i<10;i++)
			cin>>x[i];
		if(func(0,0,0))
			cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
	int n;
	int data[10];
	int a[11],b[11];
	int ai,bi;
	int k;
	int flag;
	cin>>n;
	while(n--){
		for(int i=0;i<10;i++) cin>>data[i];
		a[0]=b[0]=0;
		ai=bi=0;
		flag=0;
		for(k=0;k<10;k++){
			if(a[ai]<data[k]){
				a[ai+1]=data[k];
				ai++;
			}
			else if(b[bi]<data[k]){
				b[bi+1]=data[k];
				bi++;
			}
			if(data[k]<a[ai] && b[bi]>data[k])
				flag=1;
		}
		if(flag==1) cout<<"NO"<<endl;
		else cout<<"YES"<<endl;
	}
	return 0;
}

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

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		bool flag = false;
		int prev;
		int in[10];
		int used[10];
		for (int j = 0; j < 10; j++)
		{
			cin >> in[i];
		}
		prev = in[0];
		vector<int> B;
		vector<int> C;
		for (int j = 0; j < 10; j++)
		{
			if (prev > in[j])
			{
				C.push_back(in[j]);
				used[j] = false;
				continue;
			}
			else
			{
				prev = in[j];
				B.push_back(in[j]);
				used[j] = true;
			}
		}
		prev = C[0];
		for (int j = 0; j < C.size(); j++)
		{
			if (prev > C[j])
			{
				flag = true;
			}
			else
			{
				prev = C[j];
			}
		}
		if (flag) cout << "NO" << endl;
		else cout << "YES" << endl;
	}
	return 0;
}

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

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

		int B, C = 0;
		B = data[0];
		bool flag = 0;

		for(int i = 1; i < 10; i++){
			if(B+1 != data[i]){
				if(C == 0){
					C = data[i];
				}else if(C+1 != data[i]){
					cout << "NO" << endl;
					break;
				}else{
					C = data[i];
				}
			}else{
				B = data[i];
			}
			if(i == 9){cout << "YES" << endl;}
		}
	}

}

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

int main(){
    int n, tmp;
    vector<int> vb, vc, vb_, vc_;
    
    cin >> n;
    
    for(int i = 0;i < n;i++){
        vb.clear();
        vc.clear();
        vb_.clear();
        vc_.clear();
        
        for(int j  = 0;j < 10;j++){
            cin >> tmp;
            
            if(j%2 != 0){
                vb.push_back(tmp);
            }else{
                vc.push_back(tmp);
            }
        }
        
        vb_ = vb;
        vc_ = vc;
        
        sort(vb.begin(), vb.end());
        sort(vc.begin(), vc.end());
        
        if(vb_ == vb && vc_ == vc){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
        
    }
    
    return 0;
}

C++: #include<iostream>

int r=0,l=0;

int main(){
	int n;
	std::cin>>n;
	for(int i=0;i<n;++i){
		bool f=true;
		for(int j=0;j<10;++j){
			int a;
			std::cin>>a;
			if(r<a&&l<a){
				if(r<=l)l=a;
				else r=a;
			}else if(r<a)r=a;
			else if(l<a)l=a;
			else f=false;
			//std::cout<<r<<" "<<l<<" "<<f<<std::endl;
		}
		if(f)std::cout<<"OK"<<std::endl;
		else std::cout<<"NO"<<std::endl;
		r=0,l=0;
	}
	return 0;
}