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<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<string>
#include<cmath>
#define MAXN 10005
using namespace std;
int num[10];
int numl[10],numr[10];
bool charge[10];
int main()
{
   int n;
     scanf("%d",&n);
   while(n--){
    for(int i=0;i<10;i++)
    {
      scanf("%d",&num[i]);
      charge[i]=false;
    }
    int left=num[0],right=0,count1=1;
     charge[0]=true;
    for(int j=1;j<10;j++)
    {
       if(!charge[j]&&num[j]>left)
        {
         left=num[j];
         count1++;
         charge[j]=true;
        }
    }
     for(int j=0;j<10;j++)
    {
       if(!charge[j]&&num[j]>right)
        {
         right=num[j];
         count1++;
         charge[j]=true;
        }
    }
    if(count1!=10) printf("NO\n");
    else printf("YES\n");
   }
    return 0;
}

C++: #include <iostream>

using namespace std;
int main(){
	int N;
	cin >> N;
	for(int i = 0; i < N; ++i){
		//read input data and test it
		bool ok = true;
		int a, b;
		a = b = 0;
		for(int j = 0; j < 10; ++j){
			int c;
			cin >> c;
			if(b > c){
				ok = false;
			}else if(a > c){
				b = c;
			}else{
				a = c;
			}
		}
		if(ok){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
}

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

using namespace std;

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0,tmp;i<n;i++){
		list<int> a,b,c;
		for(int j=0;j<10;a.push_back(tmp),j++)
			scanf("%d",&tmp);
		while(!a.empty()){
			if(a.front()>b.back()||b.empty()){
				b.push_back(a.front());
				a.pop_front();
			}
			else if(a.front()>c.back()||c.empty()){
				c.push_back(a.front());
				a.pop_front();
			}
			else break;
		}
		puts(a.empty()?"YES":"NO");
	}
	return 0;
}

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

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const LL INF = 1e18;


int main(){
	int n;
	cin>>n;
	REP(i,n){
		int num[10];
		REP(j,10)cin>>num[j];
		bool flag;
		REP(j,1023){
			bitset<10>bs(j);
			int n1=0,n2=0;
			flag=true;
			REP(k,10){
				if(bs[k]==0){
					
					if(n1<num[k])n1=num[k];
					else{
						flag=false;
						break;
					}
				}else{
					if(n2<num[k])n2=num[k];
					else{
						flag=false;
						break;
					}
				}
			}
			if(flag)break;
		}
		if(flag){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}
/*

*/

C++: #include <iostream>
using namespace std;
int n, a[10];

bool dfs(int b, int c, int cnt) {
	bool ans = false;
	if (cnt == 10) {
		return true;
	}
	if (b < a[cnt]) {
		ans = dfs(a[cnt], c, cnt + 1);
	}
	if (c < a[cnt]) {
		ans = dfs(b, a[cnt], cnt + 1);
	}
	return ans;
}

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

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  int a[10];
  int b[11];
  int c[11];
  int k;
  int k2;
  int out=0;
  cin>>n;
  b[0]=0;
  c[0]=0;
  for(int i=0;i<n;i++){
    out=0;
    k=0;
    k2=0;
    b[1]=0;
    c[1]=0;
    for(int j=0;j<10;j++){
      cin>>a[j];
      if(b[k]<a[j]){
	b[k+1]=a[j];
	k++;
      }
      else if(c[k2]<a[j]){
	c[k2+1]=a[j];
	k2++;
      }
      else{
	out=1;
      }
    }
    if(out==0) cout << "YES" << endl;    
    else if(out==1) cout << "NO" <<endl;
  }
}

C++: #include <iostream>
#include <vector>
int ball[10];
int left = 0,right = 0;
bool dfs(int de,int left, int right){//??????????????§???????????????
	if(de == 9)return true;
	if(left < ball[de]){
		left = ball[de];
		return dfs(de + 1.left,right);
	}
	if(right < ball[de]){
		right = ball[de];
		return dfs(de + 1,left,right);
	}
	return false;
}

int main(){
	int n;
	std::cin >> n;
	while(n--){
		for(int i = 0; i < 10; ++i){
			std::cin >> ball[i];
		}
		left = 0, right = 0;
		if(dfs(0,0,0))std::cout << "YES" << std::endl;
		else std::cout << "NO" << std::endl;
	}
}

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

int main(){
	stack<int> b,c;
	int n;
	cin>>n;

	for(int i=0;i<n;i++){
		bool flag=true;
		b.push(0);c.push(0);
		for(int j=0;j<10;j++){
			int t;
			cin>>t;
			if(b.top()<t && c.top()<t){
				b.top()>c.top()?b.push(t):c.push(t);
			}
			else if(b.top()<t){
				b.push(t);
			}
			else if(c.top()<t){
				c.push(t);
			}
			else {
				flag=false;
				break;
			}
		}
		cout<<(flag?"YES":"NO")<<endl;

		while(!b.empty()) b.pop();
		while(!c.empty()) c.pop();
	}
	return 0;
}