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 <bits/stdc++.h>
using namespace std;
int N;
int ar[10];
bool dfs(int i,int L,int R)
{
    if(i==10)
        return true;
    if(ar[i]<L&&ar[i]<R)
        return false;
    if(ar[i]>L)
    {
        if(dfs(i+1,ar[i],R))
            return true;
    }
    else if(dfs(i+1,L,ar[i]))
        return true;
    return false;
}
int main()
{
    scanf("%d",&N);
    while(N--)
    {
        for(int i=0;i<10;i++)
            scanf("%d",&ar[i]);
        if(dfs(0,0,0))
            printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int main(void){
    int a[11],fir,sec=0,i,n;
    cin>>n;
    while (n--) {
    
    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;
}

C++: //Ball
#include<bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin >> n;
  for(int i=0; i<n; i++){
    int j, tmp, b=0, c=0;
    for(j=0; j<10; j++){
      cin>>tmp;
      if(b>=c && b<tmp){b=tmp; continue;}
      else if(b>=c && c<tmp){c=tmp; continue;}
      else if(b<c && c<tmp){c=tmp; continue;}
      else if(b<c && b<tmp){b=tmp; continue;}
      break;
    }
    if(j==10) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,j,j1,j2,a;
	cin>>n;
	for(int i=0;i<n;i++){
		j1=j2=0;a=1;
		for(int k=0;k<10;k++){
			cin>>j;
			if(j1<j&&j2<j){if(j1<j2)j2=j;else j1=j;
			}else if(j1<j)j1=j;
			else if(j2<j)j2=j;
			else a=0;
		}
		if(a==1)cout<<"YES"<<endl;else cout<<"NO"<<endl;
	}
	return 0;
}

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

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

int main() {
	int n;
	int d[10];
	int va[10];
	int vb[10];
	int trush;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> d[i];
		}

		int ca = 0, cb = 0;
		va[0] = d[0];
		ca++;
		if (d[1] > va[0]) {
			va[1] = d[1];
			ca++;
		}

		else {
			vb[0] = d[1];
			cb++;
		}

	for (int j = 2; j < 10; j++) {
			if (d[j] > va[ca-1]) {
				va[ca] = d[j];
				ca++;
			}

			else if (d[j] > vb[cb - 1]) {
				vb[cb] = d[j];
				cb++;
			}


			else if (d[j] < va[ca - 1] && d[j] < vb[cb - 1]) {
				cout << "NO" << endl;
				goto FINLOOP;
			}
			
		}
		cout << "YES" << endl;

		FINLOOP:
		for (int i = 0; i < 10; i++) {
			va[i] = 0;
		}
		for (int i = 0; i < 10; i++) {
			vb[i] = 0;
		}
	}
	return 0;
}

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

using namespace std;

void solve() {
  int a = 0, b = 0, c;
  for (int i = 0; i < 10; ++i) {
    cin >> c;
    if (c < a) {
      cout << "NO" << endl;
      return;
    }
    if (c < b) a = c;
    else b = c;
  }
  cout << "YES" << endl;
}

int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) solve();
}

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

using namespace std;

int main()
{
	int n;
	scanf("%d",&n);
	while(n--){
		int b=-1,c=-1,a,flag=true;
		for(int i=0;i<10;i++){
			scanf("%d",&a);
			if(a>b){
				b=a;
			}else if(a>c){
				c=a;
			}else{
				flag=false;
			}
		}
		printf("%s\n",flag?"YES":"NO");
	}
	return 0;
}

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

int ball[10];

bool DFS(int B,int C,int cnt){
  if(cnt == 10)
    return true;

  bool ans = false;
  if(B < ball[cnt])
    ans = DFS(ball[cnt],C,cnt+1);
  if(C < ball[cnt])
    ans = DFS(B,ball[cnt],cnt+1);

  return ans;
}

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

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

    if(DFS(0,0,0)==true)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

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

int ma[11];
int a[11];int b[11];

bool ch;

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

void dfs(int deep,int aa,int bb)
{
    if(ch)return ;
    if(deep==10)
    {
        ch=true;
        return ;
    }


    if(ma[deep]>a[aa-1])
    {
        a[aa]=ma[deep];
        dfs(deep+1,aa+1,bb);
    }

    if(ch==false&&ma[deep]>b[bb-1])
    {
        b[bb]=ma[deep];
        dfs(deep+1,aa,bb+1);
    }

}


int main()
{
    int f;
    scanf("%d",&f);
    while(f--)
    {
        ch=false;
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for(int i=0;i<10;i++)
            scanf("%d",&ma[i]);
        dfs(0,1,1);
        if(ch)
            printf("YES\n");
        else
            printf("NO\n");
    }


}

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

int main(){

  int n,m;

  cin >> n;

  for(int i=0;i<n;i++){

    int a[100],b[100] = {0},c[100] = {0} ,s = 0,t = 0,x,y,count = 0;

    for(int j=0;j<10;j++){

      cin >> m;

      if(j == 0){
	b[s] = m;
	s++;
      }

      if(j == 1){
	c[t] = m;
	t++;
      }

      if(m > b[s-1] && m < c[t-1]){
	b[s] = m;
	s++;
      }

      else if(m > c[t-1] && m < b[s-1]){
	c[t] = m;
	t++;
      }

      else if(b[s-1] > c[t-1] && m > b[s-1]){
	b[s] = m;
	s++;
      }

      else if(c[t-1] > b[s-1] && m > c[t-1]){
	c[t] = m;
	t++;
      }

      else if(m < c[t-1] && m < b[s-1])	count = 1;
    }

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

  }
}

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cassert>

using namespace std;


bool solve(){
	int a = 0, b = 0;
	int in;
	int ans = 1;
	for(int i=0;i<10;i++){
		cin>> in;
		if(b < in){
			b = in;
		}else if(a < in){
			a = in;
		}else{
			ans = 0;
			break;
		}
		if(a > b) swap(a,b);
	}
	if(ans){
		cout<< "YES"<< endl;
	}else{
		cout<< "NO"<< endl;
	}
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	int n;
	cin>> n;
	for(int i=0;i<n;i++){
		solve();
	}
	return 0;
}