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<cstdio>
#include<iostream>
#define Max 15
using namespace std;
int n;
int number[Max];
bool flag=false;
void DFS(int l1,int r1,int l2,int r2,int cnt); 
int main()
{
	cin>>n;
	while(n--){
		for(int i=0;i<10;i++)
		{
			cin>>number[i];
		}
		flag=0;
		DFS(0,0,0,0,0);
		if(flag)printf("YES\n");
		else printf("NO\n");
	}
}
void DFS(int l1,int r1,int l2,int r2,int cnt)
{
	if(l2<l1||r2<r1) return ;//出现了上面的球反而小 失败 
	if(cnt==10)
	{
		flag=true;
		return;
	}
	DFS(l2,r1,number[cnt],r2,cnt+1);//往左面放第二个球 那个球放在第一个位置上 
	DFS(l1,r2,l2,number[cnt],cnt+1);                //往右面放第二个球 那个球放在第一个位置上
}

C++: #include <iostream>
#include <climits>
#define CAPACITY 9
using namespace std;
int b, c;

bool dfs(int pos, int ary[], bool flag) {
    if(pos < 0) {
        return(false);
    }
    
    flag = dfs(pos - 1, ary, flag);
    
    if(pos == CAPACITY) {
        flag = true;
    }
    if(ary[pos] > b) {
        b = ary[pos];
    } else if(ary[pos] > c) {
        c = ary[pos];
    } else {
        return(false);
    }
    cout << "B = " << b << "C = " << c << endl;
    
    return(flag);
}

int main(void) {
    int num;
    
    cin >> num;
    int ary[10];
    
    for(int r = 0; r < num; r++) {
        for(int c = 0; c < 10; c++) {
            cin >> ary[c];
        }
        b = ary[0];
        c = INT_MIN;
        if(dfs(CAPACITY, ary, true)) {
            cout << "YES";
        } else {
            cout << "NO";
        }
        cout << endl;
    }
    
    return(0);
}

C++: #include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;

#define FOR(x) for(int i = 0; i < x; i++)


stack<short> x, y;
short a[10], n, j, i;

bool solve(short c, bool judge){
	if(c == 10) return true;
	if(x.top() < a[c]){
		x.push(a[c]);
		if(solve(c + 1, true)) return true;
	}
	if(y.top() < a[c]){
		y.push(a[c]);
		if(solve(c + 1, false)) return true;
	}
	if(judge) x.pop();
	else y.pop();
	return false;
}

int main(){
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		x.push(0);
		y.push(0);
		for(j = 0; j < 10; j++)
			scanf("%d", &a[j]);
		if(solve(0, true)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

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

using namespace std;

int main(void){

	int N,B=0,C=0,ball,flag=0;

	cin>>N;

	for(int i=0;i<N;i++){
		B=0,C=0,flag=0;
		for(int j=0;j<10;j++){
			cin>>ball;
			if(ball>B){
				if(ball>C){
					if(C>B) C=ball;
					else B=ball;
				}
				else B=ball;
			}
			else if(ball>C){
				C=ball;
			}
			else flag=1;
		}
		if(flag==0) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}

return 0;

}

C++: #include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define B 0
#define C 1

int main()
{
    int n;
    cin >> n;
    while(n>0)
    {
        int a[10],b[10],c[10];
        rep(i,10)cin >> a[i];
        int bnum=0,cnum=0;
        int t;
        int side = B;
        int res =1;
        b[0] =a[9];
        bnum = 1;
        for(int i = 8;i!=0;i--)
        {
            if(side == B)
            {
                if(b[bnum-1]<a[i])
                {
                    side=C;
                    if(c[cnum-1]<a[i]){res = 0;break;}
                    else{c[cnum]=a[i]; cnum++;}
                }
                else
                {
                    b[bnum] = a[i];
                    bnum++;
                }
            }
            else
            {
                if(c[cnum-1]<a[i]){
                    side = B;
                    if(b[bnum-1]<a[i]){res = 0;break;}
                    else{b[bnum-1] = a[i];bnum++;}
                }
                else
                {
                    c[cnum]=a[i];
                    cnum++;
                }
            }
        }
        if(res==1)cout <<"YES" << endl;
        else cout << "NO" << endl;

        n--;
    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
main(){
  int n,a;
  srand((unsigned)time(NULL));
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>a;
    }
    if(rand()%2==0){
      cout<<"YES"<<endl;
    }
    else{
      cout<<"NO"<<endl;
    }
  }
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int n;

	cin >> n;

	while(n--){
		int input = 0;
		int left = 0, right = 0;
		bool achieve = true;
		REP(i, 10){
			cin >> input;

			if(left > input && right > input){
				//両方入らなかったら
				achieve = false;
				break;
			}
			else{
				//どっちかにしか入らない場合
				if(left > input || right > input){
					//入る方探して入れる
					if(input > left){
						left = input;
					}
					else{
						right = input;
					}
				}
				//どっちにも入る場合
				else{
					//先に入ってる数字が大きい方に入れる
					if(left > right){
						left = input;
					}
					else{
						right = input;
					}
				}
			}
		}
		cout << (achieve ? "YES" : "NO") << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

bool s( int ord[], int const i, int const a = -1, int const b = -1 )
{
    if ( i >= 10 )
        return true;
    
    if ( ord[i] <= a && ord[i] <= b )
        return false;

    if ( ord[i] > a )
        return s( ord, i+1, ord[i], b );

    if ( ord[i] > b )
        return s( ord, i+1, a, ord[i] );

    return true;
}

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

    for( int iii=0; iii<n; ++iii ) {
        int ord[10];
        for( int i=0; i<10; ++i )
            cin >> ord[i];

        cout << ( s( ord, 0 ) ? "YES" : "NO" ) << endl;
    }
}

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

bool checkStorable(const int (&nums)[10]);

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

bool checkStorable(const int (&nums)[10])
{
    int prev_value_left = 0;
    int prev_value_right = 0;
    bool is_storable = true;
    
    for(int i=0; i<10; i++)
    {
        if(nums[i] > prev_value_left)
        {
            prev_value_left = nums[i];
        }
        else
        {
            if(nums[i] > prev_value_right)
            {
                prev_value_right = nums[i];
            }
            else
            {
                is_storable = false;
                break;
            }
        }
    }
    return is_storable;
}