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 main(void){
  int N,t,B,C,i,j;
  cin >> N;
  for(i = 0 ; i < N ; i++){
    bool is = true;
    for( B = 0, C = 0, j = 0; j < 10; j++){
      cin >> t;
      if(B >= t && C >= t) is = false;
      if(is){
	if(B < t && C < t){
	  if(B < C) C = t;
	  else B = t;
	}
	else if(B < t) B = t;
	else if(C < t) C = t;
      }
    }
    if(is) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
using namespace std;

int main(){
	int n;
	cin>>n;
	rep(k,0,n){
		int d[10]={},a[11]={},b[11]={},at=0,bt=0;
		rep(i,0,10) cin>>d[i];
		bool f=1;
		rep(i,0,10){
			if(a[at]<d[i]){
				a[at+1]=d[i]; at++;
			}else if(b[bt]<d[i]){
				b[bt+1]=d[i]; bt++;
			}else{
				f=0; break;
			}
		}
		cout<<(f?"YES":"NO")<<endl;
	}
}

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


bool saiki(int ball[],int ttB,int ttC,int res){
	if(res==10)return true;
	if(ball[res]>ttB){
		return saiki(ball,ball[res],ttC,res+1);
	}
	if(ball[res]>ttC){
		return saiki(ball,ttB,ball[res],res+1);
	}
	return false;
}

int main(void){
	int a,b;
	int ball[11];
	int ttB=0,ttC=0;
	int res=0;
	int n;
	scanf("%d",&n);
	for(a=0;a<n;a++){
		for(b=0;b<10;b++){
			ball[b]=0;
		}
		ttB=0;
		ttC=0;
		res=0;
		for(b=0;b<10;b++){
			scanf("%d",&ball[b]);
		}
		if(saiki(ball,ttB,ttC,res)==true)printf("Yes\n");else printf("No\n");
	}
	return 0;
}

C++: #include<stdio.h>
int i,b[11],x;
void dfs(int i,int left,int right)
{
	if(i==10)
	{
		x=1;
		return;
	}
	if(x)
	{
		return;
	} 
	if(b[i]>left)
	{	
		dfs(i+1,b[i],right);
	}
	if(b[i]>right)
	{
		dfs(i+1,left,b[i]);
	}
}
int main()
{
	int a;
	while(scanf("%d",&a)!=EOF)
	{
		while(a--)
		{
			x=0;
			for(i=0;i<10;i++)
			{
				scanf("%d",&b[i]);
			}
			dfs(0,0,0);
			if(x==1)
			{
				printf("YES\n");
			}
			else
			{
				printf("NO\n");
			}
		}
	}
	return 0;	
}

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

int main(){
	int n, ball;cin >> n;
	stack<int> r, l;
	while(n--){
		r.push(0);l.push(0);
		bool f = false;
		for(int i = 0;i < 10;i++){
			cin >> ball;
			if(r.top() < ball){
				r.push(ball);
			}else if(l.top() < ball){
				l.push(ball);
			}else{
				f = true;break;
			}
		}
		while(!r.empty())r.pop();
		while(!l.empty())l.pop();
		if(f == false)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

bool judge(int num){
	int i, n, q[2]={0,0};

	for (i=0; i<num; i++) {
		cin >> n;
		if (q[0]<n)
			q[0] = n;
		else if (q[1]<n)
			q[1] = n;
		else
			break;
	}

	if (i==num)
		return true;
	else
		return false;
}

int main(){
	int i, lines;

	cin >> lines;
	for (i=0; i<lines; i++) {
		if (judge(10))
			cout << "NO\n";
		else
			cout << "YES\n";
	}
	return 0;
}

C++: #include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
static const int MAX_N = 10;
int a[MAX_N] = {0};

bool dfs(int a[],vector<int> r,vector<int> l,int i){
	if(i==MAX_N)return true;
	if(r.size()==0 || r[r.size()-1]<a[i]){
		r.push_back(a[i]);
		return dfs(a,r,l,i+1);
	}
	if(l.size()==0 || l[l.size()-1]<a[i]){
		l.push_back(a[i]);
		return dfs(a,r,l,i+1);
	}
	return false;
}


int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){//input
			cin>>a[j];
		}
		vector<int> r;
		vector<int> l;
		if(dfs(a,r,l,0)){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
}

C++: #include <cstdio>
using namespace std;
int main(void)
{
  int a,b,ball[10],n,i,flag;
  scanf("%d",&n);
  while(n-->0)
  {
    a=-1;b=-1;
    for(i=0;i<10;i++)
      scanf("%d",&ball[i]);
    for(i=0;i<10;i++)
    {
      flag=0;
      if(ball[i]>a)
        flag=1;

      if(ball[i]>b)
      {
        if(flag==1)
        {
          if(ball[i]-a<ball[i]-b)
            a=ball[i];
          else
            b=ball[i];
        }else{
          b=ball[i];
        }
        flag=2;
      }
      if(flag==0)
      {
        printf("NO\n");
        break;
      }
      if(flag==1)
        a=ball[i];
    }
    if(flag!=0)
      printf("YES\n");
  }
  return 0;
}

C++: /*
  ID: oodt
  PROG:
  LANG:C++
*/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>

using namespace std;

const int maxx=105;
int n,m,k;
int a[maxx];
int l[maxx],r[maxx];
bool ok;

void dfs(int i,int j, int k)
{
    if(i > 10)
    {
        ok = 1;
        return ;
    }
//    if(ok) return;
    if(a[i] > l[j-1])
    {
        l[j] = a[i];
        dfs(i+1,j+1,k);
    }
    if(a[i] > r[k-1])
    {
        r[k] = a[i];
        dfs(i+1,j,k+1);
    }
}

int main()
{
#ifdef LOCAL
    freopen("/Users/ecooodt/Desktop/c++ and acm/bai?/2.1/3.txt","r",stdin);
#endif
    int T;
    scanf("%d",&T);
    while(T--)
    {
        memset(r,0,sizeof(r));
        memset(l,0,sizeof(l));
        for(int i = 1; i <= 10; i++)
        {
            scanf("%d",&a[i]);
        }
        ok = 0;
        dfs(1,1,1);
        if(ok){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }

    return 0;
}

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

int main(){
    int n,tmp,a,b;
    bool judge;
    cin >> n;
    while(n--){
        stack <int> st1;
        stack <int> st2;
        judge = true;
        for(int i=0;i<10;i++){
            cin >> tmp;
            if(i == 0){
                st1.push(tmp);
                continue;
            }
            if(st2.empty()){
                if(tmp < st1.top()) st2.push(tmp);
                else st1.push(tmp);
                continue;
            }
            if(tmp - st1.top() > 0 && tmp - st2.top() > 0){
                a = tmp - st1.top();
                b = tmp - st2.top();
                if(a < b) st1.push(tmp);
                else st2.push(tmp);
            }
            else if(tmp - st1.top() > 0) st1.push(tmp);
            else if(tmp - st2.top() > 0) st2.push(tmp);
            else judge = false;
        }
        if(judge) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

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

int N;
int b[10];
bool res;

bool dfs(int n, int b1, int b2) {
    if (n == 9) { 
        if (b[n] > b1 || b[n] > b2) return true;
        return false;
    }
    if ((b[n] > b1 && dfs(n+1,b[n],b2)) ||
        (b[n] > b2 && dfs(n+1,b1,b[n]))) {
        return true;
    } else {
        return false;
    }
}

void solve() {
    res = dfs(1,b[0],-1);
    if (res) {
        cout << "YES\n";
    }
    else {
        cout << "NO\n";
    }
}

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

C++: #include <iostream>

using namespace std;

int a[10];

bool dfs(int i, int left, int right) {
  if(i == 10) { return true; }

  bool ans = false;
  if(left < a[i]) {
    ans = dfs(i+1, a[i], right);
  }
  if(right < a[i]) {
    ans = dfs(i+1, left, a[i]);
  }
  return ans;
}

int main() {
  int n;
  scanf("%d", &n);

  for(int i = 0; i < n; i++) {
    for(int j = 0; j < 10; j++) {
      scanf("%d", &a[j]);
    }
    cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
  }
  return 0;
}