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>

#include <string.h>

int a[10];

int memo[10][10+1][10+1];

int search(int i, int j, int k)
{
  if (memo[i][j][k] >= 0)
    return memo[i][j][k];
  
  if (i == 9)
    return memo[i][j][k] = a[i];

  int r = 0;

  if (a[i] > j)
    r = std::max(search(i + 1, a[i], k), r);
		 
  if (a[i] > k)
    r = std::max(search(i + 1, j, a[i]), r);
  
  return memo[i][j][k] = r;
}

int main(int argc, char** argv)
{
  int N;

  std::cin >> N;

  while (N --) {
    for (int i = 0; i < 10; i ++)
      std::cin >> a[i];

    memset(memo, -1, sizeof(memo));

    std::cout << (search(0, 0, 0) ? "YES" : "NO") << std::endl;
  }
}

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

int main() {
	int n;
	cin >> n;
	for ( int i = 0; i < n; i++ ){
		deque<int>b,c;
		bool endflag = false;
		int dummy;
		cin >> dummy;
		b.push_back( dummy );
		cin >> dummy;
		c.push_back( dummy );
		for ( int j = 0; j < 8; j++ ){
			cin >> dummy;
			if ( !endflag ) {
				if ( c.size() - 1 ) {
					if ( b[b.size() -1] > c[c.size() -1] ) {
						if ( dummy > b[b.size()-1] )	b.push_back( dummy );
						else if ( dummy > c[c.size()-1] )	c.push_back( dummy );
						else {
							cout << "NO" << endl;
							endflag = true;
						}
					} else {
						if ( dummy > c[c.size()-1] )	c.push_back( dummy );
						else if ( dummy > b[b.size()-1] )	b.push_back( dummy );
						else {
							cout << "NO" << endl;
							endflag = true;
						}
					}
				} else {
					if ( dummy > b[b.size()-1] )	b.push_back( dummy );
					else	c.push_back( dummy );
				}
			}
		}
		if( !endflag )	cout << "YES" << endl;
	}
	
	return 0;
}

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

using namespace std;

int main() {
	vector<int> left;
	vector<int> right;
	vector<int> all;

	bool flag = true;

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else
							flag = false;
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}

		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO"<<endl;
		flag = true;
	}

	return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main(){
  int N;
  cin >> N;
  int boll[10];
  stack<int> B,C;
  B.push(0); C.push(0);
  for(int i=0;i<N;i++){
    for(int j=0;j<10;j++) cin >> boll[j];
    for(int j=0;j<10;j++){
        if(boll[j]>B.top()) B.push(boll[j]);
        else if(boll[j]>C.top()) C.push(boll[j]);
        else{
          cout << "NO" << endl;
          break;
        }
        if(j==9) cout << "YES" << endl;
    }
  }
  return 0;
}

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

using namespace std;

int n;
int ball[10]; 
vector<int> l;
vector<int> r;

bool solve() {
    bool res = false;
    for (int i = 0; i < 1024; i++) {
        for (int j = 0; j < 10; j++) {
            if (i & (1 << j)) {
                l.push_back(ball[j]);
            }
            else {
                r.push_back(ball[j]);
            }
        }
        int lLen = l.size();
        int rLen = r.size();
        bool lOK = true;
        bool rOK = true;        
        for (int j = 0; j < lLen - 1; j++) {
            if (l.at(j) > l.at(j + 1)) {
                lOK = false;
                break;
            }
        }
        for (int j = 0; j < rLen - 1; j++) {
            if (r.at(j) > r.at(j + 1)) {
                rOK = false;
                break;
            }
        }
        if (lOK && rOK) {
            res = true;
            break;
        }
        l.clear();
        r.clear();        
    }
    return res;
}

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

C++: // 0033.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define roop(a,t) for(int a=0;a<t;a++) 
int a[10], n;
bool bit(int n,vector<int>left,vector<int>right) {
	if (n == 10) {
		bool left_f = true;
		bool left_r = true;
		roop(i, (int)left.size() - 1) { if (left[i + 1] <= left[i]) { return false; } }
		roop(i, (int)right.size() - 1) { if (right[i + 1] <= right[i]) { return false; } }
		return true;
	}
	if (left.size() > 0 && right.size() > 0) {
		if (left[left.size() - 1] > a[n] && right[right.size() - 1] > a[n]) { return false; }
	}
	vector<int>new_l = left;
	vector<int>new_r = right;
	
	new_l.push_back(a[n]);
	new_r.push_back(a[n]);
	return (bit(n + 1, new_l, right) || bit(n + 1, left, new_r));
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	vector<int>emptynow;
	roop(i, n) {
		roop(j, 10) {
			cin >> a[j];
		}
		if (bit(0, emptynow, emptynow)) { cout << "YES" << endl;}
		else { cout << "NO" << endl; }
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int X,Y;
const int N=10;
int D,ball[N];

bool solve(int i){
	if(i==N)return true;//iがボールの個数に追いついたら終了
	if(X<ball[i]){//入るボールが入ってるボールより大きければ
	X=ball[i];//ボールを入れる
		if(solve(i+1))return true;
	
	}
	if(Y<ball[i]){
	Y=ball[i];
		if(solve(i+1))return true;
	}
	return false;

}
//solve関数　終わる条件→
//solve関数に入った初めの処理→
//solve関数に入って２回目の処理→


int main(){
	cin>>D;
	for(int l=0;l<D;l++){
		for(int i=0;i<N;i++)cin>>ball[i];
		X=ball[0];//一つ目のボールを右に入れておく
			if(solve(1)==true)cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
}	

return 0;
}

C++: #include<stdio.h>
int a[10],b=0,c=0;
bool tube[10];
bool dfs(int i){
    if(i==10) return true;
    bool flagb,flagc;
    if(b>=a[i]&&c>=a[i]) return false;
    if(b<a[i]){
        int oldb=b;
        b=a[i];
        flagb=dfs(i+1);
        b=oldb;
    }
    if(c<a[i]){
        int oldc=c;
        c=a[i];
        flagc=dfs(i+1);
        c=oldc;
    }
    return flagb||flagc;
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            scanf("%d",a+j);
        }
        if(dfs(0)) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}