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

typedef vector<int> vi;

#define pb push_back

bool dfs(vi& a, int i, int b, int c)
{
  if (i == 10)
    return true;
  if (b < a[i] && dfs(a, i+1, a[i], c))
    return true;
  if (c < a[i] && dfs(a, i+1, b, a[i]))
    return true;
  return false;
}

int main(int argc, char **argv)
{
  int n, x;
  cin >> n;
  while (n--) {
    vi a;
    for (int i = 0; i < 10; i++) {
      cin >> x;
      a.pb(x);
    }
    if (dfs(a, 0, 0, 0))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
int a;
int b;
int n;
int c;
int d;
int e;
int f;
c=0;
while(c<n){
f=0;
a=0;
b=0;
d=0;
while(d<10){
cin >>e;
if(e>a&&a>b){a=e;}
else if(e>b&&b>a){b=e;}
else if(e>a){a=e;}
else if(e>b){b=e;}
else{f=1; break;}
d=d+1;}
if(f==0){cout <<"YES"<<endl;}
if(f==1){cout <<"NO"<<endl;}
c=c+1;}}

C++: // Aoj 0033: Ball
#include<bits/stdc++.h>
#define mset(x,y) memset(x,y,sizeof(x))
using namespace std;

const int N=110,M=20010;
int h[N],to[M],nexp[M],p=1;
inline void init_list(){mset(h,0),mset(nexp,0),p=1;}
inline void ins(int a,int b){
    nexp[p]=h[a],h[a]=p,to[p]=b,p++;
}
int arr[N];
int col[N];
bool imp;
void dfs(int x,int ncol){
    col[x]=ncol;
    for(int u=h[x];u;u=nexp[u]){
        if(col[to[u]] == col[x]) imp=1;
        if(imp) return;
        if(!col[to[u]]) dfs(to[u],ncol^1);
    }
}

int main(){
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--){
        for(int i=0;i<10;i++) cin>>arr[i];
        for(int i=0;i<10;i++)
        for(int j=i+1;j<10;j++)
            if(arr[i]>arr[j]) ins(i,j),ins(j,i);
        mset(col,0), imp=0;
        for(int i=0;i<10;i++)
            if(!col[i]) dfs(i,2);
        if(imp) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
vector<int> A = {-1};
vector<int> B = {-1};
int num[10];
bool flag = false;
void push(int i)
{
	if (i == 10)
		flag = true;
	else
	{
		if (A.back() < num[i])
		{
			A.push_back(num[i]);
			push(i + 1);
			A.pop_back();
		}
		if (B.back() < num[i])
		{
			B.push_back(num[i]);
			push(i + 1);
			B.pop_back();
		}
	}
}
int main()
{
	int k;
	cin >> k;
	while (k--)
	{
		flag = false;
		for (int i = 0; i <= 9; ++i)
			cin >> num[i];
		if (flag == true)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}

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

int main()
{
    int Atop=0, Btop=0, n, ball;
    cin >> n;
    while (n-->0) {
        bool fine = true;
        for (int i = 0; i < 10; ++i) {
            cin >> ball;
            if (max(Atop, Btop) < ball) {
                if (Atop >= Btop) Atop = ball;
                else Btop = ball;
            } else if (Atop < ball) {
                Atop = ball;
            } else if (Btop < ball) {
                Btop = ball;
            } else {
                fine = false;
            }
        }
        cout << (const char *)(fine ? "YES" : "NO") << endl;
    }
}

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

int main() {
	int n;
	int d[10];
	int va[10];
	int vb[10];
	int trush;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> d[i];
		}

		int ca = 0, cb = 0;
		va[0] = d[0];
		ca++;
		if (d[1] > va[0]) {
			va[1] = d[1];
			ca++;
		}

		else {
			vb[0] = d[1];
			cb++;
		}

	for (int j = 2; j < 10; j++) {

		if (d[j] < va[ca - 1] || d[j] < vb[cb - 1]) {
			cout << "NO" << endl;
			goto FINLOOP;
		}

			else if (d[j] > va[ca-1]) {
				va[ca] = d[j];
				ca++;
			}

			else if (d[j] > vb[cb - 1]) {
				vb[cb] = d[j];
				cb++;
			}
			
		}
		cout << "YES" << endl;

		FINLOOP:
		for (int i = 0; i < 10; i++) {
			va[i] = 0;
		}
		for (int i = 0; i < 10; i++) {
			vb[i] = 0;
		}
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int arr[10],used[10];
void DFS(int pre,int cur)
{
   if(cur<10&&arr[pre]<arr[cur])
   {
	   used[cur]=1;
	   DFS(cur,cur+1);
   }
   else if(cur<10&&arr[pre]>=arr[cur])
	   DFS(pre,cur+1);
}
int main()
{
   int T,pre;
   bool judge;
   cin>>T;
   while(T--)
   {
     for(int i=0;i<10;i++)
		 cin>>arr[i];
	 for(int i=0;i<10;i++)
	 {
		 memset(used,0,sizeof(used));
		 used[i]=1;
	     DFS(i,i+1);
		 judge=false;
		 pre=0;
	     for(int j=0;j<10;j++)
		    if(used[j]==0)
				if(pre>=arr[j])
			{
				judge=true;
				break;
			}else pre=arr[j];
		 if(!judge)
		 {
			 cout<<"YES"<<endl;
			 break;
		 }
	 }
	 if(judge)cout<<"NO"<<endl;
   }

}

C++: #include<iostream>
#include<stack>
using namespace std;
int a[15];
stack <int> l,r;
bool flag;
void dfs(int x)
{
	if(x>10)
	{
		flag=true;
		return;
	}
	if(flag)
	  return;
	if(a[x]>l.top())
	{
		l.push(a[x]);
		dfs(x+1);
		l.pop();
	}
	if(a[x]>r.top())
	{
		r.push(a[x]);
		dfs(x+1);
		r.pop();
	}
}
int main ()
{
	ios::sync_with_stdio(false);
	int T;
	cin>>T;
	while(T--)
	{
		l.push(0);r.push(0);
		for(int i=1;i<=10;i++)
		  cin>>a[i];
		dfs(1);
		if(flag==true)
		  cout<<"YES"<<endl;
		else
		  cout<<"NO"<<endl;
		flag=false;
		while(!l.empty())
		  l.pop();
		while(!r.empty())
		  r.pop();
	}
	return 0;
}

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

#define SIZE 10

int ary[SIZE];

string solve(int a, int b, int f) {
	if (f >= 10) return "YES";
	
	if (ary[f] > a) return solve(ary[f], b, f + 1);
	if (ary[f] > b) return solve(a, ary[f], f + 1);

	return "NO";
}

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

	for (int i = 0; i++ < n;) {
		for (int j = 0; j < SIZE; j++) {
			cin >> ary[j];
		}
		cout << solve(0, 0, 0) << 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,b,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 <bits/stdc++.h>
using namespace std;

int main()
{
  int n;

  cin >> n;
  while (n != 0){
    stack<int> a, b;
    int s[10];
    bool judge = true, j = false;
    for (int i = 0; i < 10; i++){
      cin >> s[i];
    }
    a.push(s[0]);
    for (int i = 1; i < 10; i++){
      if (a.top() < s[i]){
        a.push(s[i]);
      }
      else if (!j){
        b.push(s[i]);
        j = true;
      }
      else if (b.top() < s[i]){
        b.push(s[i]);
      }
      else {
        judge = false;
        break;
      }
    }

    if (judge){
      cout << "YES\n";
    }
    else {
      cout << "NO\n";
    }
    n--;
  }
}