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;
	for (int ni = 0; ni < n; ni++) {
		int a[10], b[11], c[11];
		int pb = 0, pc = 0;
		int ok = 1;
		b[0] = c[0] = 0;
		for (int i = 0; i < 10; i++) {
			cin >> a[i];
			if (a[i] > b[pb]) {
				b[++pb] = a[i];
			}
			else if (a[i] > c[pc]) {
				c[++pc] = a[i];
			}
			else {
				ok = 0;
			}
		}
		if (ok) cout << "YES\n";
		else cout << "NO\n";
	}
}

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

int main() {
	int n1=0,n2=0,temp,num;
	bool flg=true;
	cin>>num;
	while(num--){
		for(int i=0;i<10;i++){
			cin>>temp;
			if(temp>n1) n1=temp;
			else if(temp>n2) n2=temp;
			else flg=false;
		} n1=0;n2=0;
		if(flg) cout<<"YES"<<endl;
		else cout<<"NO"<<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 i=0;i<10;i++){
			cin>>ball[i];
		}
		l=0,r=0;
		flag=false;
	    dfs(i,l,r);
		if(flag){
			cout<<"NO"<<endl;
		}else{
			cout<<"YES"<<endl;
		} 
	}
}

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

using namespace std;

const int MAX_H = 1000;
const int MAX_W = 1000;
char field[MAX_H][MAX_W];

int dy[] = { 0, -1, 0, 1 };
int dx[] = { -1, 0, 1, 0 };

void dfs(int i, int j) {
  char c = field[i][j];
  if (c == 0) return;
  field[i][j] = 0;  // mark as visited

  for (int k = 0; k < 4; k++) {
    int new_i = i + dy[k];
    int new_j = j + dx[k];
    if (field[new_i][new_j] == c) {
      dfs(new_i, new_j);
    }
  }
}

int main() {

  while (1) {
    int W, H;
    cin >> H >> W;
    if (W == 0 && H == 0) {
      break;
    }

    int ans = 0;

    memset(field, 0, MAX_W * MAX_H);
    for (int i = 1; i <= H; i++) {
      for (int j = 1; j <= W; j++) {
        cin >> field[i][j];
      }
    }

    for (int i = 1; i <= H; i++) {
      for (int j = 1; j <= W; j++) {
        if (field[i][j]) {
          dfs(i, j);
          ans++;
        }
      }
    }

    cout << ans << endl;
  }
  
  return 0;
}

C++: #include "iostream"
using namespace std;

int main()
{
	//freopen("m.txt","r",stdin);
	int n,a,b,c,flag;
	cin>>n;
	while(n--)
	{
		a=b=c=-1,flag=1;
		for(int i=0;i<10;i++)
		{
			cin>>a;
			if(flag)
			{
				if(a>b)
					b=a;
				else if(a>c)
					c=a;
				else
					flag=0;
			}
		}
		cout<<(flag?"YES":"NO")<<endl;
	}
	return 0;
}

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

int main(){
	int n;
	std::cin >> n;
	while (n){
		std::vector<int> ball(10);
		for (int i = 0; i < 10; ++i)std::cin >> ball[i];
		int cnt = 0;
		for (int i = 1; i < 10; ++i){
			if (ball[i] < ball[0])cnt++;
		}
		if (cnt < 4)std::cout << "YES" << std::endl;
		else std::cout << "NO" << std::endl;
		n--;
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>

int main(){
	int ball[10];
	int cell[2][10]={0};
	int n,i,k,cell_1=1,cell_2=1,flag=0;
	
	scanf("%d",&n);
	
	for(k=0;k<n;k++){
		for(i=0;i<10;i++)scanf("%d",&ball[i]);
		
		cell[0][0]=ball[0];
		cell[1][0]=ball[1];

		for(i=2;i<10;i++){
			if(cell[0][cell_1-1] < ball[i]){
				cell[0][cell_1]=ball[i];
				cell_1++;
			}
			else if(cell[1][cell_2-1] < ball[i]){
				cell[1][cell_2]=ball[i];
				cell_2++;
			}
			else flag=1;
		}
		
		if(flag==0)printf("YES\n");
		else printf("NO\n");
	
	}
	return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#define rep(i, n) for (int i=0; i<n; ++i)
#define FOR(i, a, b) for (int i=a; i<b; ++i)
#define pb(x) push_back(x)
#define ll long long
#define ul unsigned long long
#define dbg(x) cout  << #x << " : " << (x) << endl
#define out(x) cout << (x)
#define outl(x) cout << (x) << endl
#define int(n); int n; cin >> n;
#define long(n); long long n; cin >> n;
#define dbl(f); double f; cin >> f;
#define s(s); string s; cin >> s;
#define into(a, n) for (int i = 0; i < n; ++i) cin >> a[i]
using namespace std;

const int inf =1500000000;

int a[11],b[11],c[11];

bool dfs(int l,char x) {
  if (l>=11) return true;
  if (x=='b') {
    b[l]=a[l];
    rep(i, l) if(b[l]<b[i]) {b[l]=-1; return false;}
  }
  if (x=='c') {
    c[l]=a[l];
    rep(i, l) if(c[l]<c[i]) {c[l]=-1; return false;}
  }
  bool p= dfs(l+1,'b')||dfs(l+1,'c');
  b[l]=-1;c[l]=-1;
  return p;
}

int main () {
  int(n);
  bool flg;
  rep(i, n) {
    flg=false;
    b[0]=-1;c[0]=-1;
    FOR(i, 1, 11) {
      cin>>a[i];
      b[i]=-1; c[i]=-1;
    }
    flg=dfs(1,'b')||dfs(1,'c');
    outl(flg?"YES":"NO");
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n,l[10],a,b;
  cin>>n;
  while(n){
    a=b=0;
    cin>>l[0]>>l[1]>>l[2]>>l[3]>>l[4]>>l[5]>>l[6]>>l[7]>>l[8]>>l[9];
    for(int i=0;i<10;i++){
      if(!(i%2)){
	if(l[i]>a)a=l[i];
	else
	  break;
      }
      else{
	if(l[i]>b)b=l[i];
        else
	  break;
      }
    }
    (a==l[8]&&b==l[9])?cout<<"YES":cout<<"NO";
    cout<<endl;
    n--;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
using namespace std;
const int maxn = 10001;
int a[maxn];
int vis[maxn];
void dfs(int pre , int cur)
{
    if(cur < 10 && a[pre] < a[cur])
    {
        vis[cur] = 1;
        dfs(cur , cur + 1);
    }
    else if(cur < 10 && a[pre] > a[cur]){
        dfs(pre , cur + 1);
    }
}

int main()
{
    #ifdef DoubleQ
    freopen("in.txt" , "r" , stdin);
    #endif // DoubleQ
    int n;
    cin >> n;
    while(n --){
        for(int i = 0 ; i < 10 ; i ++){
            cin >> a[i];
        }
        bool flag = false;
        for(int i = 0 ; i < 10 ; i ++){
            memset(vis , 0 , sizeof(vis));
            vis[i] = 1;
            dfs(i , i + 1);
            int pre = 0;
            for(int j = 0 ; j < 10 ; j ++){
                if(vis[j] == 0){
                    if(pre > a[j]){
                        flag = true;
                        break;
                    }
                    else pre = a[j];
                }
            }
            if(!flag){
                cout << "YES" << endl;
                break;
            }
        }
        if(flag) cout << "NO" << endl;

    }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int d=0;d<n;d++){
	int a[10]={},b[10]={},c[10]={};
	for(int i=0;i<10;i++){
		cin>>a[i];
	}
	int j=0,k=0;
	for(int i=0;i<10;i++){
		if(b[j]<a[i]){
			b[j+1]=a[i];
			j++;
		}
		else if(c[k]<a[i]){
			c[k+1]=a[i];
			k++;
		}
		else{
			cout<<"NO"<<endl;
			goto age;;
		}
	}
	cout<<"YES"<<endl;
	age:;
}
	return 0;
}