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 <iostream>
#include <stack>
using namespace std;

int main(){
	int n, ball;cin >> n;
	stack<int> r, l;
	while(n--){
		r.push(0);l.push(0);
		bool f = false;
		for(int i = 0;i < 10;i++){
			cin >> ball;
			if(r.top() < ball){
				r.push(ball);
			}else if(l.top() < ball){
				l.push(ball);
			}else{
				f = true;break;
			}
		}
		while(!r.empty())r.pop();
		while(!l.empty())l.pop();
		if(f == false)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

bool judge(int num){
	int i, n, q[2]={0,0};

	for (i=0; i<num; i++) {
		cin >> n;
		if (q[0]<n)
			q[0] = n;
		else if (q[1]<n)
			q[1] = n;
		else
			break;
	}

	if (i==num)
		return true;
	else
		return false;
}

int main(){
	int i, lines;

	cin >> lines;
	for (i=0; i<lines; i++) {
		if (judge(10))
			cout << "NO\n";
		else
			cout << "YES\n";
	}
	return 0;
}

C++: #include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
static const int MAX_N = 10;
int a[MAX_N] = {0};

bool dfs(int a[],vector<int> r,vector<int> l,int i){
	if(i==MAX_N)return true;
	if(r.size()==0 || r[r.size()-1]<a[i]){
		r.push_back(a[i]);
		return dfs(a,r,l,i+1);
	}
	if(l.size()==0 || l[l.size()-1]<a[i]){
		l.push_back(a[i]);
		return dfs(a,r,l,i+1);
	}
	return false;
}


int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){//input
			cin>>a[j];
		}
		vector<int> r;
		vector<int> l;
		if(dfs(a,r,l,0)){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
}

C++: #include <cstdio>
using namespace std;
int main(void)
{
  int a,b,ball[10],n,i,flag;
  scanf("%d",&n);
  while(n-->0)
  {
    a=-1;b=-1;
    for(i=0;i<10;i++)
      scanf("%d",&ball[i]);
    for(i=0;i<10;i++)
    {
      flag=0;
      if(ball[i]>a)
        flag=1;

      if(ball[i]>b)
      {
        if(flag==1)
        {
          if(ball[i]-a<ball[i]-b)
            a=ball[i];
          else
            b=ball[i];
        }else{
          b=ball[i];
        }
        flag=2;
      }
      if(flag==0)
      {
        printf("NO\n");
        break;
      }
      if(flag==1)
        a=ball[i];
    }
    if(flag!=0)
      printf("YES\n");
  }
  return 0;
}

C++: /*
  ID: oodt
  PROG:
  LANG:C++
*/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>

using namespace std;

const int maxx=105;
int n,m,k;
int a[maxx];
int l[maxx],r[maxx];
bool ok;

void dfs(int i,int j, int k)
{
    if(i > 10)
    {
        ok = 1;
        return ;
    }
//    if(ok) 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);
    }
}

int main()
{
#ifdef LOCAL
    freopen("/Users/ecooodt/Desktop/c++ and acm/bai?/2.1/3.txt","r",stdin);
#endif
    int T;
    scanf("%d",&T);
    while(T--)
    {
        memset(r,0,sizeof(r));
        memset(l,0,sizeof(l));
        for(int i = 1; i <= 10; i++)
        {
            scanf("%d",&a[i]);
        }
        ok = 0;
        dfs(1,1,1);
        if(ok){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }

    return 0;
}

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

int main(){
    int n,tmp,a,b;
    bool judge;
    cin >> n;
    while(n--){
        stack <int> st1;
        stack <int> st2;
        judge = true;
        for(int i=0;i<10;i++){
            cin >> tmp;
            if(i == 0){
                st1.push(tmp);
                continue;
            }
            if(st2.empty()){
                if(tmp < st1.top()) st2.push(tmp);
                else st1.push(tmp);
                continue;
            }
            if(tmp - st1.top() > 0 && tmp - st2.top() > 0){
                a = tmp - st1.top();
                b = tmp - st2.top();
                if(a < b) st1.push(tmp);
                else st2.push(tmp);
            }
            else if(tmp - st1.top() > 0) st1.push(tmp);
            else if(tmp - st2.top() > 0) st2.push(tmp);
            else judge = false;
        }
        if(judge) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

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

int N;
int b[10];
bool res;

bool dfs(int n, int b1, int b2) {
    if (n == 9) { 
        if (b[n] > b1 || b[n] > b2) return true;
        return false;
    }
    if ((b[n] > b1 && dfs(n+1,b[n],b2)) ||
        (b[n] > b2 && dfs(n+1,b1,b[n]))) {
        return true;
    } else {
        return false;
    }
}

void solve() {
    res = dfs(1,b[0],-1);
    if (res) {
        cout << "YES\n";
    }
    else {
        cout << "NO\n";
    }
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> b[j];  
        }
        solve();
    }
}

C++: #include <iostream>

using namespace std;

int a[10];

bool dfs(int i, int left, int right) {
  if(i == 10) { return true; }

  bool ans = false;
  if(left < a[i]) {
    ans = dfs(i+1, a[i], right);
  }
  if(right < a[i]) {
    ans = dfs(i+1, left, a[i]);
  }
  return ans;
}

int main() {
  int n;
  scanf("%d", &n);

  for(int i = 0; i < n; i++) {
    for(int j = 0; j < 10; j++) {
      scanf("%d", &a[j]);
    }
    cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
  }
  return 0;
}

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

int main(void){
  int N,temp,flag;
  vector<int> A,B(1,0),C(1,0);
  cin >> N;
  for(int i=0; i<N; ++i){
    while(!A.empty()){
      temp=*A.end();
      if(temp>=*B.end()) B.push_back(temp);
      if(temp>=*C.end()) C.push_back(temp);
      else{
	cout << "NO" << endl;
	flag = 1;
	break;
      }
      A.pop_back();
    }
    if(flag!=1)
      cout << "YES" << endl;
    flag=0;
  }
}

C++: #include<iostream>
using namespace std;
int main(void)
{
int n;
cin>>n;

for(int i=0;i<n;i++)
{
int b[10]={0};
int c[10]={0};
	int a[10]={0};
	for(int j=0;j<10;j++)
	{
	int x;
	cin>>x;
	a[j]=x;
	}
	int k=0;
	for(int j=0;j<10-1;j++)
	{
	
	if(a[j]>a[j+1])
		{
		b[k]=a[j];
		k++;
		}
	else c[j]=a[j];
	}
	for(int i=0;i<10-1;i++)
	{
	if(b[i]>b[i+1] && b[i+1]!=0 || c[i]>c[i+1] && c[i+1]!=0)
	{
	cout<<"NO"<<endl;
	break;
	}
	else 
	{
	cout<<"YES"<<endl;
	break;
	}
	}
}
return 0;
}