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>

using namespace std;

int n, a[11];

bool dfs(int idx, int mxa, int mxb){
  if(idx==10)return true;
  if(a[idx]<mxa && a[idx]<mxb)return false;
  bool ap=false, bp=false;
  if(a[idx]>mxa){
    ap = dfs(idx+1, a[idx], mxb);
  }
  if(a[idx]>mxb){
    bp = dfs(idx+1, mxa, a[idx]);
  }
  return ap || bp;
}

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

C++: #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

int main(){
    int n,b,B=0,C=0;
    
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        B=0;C=0;
        for(int j=0;j<10;j++){
            scanf("%d",&b);
            if(min(B,C)<b){
                if(B>C && B<b)B=b;
                else C=b;
            }else{
                B=0;C=0;
                break;
            }
        }
        if(B==10 || C==10)
            puts("YES");
        else
            puts("NO");
    }
}

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

using namespace std;
vector<int> B;
vector<int> C;

bool calc(int a[], int n, vector<int>& Vec)
{
	Vec.push_back(a[n - 1]);
	if(n == 10)
	{
		return(true);
	}
	if(B[B.size() - 1] > a[n] && C[C.size() - 1] > a[n])
	{
		return(false);
	}
	else if(B[B.size() - 1] < a[n] && C[C.size() - 1] < a[n])
	{
		return(calc(a, n + 1, B) || calc(a, n + 1, C));
	}
	else if(B[B.size() - 1] < a[n])
	{
		return(calc(a, n + 1, B));
	}
	else if(C[C.size() - 1] < a[n])
	{
		return(calc(a, n + 1, C));
	}
}

void solve()
{
	int n;
	cin >> n;
	while(n--)
	{
		B.clear();
		C.clear();
		int a[10];
		for(int i = 0; i < 10; ++i)
		{
			cin >> a[i];
		}
		C.push_back(0);
		if(calc(a, 1, B))
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>
#include <cstring>
#include <cstdlib>

typedef long long ll;

using namespace std;

int N;
int ball[10];

bool dfs(int a, int b, int num){
	if(num == 10) return true;
	if(ball[num] > a && dfs(ball[num], b, num+1)) return true;
	if(ball[num] > b && dfs(a, ball[num], num+1)) return true;
	return false;	
}

int main(void){
	cin >> N;

	for(int i=0; i<N; ++i){

		for(int j=0; j<10; j++){
			cin >> ball[j];
		}
		if(dfs(0, 0, 0)) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}

	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
int l[12],r[12],q[12];
bool yon;
void dfs(int i,int j,int k){
	if(i == 10){
		yon = true;
		return ;
	}
	if(yon){
		return ;
	} 
	if(q[i] > l[j-1]){
		l[j] = q[i];
		dfs(i+1,j+1,k);
	}
	if(q[i] > r[k-1]){
		r[k] = q[i];
		dfs(i+1,j,k+1);
	}
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--){
		for(int i=1;i<=10;i++){
			scanf("%d",&q[i]);
		}
		yon = false;
		l[0] = -1;
		r[0] = -1;
		dfs(1,1,1);
		if(yon){
			printf("YES\n");
		}else{
			printf("NO\n"); 
		}
	}
	return 0;
}

C++: #include <iostream>

using namespace std;
const int kBalln = 10;
int main(){
  int n;
  int ball;
  int b, c;
  bool ans;
  cin >> n;
  for (int j = 0; j < n; ++j)
    {
      b = 0; c = 0;ans = true;
      for (int i = 0; i < kBalln; ++i)
        {
          cin >> ball;
          if (b < ball)
            {
              b = ball;
            }
          else if (c < ball)
            {
              c = ball;
            }
          else
            {
              ans = false;
              // cout << "NO" << endl;
              break;
            }
        }
      cout << (ans ? "YES" : "NO") << endl;
    }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
  int n;
  bool success;

  cin >> n;
  while(n--){
    success = false;
    int b = 0, c = 0;
    int a[10];
    for(int i=0; i<10; i++){
      cin >> a[i];
    }

    for(int i=0; i<10; i++){ 
      if(b < a[i] && c < a[i]){
        if(b < c)
          c = a[i];
        else
          b = a[i];
      }
      else if(b < a[i]){
          b = a[i];
      }
      else if(c < a[i]){
          c = a[i];
      }
      else{
        success = false;
        break;
      }

      if(i == 9)
        success = true;
    }

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

C++: #include<cstdio>  
int n,l1,l2,a[15];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
	    bool f=0;l1=-1;l2=0;
		for(int j=1;j<=10;j++)
			scanf("%d",&a[j]);
		for(int j=1;j<=10;j++)
		if(!f)
		{
			if(a[j]<l1&&a[j]<l2){f=1;printf("No\n");break;}
			if(l1>l2){if(a[j]>l1)l1=a[j];else l2=a[j];} 
			else{if(a[j]>l2)l2=a[j];else l1=a[j];}
		}
		if(!f)printf("YES\n");a
	}
}

C++: #include<stdio.h>
#include<string.h>
int l[15],r[15],q[15];
bool yon;
void dfs(int i,int j,int k){
	if(i == 10){
		yon = true;
		return ;
	}
	if(yon){
		return ;
	} 
	if(q[i] > l[j-1]){
		l[j] = q[i];
		dfs(i+1,j+1,k);
	}
	if(q[i] > r[k-1]){
		r[k] = q[i];
		dfs(i+1,j,k+1);
	}
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--){
		for(int i=1;i<=10;i++){
			scanf("%d",&q[i]);
		}
		yon = false;
		dfs(1,1,1);
		if(yon){
			printf("YES\n");
		}else{
			printf("NO\n"); 
		}
	}
	return 0;
}

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


int main()
{
	int n;
	cin >> n;
	int a[11];
	while (n--)
	{
		bool flag = true;
		int min_a = 0, min_b = 0;
		for (int i = 0; i < 10; i++)
			cin >> a[i];
		for (int j = 0; j < 10; j++)
		{
			if (a[j] > min_a)
			{
				if (min_a >= min_b)
				{
					min_a = a[j];
				}
				else
				{
					min_b = a[j];
				}
				continue;
			}
			else if (a[j] > min_b)
			{
				min_b = a[j];
			}
			else
			{
				flag = false;
				break;
			}
		}
		if (flag==true)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
    return 0;
}

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

C++: #include<iostream>
using namespace std;
int main(){
	int row[2],order[10],memo[10][2],n;
	cin >>n;
	for(int i=0; i<n; i++){
		for(int l=0; l<10; l++){
			cin >>order[l];
		}
		row[0] = order[0];
		row[1] = 0;
		int x = 0,l;
		for(l=1; l<10; l++){
			if(row[0]<order[l] && row[1]>order[l]){row[0] = order[l];}
			else if(row[0]>order[l] && row[1]<order[l]){row[1] = order[l];}
			else if(row[0]<order[l] && row[1]<order[l]){
				memo[x][0] = row[0];
				memo[x][1] = l;
				row[0] = order[l];
				x++;
			}
			else if(row[0]>order[l] && row[1]>order[l]){
				if(x == 0){cout <<"NO"<<endl;break;}
				else{
					x--;
					row[0] = memo[x][2];
					l = memo[x][1];
					row[1] = order[l];
				}
			}
		}
		if(l == 10){cout <<"YES"<<endl;}
	}
	return 0;
}