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

	return 0;
}

C++: #include <iostream>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  cin>>n;
  while(n--){
    int a[10],b[2][11]={0},b1=1,b2=1,k=0;
    r(i,10)cin>>a[i];
    r(i,10){
      if(a[i]>b[1][b1-1])b[1][b1++]=a[i];
      else b[0][b2++]=a[i];
    }cout<<b1<<b2;
    r(i,b1-1){if(b[1][i]>b[1][i+1])k++;}
    r(i,b2-1){if(b[0][i]>b[0][i+1])k++;}
    if(k)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
  }
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main(void) {
	int n = 0;
	vector<string> r;
	scanf("%d",&n);
	for(int i=0; i<n; i++)
	{
		int a[10];
		scanf("%d %d %d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);
		int ca=a[0],cb=0;
		for (int j=1; j<=9; j++)
		{
			if (ca >= cb){
				if (ca < a[j])
				{
					ca = a[j];
				} else if(cb < a[j]) {
					cb = a[j];
				} else {
					r.push_back("NO");
					break;
				}
			} else {
				if (cb < a[j])
				{
					cb = a[j];
				} else if(ca < a[j]) {
					ca = a[j];
				} else {
					r.push_back("NO");
					break;
				}
			}
			if (j==9){r.push_back("YES");break;}
		}
	}
	for (int i=0; i<r.size(); i++)
	{
		cout << r[i] << 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<bits/stdc++.h>
using namespace std;

int a[20];

bool check(int x)
{
	int pre = 0;
	for (int i = 0; i < 10; i++) if (x & (1 << i))
	{
		if (a[i] < pre) return false;
		pre = a[i];
	}
	return true;
}

bool dfs(int i, int x, int pre)
{
	if (i == 10)
	{
		return check(x);
	}
	bool temp = false;
	if (a[i] > pre) temp = dfs(i + 1, x, a[i]);
	return temp || dfs(i + 1, x | (1 << i), pre);
}

int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		for (int i = 0; i < 10; i++) scanf("%d", &a[i]);
		printf("%s\n", dfs(1, 0, a[0]) ? "YES" : "NO");
	}
	return 0;
}

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

using namespace std;

int solve(int* raw,int ri, int le, int t);

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

  //solve???YES??????1NO??????0
int solve(int* raw, int ri, int le, int t){
  if(t==10){return 1;}
  int rid=0,led=0;
  if(ri<raw[t]) rid=solve(raw,raw[t],le, t+1);
  if(le<raw[t]) led=solve(raw,ri,raw[t], t+1);
  if(ri>=raw[t]&&le>=raw[t]) return 0;
  if(rid+led) return 1;
  else return 0;
  }

C++: /*
Á·Ï°Ìâ£ºBall_AOJ 0033
*/
#include <cstdio>
#include <cstring>
using namespace std;

int a[15];
int mark[15];
int count;

void dfs(int x)
{
	mark[x] = 1;
	if(x==9)
	{
		count++;
		return ;
	}
	for(int i=x+1; i<=9; i++)
		if(a[x]<a[i]&&mark[i]==0)
		{
			return dfs(i);
		}
		else
		{
			if(i==9)
				count++;
			continue;
		}
	return ;
}

int main()
{
	int T;
	scanf("%d", &T);
	while(T--)
	{
		count=0;
		bool flag=false;
		memset(mark, 0, sizeof(mark));
		for(int i=0; i<10; i++)
			scanf("%d", &a[i]);
		for(int i=0; i<10; i++)
		{
			if(mark[i]==0)
				dfs(i);
		}
		if(count<=2)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

C++: #include <stdio.h>

int main(void){
    int next;
    int n;
    int atop,btop;
    
    scanf("%d", &n);
    for (int i=0; i<n; i++){
        atop = btop = 0;
        for (int j=0; j<10; j++){
            scanf("%d", &next);
            if (next<atop && next<btop){
                printf("NO\n");
                break;
            }
            else if (next<atop && next>btop) btop = next;
            else if (next>atop && next<btop) atop = next;
            else (atop<btop?btop:atop) = next;
            if (j==9) printf("YES\n");
        }
    }
    
    return 0;
}

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

int main(void){

    vector<int> input(10,0);
    
    int times;
    cin >> times;

    while(times > 0){

        for(int i = 0;i < 10;i++){
            cin >> input[i];
        }
        vector<int> a(10,0);
        vector<int> b(11,0);
        a[0] = input[0];
        int j = 1,k = 0,flag = 1;
        int keep1 = 0,keep2 = 0;
        
        for(int i = 1;i < 10;i++){

            if(a[j-1] < input[i] && b[k] < input[i]){
                a[j++] = input[i];
            }else if(b[k] < input[i]){
                b[k] = input[i];
            }else{
                flag = 0;
                break;
            }
        }

        if(flag){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
        times--;
    }




    return 0;
}