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 <stack>
using namespace std;

int main(){
	stack<int> b,c;
	int n;
	cin>>n;

	for(int i=0;i<n;i++){
		bool flag=true;
		b.push(0);c.push(0);
		for(int j=0;j<10;j++){
			int t;
			cin>>t;
			if(b.top()<t && c.top()<t){
				if(b.top()>c.top()) b.push(t);
				else c.push(t);
			}
			else if(b.top()<t){
				b.push(t);
			}
			else if(c.top()<t){
				c.push(t);
			}
			else {
				flag=false;
				break;
			}
		}
		cout<<(flag?"YES":"NO")<<endl;

		while(!b.empty()) b.pop();
		while(!c.empty()) c.pop();
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>

int main(){
	int ball[10];
	int cell[2][10]={0};
	int n,i,k,cell_1=1,cell_2=1,flag[1000]={0};
	
	scanf("%d",&n);
	
	for(k=0;k<n;k++){
		for(i=0;i<10;i++)scanf("%d",&ball[i]);
		
		cell[0][0]=0;
		cell[1][0]=0;

		for(i=0;i<10;i++){
			if(cell[0][cell_1-1] < ball[i]){
				cell[0][cell_1]=ball[i];
				cell_1++;
			}
			else if(cell[1][cell_2-1] < ball[i]){
				cell[1][cell_2]=ball[i];
				cell_2++;
			}
			else flag[k]=1;
		}	
	}
	
	cell_1=1;
	cell_2=1;
	
	for(i=0;i<n;i++){
		if(flag[i]==0)printf("YES\n");
		else printf("NO\n");
	}
	
	return 0;
}

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

int main() {
	int n, x, z;
	cin >> n;

	for (int i = 0; i < n; i++) {
		vector< vector<int> > v;
		v.assign(3, { 0 });
		z = 1;
		for (int j = 0; j < 10; j++) {
			cin >> x;
			for (int k = 0; k < z; k++) {
				if (v[k].back() < x) {
					v[k].push_back(x);
					break;
				}

				if (k == z - 1) {
					v[z].push_back(x);
					z++;
					break;
				}
			}

			if (z == 3) {
				x = -1;
				break;
			}
		}

		if (x == -1) {
			cout << "NO";
		}
		else {
			cout << "YES";
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>

int main(){
  int n;
  std::cin >> n;
  while(n--){
    int b = 0;
    int c = 0;
    for(int i=0; i<10; i++){
      int t;
      std::cin >> t;
      if(b < t){
        if(c < t)
          if(b < c) c = t;
          else      b = t;
        else  b = t;
      }
      else if(c < t)  c = t;
      else{
        std::cout << "NO" << std::endl;
        break;
      }
      if(i == 9)  std::cout  << "YES" << std::endl;
    }
  }
}

C++: #include<stdio.h>
#include<malloc.h>

bool decide(int *b){
	for(int i = 0; i < 8; i++)
		for(int j = i+1; j < 9; j++)
			for(int k = j + 1; k < 10; k++)
				if(b[i] > b[j] && b[j] > b[k])return false;
	return true;
}

int main(){
	int N;
	scanf("%d",&N);
	int (*a)[10];
	a = (int (*)[10])malloc(N*10*sizeof(int));
	for(int i = 0; i < N; i++)
		for(int j = 0; j < 10; j++)
			scanf("%d",&a[i][j]);

	for(int k = 0; k < N; k++){
		int *b = a[k];
		if(decide(b) == false)printf("NO\n");
		else printf("YES\n");
		}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<bitset>
#include<queue>
#include<string>
#include<vector>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,n,a) for(int i=n;i>a;i--)
#define mem0(x) memset(x,0,sizeof(x))
#define memff(x) memset(x,INF,sizeof(x))
#define INF 100000000
using namespace std;
typedef pair<int,int> p;
typedef long long LL;
int aa[15];
int main()
{
    //freopen("input.in","r",stdin);
    int n;
    bitset<10> dis;
    cin>>n;
    while(n--)
    {
        for(int i=1;i<=10;i++)
        cin>>aa[i];
        int all=1024;
        while(all>0)
        {
            dis=static_cast<bitset<10> >(all);
            bool flag=true;
            int left=0,right=0;
            for(int i=1;i<=10;i++)
            {
                if(dis[i-1])
                {
                    if(aa[i]>left)
                    {
                         left=aa[i];
                    }
                    else
                    {
                        flag=false;
                        break;
                    }
                }
                else
                {
                    if(aa[i]>right)
                    {
                        right=aa[i];
                    }
                    else
                    {
                        flag=false;
                        break;
                    }
                }
            }
            if(flag)
            {
                break;
            }
            else all--;
        }
        if(all>0)
        cout<<"YES"<<endl;
        else
        cout<<"NO"<<endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int N;
	
	cin >> N;
	
	for(int n = 0;n < N;n++)
	{
		int tubeB = 0, tubeC = 0;
		bool ans = true;
		
		for(int i = 0;i < 10;i++)
		{
			int ball;
			cin >> ball;
			
			if(tubeB < ball) tubeB = ball;
			else if(tubeC < ball) tubeC = ball;
			else ans = false;
		}
		
		if(ans) cout << "YES\n";
		else cout << "NO\n";
	}
	
	return 0;
}

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

int a[10];
bool check;

void dfs(int b, int c, int index) {
  if(index == 10) {
    check = true;
  }
  if(b < a[index]) {
    dfs(a[index], c, index + 1);
  }
  if(c < a[index]) {
    dfs(b, a[index], index + 1);
  }
}

int main(void) {
  int n;
  
  cin >> n;
  
  for(int i = 0; i < n; ++i) {
    check = false;
    for(int i = 0; i < 10; ++i) {
      cin >> a[i];
    }
    dfs(0, 0, 0);
    if(check) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>

using namespace std;

int main(void)
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i=0; i<n; i++) {
        int a[10];
        bool f = 0;
        for(int j=0; j<10; j++) cin >> a[j];
        for(int j=0; j<8; j++) {
            if(a[j] > a[j+1] && a[j+1] > a[j+2]) {
                f = 1;
                break;
            }
        }
        printf("%s\n", f ? "No" : "Yes");

    }

    return 0;
}

C++: #include<cstdio>  
#include<string>  
#include<iostream>  
#include<cstring>  
#include<algorithm>  
using namespace std;  
typedef long long LL;  
const int INF = 0x7FFFFFFF;  
const int maxn = 1e5 + 10;  
   
int a[11],vis[11],flag;  
  
void dfs(int x,int l,int r)  
{  
    int i;  
    if(x==11)return;   
    if(flag)return;  
    if(a[x]>l)dfs(x+1,a[x],r);  
    else if(a[x]>r)dfs(x+1,l,a[x]);  
    else{flag=1;return;}  
}  
  
int main()  
{  
  int T,i,j,k;  
  scanf("%d",&T);  
  while(T--)  
  {  
    flag=0;  
    for(i=1;i<=10;i++)  
      scanf("%d",&a[i]);  
    memset(vis,0,sizeof(vis));  
    dfs(1,0,0);  
    if(flag)printf("NO\n");  
    else printf("YES\n");  
  }  
 return 0;  
}

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

bool res = false;
int a[10];

void dfs(int i, int l, int r) {
    if (i >= 10) {
        res = true;
        return;
    }
    else {
        if (a[i] > l) dfs(i + 1, a[i], r);
        if (a[i] > r) dfs(i + 1, l, a[i]);
    }
}

int main() {
    int T;
    cin >> T;
    for (int i = 0; i < T; ++i) {
        for (int j = 0; j < 10; ++j) cin >> a[j];
        res = false;
        dfs(0, 0, 0);
        cout << (res?"YES":"NO") << endl;
    }
    return 0;
}