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 <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#define INF 1000000000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define all(x) (x).begin(),x.end()
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

int a[11];

int dfs(int left,int right,int cnt){
  //cout<<left<<" "<<right<<" "<<cnt<<endl;
  if(cnt==9)return cnt;
  if(left<a[cnt]&&right<a[cnt]) cnt=max(dfs(a[cnt],right,cnt+1),dfs(left,a[cnt],cnt+1));
  else if(left<a[cnt])cnt=dfs(a[cnt],right,cnt+1);
  else if(right<a[cnt]) cnt=dfs(left,a[cnt],cnt+1);
  
  return cnt;
}

int main(){
  int n;
  cin>>n;
  rep(i,n){
    rep(j,10)cin>>a[j];
    //rep(j,10)cout<<a[i]<<" ";
    //cout<<endl;
    if(dfs(a[0],-INF,1)==9)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n,a[10];
	cin>>n;
	for(int i=0;i<n;i++){
		bool t=true;
		for(int j=0;j<10;j++)
			cin>>a[j];
		int b,c;
		if(a[0]>a[1]){
			b=a[0];
			c=a[1];
		}
		else{
			b=a[1];
			c=a[0];
		}
		for(int j=2;j<10;j++){
			if(c>a[j])
				t=false;
			if(c<a[j]&&b>a[j])
				c=a[j];
			if(b<a[j])
				b=a[j];
		}
		if(t==true)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}

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

int main(){
    int x;
    for(int i=0;i<x;++i){
        std::vector<int> vec(10);
        for(int l=0;l<10;++l){
            std::cin>>vec[l];
        }
        std::vector<std::vector<int> > vec2(2);
        vec2[0].push_back(vec[0]);
        for(int l=1;l<vec.size();++l){
            if(l==1){
                if(vec2[0][0]<vec[1]){
                    vec2[0].push_back(vec[1]);
                }else vec2[1].push_back(vec[1]);
            }else{
                if(vec[l]>vec2[0][vec2[0].size()-1]){
                    vec2[0].push_back(vec[l]);
                }else{
                    if(vec2[1].size()==0)vec2[1].push_back(vec[l]);
                    else if(vec2[1][vec2[1].size()-1]<vec[l]){
                        vec2[1].push_back(vec[0]);
                    }else{
                        std::cout<<"NO"<<std::endl;
                        goto con;
                    }
                }
            }
        }
        std::cout<<"YES"<<std::endl;
con:
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<cmath>
#include<stack>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn =  10 + 8;

int n;
int g[maxn];

int main()
{
    scanf("%d", &n);
    while(n--)
    {
        memset(g, 0, sizeof g);
        stack<int> p,q;
        p.push(0); q.push(0);
        for(int i = 0; i < 10; ++i) cin >> g[i];
        int i = 0;
        while(true)
        {
            if(i == 10) break;
            if(g[i] > p.top()) {p.push(g[i]);}
            else {
                if(g[i] > q.top())
                {
                    q.push(g[i]);
                }
            }
            i++;
        }
        if(p.size() + q.size() == 12) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int tama[10];

bool Haireruka(int i,int left,int right){
	if(tama[i]<left){
		if(Haireruka(i+1,tama[i],right))return true;
	}
	if(tama[i]<right){
		if(Haireruka(i+1,left,right))return true;
	}
	return false;
}

int main(){
	for(int i=0;i<10;i++){
		cin>>tama[i];
	}
	if(Haireruka(0,0,0))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

C++: #include<cstdio>
int main()
{
    int N,ba[10],B,C,ju;
    scanf("%d",&N);
    for(int i=0;i<N;i++)
    {
        ju=0;
        B=0;
        C=-1;
        for(int j=0;j<10;j++)
        {
            scanf("%d",&ba[j]);
        }
        for(int j=0;j<10;j++)
        {
            if(ba[j]>B&&ba[j]>C)
            {
                if(B>C)B=ba[j];
                else C=ba[j];
            }
            else if(ba[j]>B)B=ba[j];
            else if(ba[j]>C)C=ba[j];
            else ju++;
        }
        if(ju==0)printf("YES\n");
        if(ju>=1)printf("NO\n");
    }
    return 0;
}

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

using namespace std;

vector<int> a;
stack<int> b, c;

bool dfs(int i)
{
	if (i == 10) return true;

	bool res1 = false, res2 = false;

	if (b.empty()) {
		b.push(a[i]);
		res1 = dfs(i + 1);
		b.pop();
    } else if(c.empty()) {
		c.push(a[i]);
		res2 = dfs(i + 1);
		c.pop();
    } else if (b.size() && c.size()) {
        if (b.top() < a[i]) {
            b.push(a[i]);
            res1 = dfs(i + 1);
            b.pop();
        } else if (c.top() < a[i]) {
            c.push(a[i]);
            res2 = dfs(i + 1);
            c.pop();
        }
    }

	return res1 || res2;
}

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

	while (n--) {
		a.clear();
		while (b.size()) b.pop();
		while (c.size()) c.pop();

		for (int i = 0; i < 10; ++i) { int v; cin >> v; a.push_back(v); }

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

C++: #include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
int n;
int ba[10];
bool bfs(int l,int r,int x)
{
	if(x==10) return true;
	if(ba[x]<l&&ba[x]<r) return false;
	if(l<ba[x]&&bfs(ba[x],r,x+1)) return true;
	if(r<ba[x]&&bfs(l,ba[x],x+1)) return true;
	return false;
}

int main()
{
	cin>>n;
	for(;n>0;n--){
		for(int i=0;i<10;i++){
			scanf("%d",&ba[i]);
		}
		if(bfs(0,0,0)) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

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

int B, C, num[20], b, c;

string dfs(int x){
    if(x == 10)  return "YES";
    else if(B>num[x]){
        if(C<num[x]){
            C = num[x];
            return dfs(x+1);
        }
        else return "NO";
    }
    else if(B<num[x]){
        B = num[x];
        return dfs(x+1);
    }
}

int main(void){
    int N;
    while(cin >> N){
    B = 0;
    C = 0;
    for(int i=0; i<10; i++){
        cin >> num[i];
    }
    string str = dfs(0);
    cout << str << endl;
    }
    return 0;
}

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

int data[10];
bool sumilation(int left,int right,int num){
	if(num == 10) return true;
	
	if(left < data[num]){
		if(sumilation(data[num],right,num+1)) return true;
	} 
	if(right < data[num]){
		if(sumilation(left,data[num],num+1)) return true;
	}
	return false;
	
	
}

int main(){
	int times;
	cin >> times;
	for(int i=0;i<times;i++){
		for(int k=0;k<10;k++)
		cin >> data[k];
		if(sumilation(0,0,0) == true){
		cout << "YES" << endl;
		} else {
		cout << "NO" <<endl;
		}
		
		
	}

}