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

int main() {
    int n; cin >> n;  // ???????????????????????°
    
    while(n--){
        int balls[10] = {0};
        for(int i = 0; i < 10; i++) cin >> balls[I]; // ??????????????????????????\???
        
        bool isYES = true;  // ???10???????????????????????????????????????
        int topB = 0, topC = 0;  // ???B?????????C???????????¨????????????
        for(int i = 0; i < 10; i++){
            if (topB < balls[i]){
                topB = balls[i];
            } else if (topC < balls[i]) {
                topC = balls[i];
            } else {
                isYES = false;
                break;
            }
        }
        cout << (isYES ? "YES" : "NO") << endl;
    }
}

C++: #include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    int a[10];
    for (int j=0;j<10;j++)
    cin >> a[j];
    int left,right; left = a[0];
    right = 0;
    for (int j=1;j<10;j++){
      if(a[j]<left && a[j]<right){
        cout << "NO" << endl; break;
      } else{
        if(j==9){
          cout << "YES" << endl; break;
        } else{
          if(a[j]>left && a[j]<right)
            left = a[j];
          else{
            if(a[j]<left && a[j]>right)
              right = a[j]; else{ if(left<right) right = a[j];
          else left = a[j];
          }
          }
          }
          }
    }
  }
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1000000
using namespace std;
int num[10];
bool check(int pos, int l, int r){
    if(pos >= 10) return true;
    if(l < num[pos]) if(check(pos+1,num[pos],r)) return true;
    if(r < num[pos]) if(check(pos+1,l,num[pos])) return true;
    return false;
}
int main(){
    int n;
    cin >> n;
    rep(i,n){
        rep(j,10) cin >> num[j];
        if(check(0,-1,-1)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #include<cstdio>
const int maxn = 15;
int n,arr[maxn];
int main(){
    scanf("%d",&n);
    while(n--){
        for(int i = 0;i < 10;++i)scanf("%d",&arr[i]);
        int b = 0,c = 0,flag = 1;
        for(int i = 0;i < 10;++i){
            if(b>arr[i]&&c>arr[i]){
                flag = 0;
                break;
            }else if(b<arr[i] && c<arr[i]){
                if(b<c)c = arr[i];
                else b = arr[i];
            }else if(b < arr[i]){
                b = arr[i];
            }else c = arr[i];
        }
        if(flag)printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                                                  it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))

typedef long long ll;
typedef complex<double> point;

// up right down left
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};

const double EPS = 1e-9;
const int days[]     = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

int main(){
    int N;
    cin >> N;
    for(int index_n=0;index_n<N;index_n++){
        vector<int> V(10);
        rep(i,10) cin >> V[i];
        // left,right,next
        queue<pair<pair<int,int>,int> > Q;
        Q.push(mp(mp(V[0],0),1));
        bool ok = false;
        while(!Q.empty()){
            int left = Q.front().first.first;
            int right = Q.front().first.second;
            int next = Q.front().second;
            Q.pop();

            if(next == 10){
                ok = true;
                break;
            }
            if(V[next] > left){
                Q.push(mp(mp(V[next],right),next+1));
            }
            if(V[next] > right){
                Q.push(mp(mp(left,V[next]),next+1));
            }
        }
        if(ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

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

using namespace std;

int n;
int stock[2][11];
int usea[11];

int dfs(int num, int r_num, int l_num) {
	int res = 0;

	if (usea[num] > stock[0][r_num]) {
		if (num == 9)
			return 1;
		stock[0][r_num + 1] = num;
		res = dfs(num + 1, r_num + 1, l_num);
		stock[0][r_num + 1] = -1;
		return res;
	}
	else if (usea[num] > stock[1][l_num]) {
		if (num == 9)
			return 1;
		stock[1][l_num + 1] = num;
		res = dfs(num + 1, r_num, l_num + 1);
		stock[1][l_num + 1] = -1;
		return res;
	}
	else {
		return 0;
	}
}


int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> usea[j];
		}
		stock[0][0] = -1;
		stock[0][1] = usea[0];
		stock[1][0] = -1;
		if (dfs(0, 1, 0)) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
		stock[0][0] = -1;
		stock[0][1] = -1;
		stock[1][0] = -1;
	}

	return 0;
}

C++: /*
P135
AOJ 0033 Ball
http://judge.u-aizu.ac.jp/onlinejudge/index.jsp

*/

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <functional>
#include <string.h>
using namespace std;

int W, H;
char board[110][110];
int a[10];
bool read()
{
    for(int i=0; i<10; ++i)
        scanf("%d", a+i);
}

bool isVisited[110][110];
int step;

void dfs(int x, int y, char c){
    if(x<0 || x>=H || y<0 || y>=W) return;
    if(board[x][y]!=c) return;
    if(isVisited[x][y]) return;
    isVisited[x][y] = true;
    dfs(x+1, y, c);
    dfs(x-1, y, c);
    dfs(x, y+1, c);
    dfs(x, y-1, c);
}

void solve()
{
    int x1=0, x2=0;
    bool ans = true;
    for(int i=0; i<10; ++i)
    {
        if(x1 < x2) swap(x1, x2);
        if(x1 < a[i]) x1 = a[i];
        else if(x2 < a[i]) x2 = a[i];
        else {ans = false; break;}
    }
    if(ans) printf("YES\n");
    else printf("NO");
}


int main()
{
    int T;
    scanf("%d", &T);
    while(T--){
        read();
        solve();
    }
}

C++: #include<iostream>

using namespace std;

int main(void){
	int a[11],fir,n;
	int i;
	cin>>n;
	while(n--){
		int sec = 0;
		for(i=0;i<10;i++){
			cin>>a[i];
		}
		fir=a[0];
		for(i=1;i<10;i++){
			if(fir<a[i])fir=a[i];
			else if(sec<a[i])sec=a[i];
			else break;
		}
		if(i==10)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;

}