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 <stack>

void get_input(int* arr) {
    for (int i = 0; i < 10; i++) {
        std::cin >> arr[i];
    }
}

char* solve(int* balls) {
    std::stack<int> a, b;
    a.push(0); b.push(0);

    for (int i = 0; i < 10; i++) {
        if (balls[i] > a.top() && balls[i] > b.top()) {
            if (a.top() > b.top()) {
                a.push(balls[i]);
            } else {
                b.push(balls[i]);
            }
        } else if (balls[i] > a.top() && balls[i] < b.top()) {
            a.push(balls[i]);
        } else if (balls[i] < a.top() && balls[i] > b.top()) {
            b.push(balls[i]);
        } else {
            return "NO";
        }
    }
    return "YES";
}

int main(void) {
    int balls[10];
    int n;
    std::cin >> n;

    for (int i = 0; i < n; i++) {
        get_input(balls);
        std::cout << solve(balls) << std::endl;
    }

    return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int ball[10];
int l,r;
bool flag;
void dfs(int num,int l,int r){
	if(num==10) return ;
//	if(flag) return ;
	if(ball[num]>l) dfs(num+1,ball[num],r);
	else if(ball[num]>r) dfs(num+1,l,ball[num]);
	else{
		flag=true;
		return ;
	}
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			cin>>ball[i];
		}
		l=0,r=0;
		flag=false;
	    dfs(i,l,r);
		if(flag){
			cout<<"NO"<<endl;
		}else{
			cout<<"YES"<<endl;
		} 
	}
}

C++: //Aizu 0033
//DinnerHunt
#include <cstdio>
#include <stack>
using namespace std;
int n,k,flag;
int main(){
	scanf("%d",&n);
	while(n--){
		stack<int> stk1,stk2;
		stk1.push(0);
		stk2.push(0);
		flag=1;
		for(int i=0;i<10;i++){			
			scanf("%d",&k);
			int a=k-stk1.top();
			int b=k-stk2.top();
			if (a<0&&b<0) flag=0;
			else if((0<a&&a<b)||(b<0)) stk1.push(k);
			else stk2.push(k);
		}
		if(flag)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++: #include <cstdio>

int B[10];
int C[10];
int ball[10];
int res = 0;

void solve(int i, int bi, int ci) {
  if (i == 10) {
    res = 1;
    return;
  }

  if (bi == 0) {
    B[bi] = ball[i];
    solve(++i, 1, ci);
    i--;
    B[bi] = 0;
  } else {
    if (ball[i] > B[bi-1]) {
      B[bi] = ball[i];
      solve(++i, ++bi, ci);
      B[bi] = 0;
      i--;
      bi--;
    }
  }

  if (ci == 0) {
    C[ci] = ball[i];
    solve(++i, bi, 1);
  } else {
    if (ball[i] > C[ci-1]) {
      C[ci] = ball[i];
      solve(++i, bi, ++ci);
    }
  }

}

int main() {
  int i,j;
  scanf("%d", &i);
  while(i) {
    for (j=0;j<10;j++)
      scanf("%d", &ball[j]);
    solve(0,0,0);
    if (res == 1) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
    i--;
    res = 0;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
  bool f;
  int n, b, c, p;
  cin >> n;
  while (n--) {
    b = c = 0;
    f = true;
    for (int i = 0; i < 10; i++) {
      cin >> p;
      if (p < b && p < c) f = false;
      else if (p > b) b = p;
      else if (p > c) c = p;
      else f = false;
    }
    cout << (f ? "YES" : "NO") << endl;
  }
}

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

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

	return "NO";
}

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

	for (int i = 0; i++ < n;) {
		cout << solve(0, 0, 0) << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
signed main(void){
	ios::sync_with_stdio(false);
	int T;
	cin>>T;
	for(int t=1;t<=T;t++){
		int a=0,b=0;
		for(int i=1,x;i<=10;i++){
			cin>>x;
			if(x<a&&x<b){
				cout<<"NO"<<endl;
				break;
			}
			else if(x>a&&x>b){
				if(a>b)	a=x;
				else	b=x;
			}
			else if(x<a&&x>b){
				b=x;
			}
			else if(x>a&&x<b){
				a=x;
			}
			if(i==10)
				cout<<"YES"<<endl;
		}
	}
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int ball[10];
int l,r;
bool flag;
void dfs(int num,int l,int r){
	if(num==10) return ;
	if(flag) return ;
	if(ball[num]>l) dfs(num+1,ball[num],r);
	else if(ball[num]>r) dfs(num+1,l,ball[num]);
	else{
		flag=true;
		return ;
	}
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			cin>>ball[j];
		}
		l=0,r=0;
		flag=false;
	    dfs(0,l,r);
		if(flag){
			cout<<"NO"<<endl;
		}else{
			cout<<"YES"<<endl;
		} 
	}
}

C++: #include <iostream>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  cin>>n;
  while(n--){
    int a[10],b[2][11]={0},b1=1,b2=1,k=0;
    r(i,10)cin>>a[i];
    r(i,10){
      if(a[i]>b[1][b1-1])b[1][b1++]=a[i];
      else b[0][b2++]=a[i];
    }
    r(i,b1-1){if(b[1][i]>b[1][i+1])k++;}
    r(i,b2-1){if(b[0][i]>b[0][i+1])k++;}
    if(k)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
  }
}

C++: #include<stdio.h>
#include <queue>
using namespace std;

bool flag = true;

void solve(queue<int> left, queue<int> right, queue<int> all) {
	if (all.size() > 0) {
		if (left.size() > 0) {
			if (all.front() > left.back()) {
				left.push(all.front());
				all.pop();
				solve(left, right, all);
			}
			else {
				if (right.size() > 0) {
					if (all.front() > right.back()) {
						right.push(all.front());
						all.pop();
						solve(left, right, all);
					}
					else if(all.size() == 0){
					
					}
					else {
						flag = false;
					}
				}
				else {
					right.push(all.front());
					all.pop();
					solve(left, right, all);
				}
			}
		}
		else {
			left.push(all.front());
			all.pop();
			solve(left, right, all);
		}
	}
}

int main() {

	int n;
	scanf("%d", &n);
	for (; n > 0; n--) {
		queue<int> all;
		queue<int> left;
		queue<int> right;
		for (int i = 0; i < 10; i++) {
			int temp;
			scanf("%d", &temp);
			all.push(temp);
		}
		solve(left, right, all);
		if (flag)
			printf("YES\n");
		else
			printf("NO\n");
	}	
	return 0;
}

C++: #include <stdio.h>

int a[11];

bool dfs(int i, int R, int L){
    if (i == 10) return true;
    if (dfs(i+1, a[i], L) && a[i] > R)
		return true;
    if (dfs(i+1, R, a[i]) && a[i] > L)
		return true;
    return false;
}

void solve(){
	for (int i=0; i<10; ++i){
		scanf("%d", &a[i]);
	}
	printf("%sn", dfs(0, 0, 0)?"YES":"NO");
}

int main (){
	int t;
	scanf("%d", &t);
	while (t --){
		solve();
	}
	return 0;
}

C++: #include<cstdio>

int main(){
	int n;
	int b,c;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		b = c = 0;
		int t;
		for(int j = 0; j < 10; j++){
			scanf("%d", &t);
			if(b < t){
				b = t;
			}else{
				if(c < t){
					c = t;
				}else{
					t = 11;
					break;
				}
			}
		}
		if(t - 11){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}

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

using namespace std;

int main() {

	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int A[10];
		for (int j = 0; j < 10; j++)cin >> A[j];
		stack<int> B, C;
		B.push(A[0]);
		for (int j = 1; j < 10; j++) {
			if (B.top() < A[j])B.push(A[j]);
			else if (C.empty() == 1 || C.top() < A[j])C.push(A[j]);
			else {
				cout << "NO" << endl;
				break;
			}
			if (j == 9)cout << "YES" << endl;
		}
	}

	return 0;
}