Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var num int
	fmt.Scan(&num)

	for i := 0; i < num; i++ {
		sc.Scan()
		line := sc.Text()

		insertCheck(line)
	}
}

func insertCheck(line string) {
	var B, C []int

	for _, v := range strings.Split(line, " ") {
		ball, _ := strconv.Atoi(v)
		switch {
		case len(B) == 0:
			B = append(B, ball)
		case B[len(B)-1] < ball:
			B = append(B, ball)
		case B[len(B)-1] >= ball:
			switch {
			case len(C) == 0:
				C = append(C, ball)
			case C[len(C)-1] < ball:
				C = append(C, ball)
			case C[len(C)-1] >= ball:
				fmt.Println("NO")
				return
			}
		}
	}
	fmt.Println("YES")
}

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];
		}
		if (dfs(0, 0, 0)) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}

	return 0;
}

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

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

int N;
int ball[10];
bool dfs(int,int,int);

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

bool dfs(int left, int right, int n){
    if(n==9 && (ball[9]>left || ball[9]>right)) return true;
    if(ball[n]>left && dfs(ball[n], right, n+1)) return true;
    if(ball[n]>right && dfs(left, ball[n], n+1)) return true;
    return false;
}

C++:  
 #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
  
 int main()
 {
   int N;
   cin>>N;
   while(N--)
   {
     int arr[10];
     bool flag=true;
     for(int i=0;i<10;i++) cin>>arr[i];
     for(int i=0;i<8;i++)
     {
       if(arr[i]>arr[i+1]&&arr[i+1]>arr[i+2])
       {
         flag=false;
         break;                                      
       }        
     }     
     if(flag) cout<<"YES"<<endl;
     else cout<<"NO"<<endl;
   }
   //while(1);     
   return 0;  
 }

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

using namespace std;

int main(){
  int N;
  cin>>N;
  while(N--){
    int h=0,l=0;
    int i;
    for(i=0;i<10;i++){
      int n;
      cin>>n;
      if(h<n){
	h=n;
      }else if(l<n){
	l=n;
	if(h<l){
	  swap(h,l);
	}
      }else{
	break;
      }
    }
    cout<<((i<10)?"NO":"YES")<<endl;
  }
  return 0;
}

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

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

C++: #include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD
 
int main(){
  int n;
  cin>>n;
  while(n--){
    int left=-1,right=-1;
    bool flag = true;
    REP(i,10){
      int x;
      cin>>x;
      --x;
      if(left>right)swap(left,right);
      if(x>right){
        right = x;
      }else if(x>left){
        left = x;
      }else{
        flag = false;
        break;
      }
    }
    if(flag){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
  }
  return 0;
}

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>
#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 {
				cout << "NO" << endl;
				break;
			}

		}

	if(ca+cb==10)
		cout << "YES" << endl;

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

C++: #include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    while (n--) {
        int left = 0, right = 0;
        int i;
        for (i = 0; i < 10; i++) {
            int ball;
            cin >> ball;
            if (left > ball && right > ball) {
                cout << "NO" << endl;
                break;
            }
            if (left > ball)
                right = ball;
            else if (right > ball)
                left = ball;
            else if (left > right)
                left = ball;
            else
                right = ball;
        }
        if (i == 10)
            cout << "YES" << endl;
    }
    return 0;
}