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>
int box[10];
int ltop=-1,rtop=-1;
bool ball(int i){
	if(i==9)return true; 
	if(ltop==-1 || rtop==-1){
		if(ltop==-1){
			ltop=box[i];
			return ball(i+1);
		}
		else{
		    rtop=box[i];
			return ball(i+1);	
		}
	}
	else{
		if(box[i]>ltop&&box[i]>rtop){
			if(ltop>rtop){
				ltop=box[i];
			}
			else{
				rtop=box[i];
			}
			return ball(i+1);
		}
		else if(box[i]>ltop){
			ltop=box[i];
			return ball(i+1);
		}
		else if(box[i]>rtop){
			rtop=box[i];
			return ball(i+1);
		}
		else return false;
	}
}
int main(){
	int n;
	std::cin>>n;
	for(int what=0;what<n;++what){
		for(int i=0;i<10;++i){
			std::cin>>box[i];
		}
		if(ball(0))std::cout<<"YES\n";
		else std::cout<<"NO\n";
		ltop=-1;
		rtop=-1;
	}
}

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

bool dfs(int num, int val1, int val2, vector<int> &v){
  if(val1 > val2){
    int x = val1;
    val1 = val2;
    val2 = x;
  }
  if(num == 10)
    return true;

  if(val2 < v[num]){
    val2 = v[num];
    return dfs(num + 1, val1, val2, v);
  }else if(val1 < v[num]){
    val1 = v[num];
    return dfs(num + 1, val1, val2, v);
  }else {
    return false;
  }
}

int main(){
  int N;
  cin >> N;
  vector<int> v(10);
  vector<int> out(N, 0);
  for(int i=0;i<N;i++){
    for(int j=0;j<10;j++)
      cin >> v[j];
    if(dfs(0, 0, 0, v)){
      out[i] = 1;
    }
  }

  for(int i=0;i<N;i++)
    if(out[i] == 1)
      cout << "YES" << endl;
    else 
      cout << "NO" << endl;

  return 0;
}

C++: #include <stdio.h>

int ball[10];

bool can(int n,int left,int right){
	bool flag;
	
	if(n==10) return true;
	if(ball[n]>right && can(n+1,left ,ball[n])) return true;
	if(ball[n]>left  && can(n+1,ball[n],right)) return true;
	
	return false;
}


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(can(0,0,0)?"YES\n":"NO\n");
		
		
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j;i<k;i++)
int N;
int A[10];
bool DFS(int Aindex,int x,int y){
  if(Aindex ==10)return true;
  if(x>A[Aindex] && y>A[Aindex])return false;
  bool m=false;
  if(x<A[Aindex])m=max(m,DFS(Aindex+1,A[Aindex],y));
  if(y<A[Aindex])m=max(m,DFS(Aindex+1,x,A[Aindex]));
  return m;
}
int main(){
  cin >> N;
  string ans[2]={"NO","YES"};
  rep(i,0,N){
    rep(i,0,10){
      cin >>A[i];
    }
    cout << ans[DFS(0,0,0)]<<endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main(void) {
    int N, a, b, c, x[10];
    cin >> N;
    for (; N--; ) {
        bool ok = true;
        b = c = 0;
        for (int i = 0; i < 10; i++) {
            cin >> x[i];
        }
        cerr << b << endl;
        cerr << c << endl;
        for (int i = 0; i < 10; i++) {
            a = x[i];
            if (a < b && a < c) {
                ok = false;
                break;
            } else if (a < b) {
                c = a;
            } else if (a < c) {
                b = a;
            } else if (b < c) {
                c = a;
            } else {
                b = a;
            }
        }
        if (ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
 
using namespace std;
 
int s[10]={0};
 
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        for(int i=0;i<10;i++)
            scanf("%d",&s[i]);
        int a=0,b=0;
        bool flag=0;
        for(int i=0;i<10;i++)
        {
            if(s[i]<a&&s[i]<b)
            {
                flag=1;
                break;
            }
            else if(s[i]<a&&s[i]>b)b=s[i];
            else if(s[i]>a&&s[i]<b)a=s[i];
            else
            {
                a=a>b?s[i]:a;
                b=a<b?s[i]:b;
                if(a==b)a=s[i];
            }
        }
        if(flag)printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}

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

int T;
int input[10];
int B[10], C[10];
int Bcnt, Ccnt;
int flag = 1;

void dfs(int i);
void clear();


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

void dfs(int i) {
    if (i>9) return;
    
    if (input[i]>B[Bcnt-1]) {
        B[Bcnt++] = input[i];
        dfs(i+1);
    } else if (input[i]>C[Ccnt-1]) {
        C[Ccnt++] = input[i];
        dfs(i+1);
    } else flag = 0;
}

void clear() {
    for (int i = 0; i<10; i++) {
        input[i] = 0;
        B[i] = 0;
        C[i] = 0;
    }
    Bcnt = Ccnt = 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<set> 
#include<vector>
#include<stack>
#include<string>
#include<ctype.h>
#include<sstream> 
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<cstring> 
using namespace std; 
int flag;
int a[11];

void dfs(int x, int l, int r)
{
	if(x == 10) return;
	if(flag) return;
	if(a[x] > l) dfs(x+1, a[x], r);
	else if(a[x] > r) dfs(x+1, l, a[x]);
	else {
		flag = 1;
		return;
	}
 } 

int main()
{	
	int n;
	cin>>n;
	while(n--)
	{
		flag = 0;
		for(int i = 0; i < 10; i++){
			cin>>a[i];
		}
		dfs(0,0,0);
		if(flag) cout<<"NO"<<endl;
		else cout<<"YES"<<endl;
	}
	return 0;
 }

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

using namespace std;

bool dfs(queue<int> q, int a, int b)
{
  if (q.empty())
    return true;

  int front = q.front();
  q.pop();

  if (front > a && dfs(q, front, b))
    return true;
  if (front > b && dfs(q, a, front))
    return true;

  return false;
}

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

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

    queue<int> q;

    for (int i = 0; i < 10; i++)
    {
      int x;
      cin >> x;
      q.push(x);
    }

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