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++: ///////////////////////////////////////////////////////////
//どんな人生を選ぶかより、選んだ人生をどう生きるかが大切だ//
/////////////////////////////////////////////////////////
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f
const int MAXN = 105;
int num[15]; bool flag;
void DFS(int index,int maxB, char maxC)
{
	if (index == 10)
	{
		flag = true;
		return;
	}
	if (flag)
	{
		return;
	}
	if (num[index] > maxB)
	{
		DFS(index + 1, num[index], maxC);
	}
	if (num[index] > maxC)
	{
		DFS(index + 1, maxB,num[index]);
	}
}
int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		flag = false;
		for (int i = 0; i < 10; i++)
		{
			scanf("%d", &num[i]);
		}
		DFS(0, 0, 0);
		if (flag)
		{
			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 = { {0} };
		for (int j = 0; j < 10; j++) {
			cin >> x;
			z = v.size();
			for (int k = 0; k < z; k++) {
				if (v[k].back() < x) {
					v[k].push_back(x);
					break;
				}

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

			if (v.size() == 3) {
				x = -1;
				break;
			}
		}

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

C++: #include<stdio.h>

int main()
{
  int i,j;
  int n,N;
  int b=0,c=0;
  char *str="YES";
  scanf("%d",&N);
  for(i=0;i<N;i++)
    {
      for(j=0;j<10;j++)
	{
	  scanf("%d",&n);
	  if(n>b)
	    b=n;
	  else if(n>c)
	    c=n;
	  else
	    str="NO";
	}
      puts(str);
    }
  
  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;i++){
  std::cin>>A;
  if(B<A)B=A;
  else if(C<A) C=A;
  else f=1;
 }
}

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

int n;
int a[10];
int r, l;

bool dfs(int i) {
    if (i == 9) return a[i] > r || a[i] > l;
    if (a[i] > r) {
        r = a[i];
    }
    if (a[i] >l) {
        l = a[i];
    }
    if (dfs(i+1)) return true;
    return false;
}

void solve() {
    if (dfs(0)) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> a[j];
        }
        solve();
    }
}

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

int main() {
int a[10],b[11],c[11];
int n;
cin>>n;
for (int jjj=1;jjj<=n;jjj++){
	for(int kk=0;kk<10;kk++) cin>>a[kk];
int bb=0,cc=0;
b[0]=0;
c[0]=0;
for (int k=0;k<10;k++){
	if(a[k]>b[bb] && b[bb]>=c[cc]){
		b[bb+1]=a[k];
		bb=bb+1;
	}
	else{
		c[cc+1]=a[k];
		cc=cc+1;
	}
}
	int l=0,m=0;
	for(int i=1;i<bb;i++){
		if(b[i]-b[i-1]<0){
			l=2;
		}
	}
	for(int j=1;j<cc;j++){
		if(c[j]-c[j-1]<0){
			m=2;
		}
	}
	if(l+m==0){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
	
}

	return 0;
}

C++: #include <cstdio>
int ball[10];
bool dfs(int n,int b,int c) {
	if(n==10) {
		return true;
	}
	bool res=false;
	if(b<ball[n]) {
		res|=dfs(n+1,ball[n],c);
	}
	if(c<ball[n]) {
		res|=dfs(n+1,c,ball[n]);
	}
	return res;
}
int main() {
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++) {
		for(int j=0;j<10;j++) {
			scanf("%d",&ball[j]);
		}
		printf("%s\n",dfs(0,0,0)?"YES":"NO");
	}
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;

int n, k, b = 0, c = 0;
bool f = 1;
stack<int> sb, sc;

int main(){
	cin >> n;
	REP(i, n){
		REP(j, 10){
			cin >> k;
			if (b == 0){
				sb.push(k);
				b++;
			}
			else if (c == 0){
				sc.push(k);
				c++;
			}
			else{
				if (sb.top() < k){
					sb.push(k);
				}
				else if (sc.top() < k){
					sc.push(k);
				}
				else{
					f = 0;
				}
			}
		}
		if (f){
			cout << "YES\n";
		}
		else{
			cout << "NO\n";
		}
	}
}

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

using namespace std;

int main(){
	int n;
	int left, right;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> left;
		right=0;
		int temp;
		bool flag = 1;
		//while(cin >> temp){
		for(int j=1;j<10;j++){
			cin >> temp;
			if(left<right){
				if(right<temp){
					right=temp;
				}else if(left<temp){
					left=temp;
				}else{
					flag=false;
				}
			}else{
				if(left<temp){
					left=temp;
				}else if(right<temp){
					right=temp;
				}else{
					flag=false;
				}
			}
		}
		if(flag){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

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

int main() {
	int n, x;
	cin >> n;
	for (int lop = 0; lop < n; lop++) {
		int a = 0, b = 0;
		bool f = true;
		for (int i = 0; i < 10; i++) {
			cin >> x;
			if (f) {
				if (a < x && b < x) {
					if (a < b) {
						b = x;
						continue;
					}
					a = x;
					continue;
				}
				if (a < x) {
					a = x;
					continue;
				}
				if (b < x) {
					b = x;
					continue;
				}
				f = false;
			}
		}
		if (f)
			cout << "YES\n";
		else
			cout << "NO\n";
		//cout << (f ? "YES\n" : "NO\n");
	}
	return 0;
}

C++: #include<stdio.h>
int n, a[10];
int b[11] = { }, c[11] =

{
};

bool
dfs (int l, int r)
{
  if (l + r == 9)
    return true;
  if (b[l] < a[l + r])
    {
      b[l + 1] = a[l + r];
      return dfs (l + 1, r);
    }
  else if (c[r] < a[l + r])
    {
      c[r + 1] = a[l + r];
      return dfs (l, r + 1);
    }
  return false;
}

int
main (void)
{
  scanf ("%d", &n);
  for (int i = 0; i < n; i++)
    {
      for (int j = 0; j < 10; j++)
	scanf ("%d", &a[j]);
      if (dfs (0, 0))
	puts ("YES");
      else
	puts ("NO");
    }
  return 0;
}