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

int main() {
	int n, x, z;
	cin >> n;

	for (int i = 0; i < n; i++) {
		vector< vector<int> > v = { vector<int>{0} };
		for (int j = 0; j < 10; j++) {
			cin >> x;
			z = v.size();
			for (int k = 0; k < z; k++) {
				if (v[k].back() < x) {
					v[k].push_back(x);
					break;
				}

				if (k == z - 1) {
					v.push_back(vector<int> { x });
					break;
				}
			}

			if (v.size() == 3) {
				x = -1;
				break;
			}
		}

		if (x == -1) {
			cout << "NO";
		}
		else {
			cout << "YES";
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>

int main(){
  int n;
  std::cin >> n;
  while(n--){
    int b = 0;
    int c = 0;
    for(int i=0; i<10; i++){
      int t;
      std::cin >> t;
      if(b < t)       b = t;
      else if(c < t)  c = t;
      else{
        std::cout << "NO" << std::endl;
        break;
      }
      if(i == 9)  std::cout  << "YES" << std::endl;
    }
  }
}

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

int ball[1001][10];
//int end[2][10];

bool dfs(int i, int j, int left_max, int right_max) {
	if (j == 10) return true;
	
	if (left_max < ball[i][j]) return dfs(i, j + 1, ball[i][j], right_max);
	else if (right_max < ball[i][j]) return dfs(i, j + 1, left_max, ball[i][j]);
	
	return false;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i ++) {
		for (int j = 0; j < 10; j ++) {
			cin >> ball[i][j];
		}
		dfs(i, 0, 0, 0) ? cout << "YES" <<  endl : cout << "NO" << endl;
	}
	
	return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
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();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

bool dfs(vi &a, int pos,int l,int r){
	if(pos==10){
		return true;
	}
	REP(i,2){
		if(i==0&&a[pos]>l&&dfs(a,pos+1,a[pos],r)){
			return true;
		}
		if(i==1&&a[pos]>r&&dfs(a,pos+1,l,a[pos])){
			return true;
		}
	}
	return false;
}

int main(){
	int n;
	cin>>n;
	REP(i,n){
		vi a(10);
		REP(i,10){
			cin>>a[i];
		}
		cout<<(dfs(a,0,0,0)?"YES":"NO")<<endl;
	}
}

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

int a[10005];
int dp[10005];
int n;

///flag == 0求最长不上升子序列的长度
///flag == 1求最长不上升子序列的最少数目
///（即最长上升子序列的长度）
void slove(bool flag)
{
    int ans = 0;
    for(int i = 0; i < n; ++i)
    {
        dp[i] = 1;
        for(int j = 0; j < i; ++j)
        {
            if(!flag && a[j] < a[i])
                dp[i] = max(dp[i], dp[j] + 1);
            if(flag && a[j] >= a[i])
                dp[i] = max(dp[i], dp[j] + 1);
        }
        ans = max(ans, dp[i]);
    }
    if(ans <= 2)
        cout << "YES" << '\n';
    else
        cout << "NO" << '\n';
}

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        n = 10;
        for(int i = 0; i < 10; ++i)
            cin >> a[i];
        slove(1);
    }
    return 0;
}

C++: #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <ostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define INF 1000000000
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define rev(i,a,b) for (int i=(a)-1;i>=b;i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef queue<int> qi;
typedef queue< pair<int, int> > qpii;
typedef vector<int> vi;
typedef vector<int, int> vii;
typedef vector<string> vs;
typedef vector< pair<int, int> > vpii;
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

int n[10];
int h, w;

bool dfs(int b, int c, int cnt) {
  if(cnt == 10) return true;
  if(n[cnt] > n[b]) {
    if(dfs(cnt, c, cnt+1)) return true;
  }
  if(c == -1 || n[cnt] > n[c]) {
    if(dfs(b, cnt, cnt+1)) return true;
  }
  return false;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

  int num;
  cin >> num;
  rep(i,0,num) {
    rep(j,0,10) cin >> n[j];

    if(dfs(0, -1, 1)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }

	return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> d(10);
	int b, c;

	for (int i = 0; i<N; i++){
		for (int k = 0; k < 10; k++)
			cin >> d.at(k);

		b = d.at(0);
		c = 0;
		for (int k = 1; k < 10; k++){
			if (b < c){
				if (b > d.at(k)){
					cout << "NO" << endl;
					break;
				}
				else{
					if (c < d.at(k))
						c = d.at(k);
					else
						b = d.at(k);
				}
			}

			else{
				if (c > d.at(k)){
					cout << "NO" << endl;
					break;
				}
				else{
					if (b < d.at(k))
						b = d.at(k);
					else
						c = d.at(k);
				}
			}
			if (k == 9)
				cout << "YES" << endl;
		}
	}
}

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

int l=0, r=0;
bool flag=true;

void solve(int N) {
	int a = 0;
	while (N > 0) {
		for (int i = 0; i < 10; i++) {
			cin >> a;
			if (a > l)
				l = a;
			else if (a > r)
				r = a;
			else 
				flag = false;
		}
		if (flag == true)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
		flag = true;
		l = 0;
		r = 0;
		N--;
	}
}
int main() {
	int n = 0;
	cin >> n;
	solve(n);
	return 0;
}

C++: #include <iostream>

using namespace std;

int main( void )
{
	int n, input[10], stA[10], stB[10];
	cin >> n;
	while(n--) {
		for(int i=0; i < 10; ++i) {
			stA[i] = stB[i] = 0;
			cin >> input[i];
		}
		int idxI, idxA, idxB;
		idxI = 2; idxA = idxB = 0;
		stA[0] = input[0]; stB[0] = input[1];
		bool hit = true;
		while(10 > idxI && hit) {
			int tmp = input[idxI];
			if(stB[idxB] < stA[idxA]) { // A
				if(stA[idxA] < tmp) stA[++idxA] = tmp;
				else if(stB[idxB] < tmp) stB[++idxB] = tmp;
				else hit = false;
			}
			else {	// B
				if(stB[idxB] < tmp) stB[++idxB] = tmp;
				else if(stA[idxA] < tmp) stB[++idxA] = tmp;
				else hit = false;
			}
			++idxI;
		}
		if(idxI == 10 && hit)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}