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() {
	int A[10];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++)
			cin >> A[j];
		stack<int> B, C;
		string ans = "YES";
		for (int j = 0; j < 10; j++) {
			int k = A[j];
			if (B.empty() == true && C.empty() == true)
				B.push(k);
			else if (B.empty() != true && C.empty() == true) {
				if (B.top() < k)
					B.push(k);
				else
					C.push(k);
			}
			else {
				if (B.top() > k && C.top() > k) {
//					cout << k << " " << B.top() << " " << C.top() << endl;
					ans = "NO";
					break;
				}
				else if (B.top() > C.top())
					B.push(k);
				else
					C.push(k);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
bool canbe = false;
string inp;

void dfs(int b, int c, int depth){
    if (depth >= 9){ canbe = true; return; }
    if (inp[depth] - '0' < b && inp[depth] - '0' < c) return;

    if (inp[depth] - '0' > b) dfs(inp[depth] - '0', c, depth+1);
    if (inp[depth] - '0' > c) dfs(b, inp[depth] - '0', depth+1);
}


int n;
int main(){
    cin >> n;
    for (int i = 0; i < n; i++){
	canbe = false;
	inp = "";
	string g;
	for (int j = 0; j < 10; j++){
	    cin >> g;
	    inp += g;	    
	}
	dfs(0, 0, 0);

	if (canbe) cout << "YES" << endl;
	else cout << "NO" << endl;
    }
}

C++: #include <stdio.h>

int
main(void)
{
	char line[80];

	int b[10];

	int n;
	
	if (fgets(line, sizeof line, stdin) == NULL) {
		return 0;
	}
	if (sscanf(line, "%d", &n) != 1) {
		return 0;
	}

	while (n--) {
		fgets(line, sizeof line, stdin);
		sscanf(line, "%d %d %d %d %d %d %d %d %d %d",
			   &(b[0]), &(b[1]), &(b[2]), &(b[3]), &(b[4]), &(b[5]),
			   &(b[6]), &(b[7]), &(b[7]), &(b[9]));

		bool f = true;
		int s0 = 0;
		int s1 = 0;
		for (int t : b) {
			if (t > s0 && t > s1) {
				if (t - s0 <= t - s1) {
					s0 = t;
				} else {
					s1 = t;
				}
			} else 	if (t > s0) {
				s0 = t;
			} else 	if (t > s1) {
				s1 = t;
			} else {
				f = false;
				break;
			}
		}
		printf("%s\n", (f ? "YES" : "NO"));
	}

	return 0;
}

C++: #include<iostream>
main(){
int n,i,A,B,C,f;
for(std::cin>>n;n-->0;puts(f?"NO":"YES"))
 for(B=C=f=i=0;i++<10;){
  std::cin>>A;
  if(B<A)B=A;else C<A?C=A:f=1;
 }
}

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

int B[11]={0};
int C[11]={0};

bool DFS(int *a,int i=0,int b=1,int c=1)
{
	bool judge=true;

	if(i==10)
		return judge;

	judge=false;

	if(B[b-1]<a[i]){
		B[b]=a[i];
		judge=DFS(a,i+1,b+1,c);
		
	}
	if(C[c-1]<a[i]){
		C[c]=a[i];
		judge=DFS(a,i+1,b,c+1);
		
	}

	return judge;
}        

int main()
{
        int N;
	int i=0;
        cin>>N;

		while(i<N){
			int A[10]={0};
			for(int i=0;i<10;i++)
				cin>>A[i];

            ??????????????????if(DFS(A)==true)
                ????????????????????????cout<<"YES"<<endl;
            ??????????????????else
		????????????????????????cout<<"NO"<<endl;

	????????????????????????i++;
        }
                
	
        return 0;
}

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

using namespace std;

int main(){
  int f;
  int n;
  int in,b,c;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    f=b=c=0;
    for(int j=0;j<10;j++){
      scanf("%d",&in);
      if(!f){
	if(in<=min(b,c)){
	  f=1;
	}
	if((b>=c && b<in)||(b<c && c>in))b=in;
	else c=in;
      }
    }
    if(f)printf("NO\n");
    else printf("YES\n");
  }
}

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

int arr[10];
bool flag;

void dfs(int num, int l, int r) {
  if(num==10) {
    flag = true;
    return;
  }

  if(arr[num] > l) dfs(num+1, arr[num], r);
  if(arr[num] > r) dfs(num+1, l, arr[num]);
  return;
}

int main() {
  int n;
  scanf("%d",&n);
  for(int i=0; i<n; ++i) {
    for(int j=0; j<10; ++j)
      scanf("%d", &arr[j]);

    flag = false;
    dfs(0,0,0);
    if(flag)
      printf("YES\n");
    else
      printf("NO\n");
  }
}

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

using namespace std;

bool yes;
int ball[10];

void print(deque <int> a){
	for (int i = 0; i < a.size(); i++){
		cout << a[i] << " ";
	}
	cout << endl;
}

void rec(deque <int> b, deque <int> c, int num)
{
	if (num >= 10){
		yes = true;
		return;
	}

	if (b.back() < ball[num]){
		b.push_back(ball[num]);
		rec(b, c, num + 1);
		b.pop_back();
	}
	if (c.back() < ball[num]){
		c.push_back(ball[num]);
		rec(b, c, num + 1);
		c.pop_back();
	}

	return;
}

int main(void)
{
	int n;
	cin >> n;
	while (n--){
		for (int i = 0; i < 10; i++){
			cin >> ball[i];
		}

		yes = false;
		deque <int> b, c;
		b.push_back(-1);
		c.push_back(-1);
		rec(b, c, 0);
		if (yes){
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

int ball[10];
int B[10];
int C[10];
int D[2] = {0,1};
int j,k;
int ans;

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

  while(n--){
    ans = 0;
    for(int i = 0;i < 10;i++){
      cin >> ball[i];
    }

    bfs(0);

    if(ans == 1)cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

void bfs(int n)
{
  if(n == 10){
    ans = 1;
    return ;
  }
  for(int i = 0;i < 2;i++){
    if(D[i] == 0){
      B[j] = ball[n];
      n++;
      if(j > 0 && B[j] < B[j-1])return ;
      j++;
      bfs(n);
    }
    else{
      C[k] = ball[n];
      n++;
      if(k > 0 && C[k] < C[k-1])return ;
      k++;
      bfs(n);
    }
    return ;
  }
}

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

int main(){
	int k;
	std::cin>>k;
	while(k>0){
		std::vector<int>v(10,0);
		std::stack<int>s;
		std::stack<int>s2;
		int a;
		for(int i=0;i<10;i++){
			std::cin>>v[i];
		}
		s.push(v[0]);
		s2.push(0);
		for(int i=1;i<10;i++){
			int x=s.top(),y=s2.top();
			if(v[i]>x&&v[i]>y){
				if(x>=y)s.push(v[i]);
				else s2.push(v[i]);
			}else if(v[i]>x&&v[i]<=y)s.push(v[i]);
			else if(v[i]<=x&&v[i]>y)s2.push(v[i]);
			else{
				std::cout<<"No"<<std::endl;
				break;
			}if(i==9)std::cout<<"Yes"<<std::endl;
		}
		k--;
	}
	return 0;
}

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

using namespace std;


int n;
int A[10];

bool solve(stack<int> v1, stack<int> v2, int index){
    if (index == 10)
        return true;
    if (v1.empty() || A[index] > v1.top())
        v1.push(A[index]);
    else if(v2.empty() || v2.top() < A[index])
        v2.push(A[index]);
    else
        return false;
    return solve(v1,v2, index + 1);
}

int main(){
    cin>>n;
    stack<int> v1,v2;
    while(n--){
        for (int i = 0; i < 10; ++i) {
            cin>>A[i];
        }
        if (solve(v1,v2,0))
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}