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 <deque>

using namespace std;

bool yes;
int ball[10];

void print(deque <int> a){
	for (int i = 0; i < a.size(); i++){
		cout << a[i] << " ";
	}
	cout << endl;
}

void rec(deque <int> b, deque <int> c, int num)
{
	if (num >= 10){
		yes = true;
		return;
	}

	if (b.back() < ball[num]){
		b.push_back(ball[num]);
		rec(b, c, num + 1);
		b.pop_back();
	}
	if (c.back() < ball[num]){
		c.push_back(ball[num]);
		rec(b, c, num + 1);
		c.pop_back();
	}

	return;
}

int main(void)
{
	int n;
	cin >> n;
	while (n--){
		for (int i = 0; i < 10; i++){
			cin >> ball[i];
		}

		yes = false;
		deque <int> b, c;
		b.push_back(-1);
		c.push_back(-1);
		rec(b, c, 0);
		if (yes){
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

int ball[10];
int B[10];
int C[10];
int D[2] = {0,1};
int j,k;
int ans;

void bfs(int n);
int main()
{
  int n;
  
  cin >> n;

  while(n--){
    ans = 0;
    for(int i = 0;i < 10;i++){
      cin >> ball[i];
    }

    bfs(0);

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

void bfs(int n)
{
  if(n == 10){
    ans = 1;
    return ;
  }
  for(int i = 0;i < 2;i++){
    if(D[i] == 0){
      B[j] = ball[n];
      n++;
      if(j > 0 && B[j] < B[j-1])return ;
      j++;
      bfs(n);
    }
    else{
      C[k] = ball[n];
      n++;
      if(k > 0 && C[k] < C[k-1])return ;
      k++;
      bfs(n);
    }
    return ;
  }
}

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

int main(){
	int k;
	std::cin>>k;
	while(k>0){
		std::vector<int>v(10,0);
		std::stack<int>s;
		std::stack<int>s2;
		int a;
		for(int i=0;i<10;i++){
			std::cin>>v[i];
		}
		s.push(v[0]);
		s2.push(0);
		for(int i=1;i<10;i++){
			int x=s.top(),y=s2.top();
			if(v[i]>x&&v[i]>y){
				if(x>=y)s.push(v[i]);
				else s2.push(v[i]);
			}else if(v[i]>x&&v[i]<=y)s.push(v[i]);
			else if(v[i]<=x&&v[i]>y)s2.push(v[i]);
			else{
				std::cout<<"No"<<std::endl;
				break;
			}if(i==9)std::cout<<"Yes"<<std::endl;
		}
		k--;
	}
	return 0;
}

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

using namespace std;


int n;
int A[10];

bool solve(stack<int> v1, stack<int> v2, int index){
    if (index == 10)
        return true;
    if (v1.empty() || A[index] > v1.top())
        v1.push(A[index]);
    else if(v2.empty() || v2.top() < A[index])
        v2.push(A[index]);
    else
        return false;
    return solve(v1,v2, index + 1);
}

int main(){
    cin>>n;
    stack<int> v1,v2;
    while(n--){
        for (int i = 0; i < 10; ++i) {
            cin>>A[i];
        }
        if (solve(v1,v2,0))
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

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

void get_input(int* arr) {
    for (int i = 0; i < 10; i++) {
        std::cin >> arr[i];
    }
}

char* solve(int* balls) {
    std::stack<int> a, b;
    a.push(0); b.push(0);

    for (int i = 0; i < 10; i++) {
        if (balls[i] > a.top() && balls[i] > b.top()) {
            if (a.top() > b.top()) {
                a.push(balls[i]);
            } else {
                b.push(balls[i]);
            }
        } else if (balls[i] > a.top() && balls[i] < b.top()) {
            a.push(balls[i]);
        } else if (balls[i] < a.top() && balls[i] > b.top()) {
            b.push(balls[i]);
        } else {
            return "NO";
        }
    }
    return "YES";
}

int main(void) {
    int balls[10];
    int n;
    std::cin >> n;

    for (int i = 0; i < n; i++) {
        get_input(balls);
        std::cout << solve(balls) << std::endl;
    }

    return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int ball[10];
int l,r;
bool flag;
void dfs(int num,int l,int r){
	if(num==10) return ;
//	if(flag) return ;
	if(ball[num]>l) dfs(num+1,ball[num],r);
	else if(ball[num]>r) dfs(num+1,l,ball[num]);
	else{
		flag=true;
		return ;
	}
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			cin>>ball[i];
		}
		l=0,r=0;
		flag=false;
	    dfs(i,l,r);
		if(flag){
			cout<<"NO"<<endl;
		}else{
			cout<<"YES"<<endl;
		} 
	}
}

C++: //Aizu 0033
//DinnerHunt
#include <cstdio>
#include <stack>
using namespace std;
int n,k,flag;
int main(){
	scanf("%d",&n);
	while(n--){
		stack<int> stk1,stk2;
		stk1.push(0);
		stk2.push(0);
		flag=1;
		for(int i=0;i<10;i++){			
			scanf("%d",&k);
			int a=k-stk1.top();
			int b=k-stk2.top();
			if (a<0&&b<0) flag=0;
			else if((0<a&&a<b)||(b<0)) stk1.push(k);
			else stk2.push(k);
		}
		if(flag)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++: #include <cstdio>

int B[10];
int C[10];
int ball[10];
int res = 0;

void solve(int i, int bi, int ci) {
  if (i == 10) {
    res = 1;
    return;
  }

  if (bi == 0) {
    B[bi] = ball[i];
    solve(++i, 1, ci);
    i--;
    B[bi] = 0;
  } else {
    if (ball[i] > B[bi-1]) {
      B[bi] = ball[i];
      solve(++i, ++bi, ci);
      B[bi] = 0;
      i--;
      bi--;
    }
  }

  if (ci == 0) {
    C[ci] = ball[i];
    solve(++i, bi, 1);
  } else {
    if (ball[i] > C[ci-1]) {
      C[ci] = ball[i];
      solve(++i, bi, ++ci);
    }
  }

}

int main() {
  int i,j;
  scanf("%d", &i);
  while(i) {
    for (j=0;j<10;j++)
      scanf("%d", &ball[j]);
    solve(0,0,0);
    if (res == 1) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
    i--;
    res = 0;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
  bool f;
  int n, b, c, p;
  cin >> n;
  while (n--) {
    b = c = 0;
    f = true;
    for (int i = 0; i < 10; i++) {
      cin >> p;
      if (p < b && p < c) f = false;
      else if (p > b) b = p;
      else if (p > c) c = p;
      else f = false;
    }
    cout << (f ? "YES" : "NO") << endl;
  }
}

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

string solve(int a, int b, int f) {
	if (f >= 10) return "YES";
	
	int x;
	cin >> x;
	
	if (x > a) return solve(x, b, f + 1);
	if (x > b) return solve(a, x, f + 1);

	return "NO";
}

int main() {
	int n;
	cin >> n;

	for (int i = 0; i++ < n;) {
		cout << solve(0, 0, 0) << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
signed main(void){
	ios::sync_with_stdio(false);
	int T;
	cin>>T;
	for(int t=1;t<=T;t++){
		int a=0,b=0;
		for(int i=1,x;i<=10;i++){
			cin>>x;
			if(x<a&&x<b){
				cout<<"NO"<<endl;
				break;
			}
			else if(x>a&&x>b){
				if(a>b)	a=x;
				else	b=x;
			}
			else if(x<a&&x>b){
				b=x;
			}
			else if(x>a&&x<b){
				a=x;
			}
			if(i==10)
				cout<<"YES"<<endl;
		}
	}
}