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<cstdio>
#include<algorithm>

using namespace std;

int N;
int l[15];
int b,c;
int res[100000000];


void solve(int k){
  for(int i=0;i<10;i++){
    if(b<l[i] && c<l[i]){
      if(l[i]-b < l[i]-c) b=l[i];
      else c=l[i];
    }
    else if(b<l[i] && c>l[i]) b=l[i];
    else if(b>l[i] && c<l[i]) c=l[i];
    else{
      res[k]=0;
      return;
    }
  }
  res[k]=1;
  return;
}


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

  for(int i=0;i<N;i++){
    b,c=0;
    scanf("%d%d%d%d%d%d%d%d%d%d",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9]);
    solve(i);
  }

  for(int i=0;i<N;i++){
    if(res[i]==0) printf("NO\n");
    else printf("YES\n");
  }


  return 0;
}

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<iostream>
using namespace std;
int main(){
  int n;cin >> n;
  while(n--){
    int r=0,l=0,d;
    bool f=false;
    for(int i=0;i<10;i++){
      cin >> d;
      //cout << d << endl;
      if(r<d){
	if(r<l&&l<d) l=d;
	else r=d;
      }else if(l<d){
	if(l<r&&r<d) r=d;
	else l=d;
      }else{
	f=true;
	break;
      }
      //cout << l << ":" << r << endl;
    }
    if(f) cout << "NO" << endl;
    else cout << "YES" << endl;
  }  
}

C++: #include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    bool flag;
    int num[15];
    int a,b,t;
    cin >> t;
    while(t--)
    {
        a = 0,b = 0;
        flag = true;
        for(int i = 0; i < 10; i++)
        {
            cin >> num[i];
        }
        for(int i = 0; i < 10; i++)
        {
            if(a >= b)
            {
                if(num[i] > a)
                {
                    a = num[i];
                }
                else if(num[i] > b)
                {
                    b = num[i];
                }
                else
                {
                    flag = false;
                    break;
                }
            }
            else
            {
                if(num[i] > b)
                {
                    b = num[i];
                }
                else if(num[i] > a)
                {
                    a = num[i];
                }
                else
                {
                    flag = false;
                    break;
                }
            }
        }
        if(flag)
        {
            printf("YES\n");
        }
        else printf("NO\n");
    }
    return 0;
}

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

int a[10];
int main() {
	int n;
	cin >> n;
	rep(k, n) {
		rep(i, 10)scanf("%d", &a[i]);
		rep(i, 1 << 10) {
			stack<int>s[2];
			rep(j, 10)if (s[(i >> j) & 1].empty() || a[j] > s[(i >> j) & 1].top())s[(i >> j) & 1].push(a[j]);
			if (s[0].size() + s[1].size() == 10) { puts("YES"); break; }
			if (i == (1 << 10) - 1)puts("NO");
		}
	}
	return 0;
}

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

bool solve(int ball[10]){
  stack<int> b, c;
  b.push(ball[0]);
  c.push(0);
  for(int i = 1; i < 10; i++){
    if(ball[i] < b.top() && ball[i] < c.top()) return false;
    if(b.top() > c.top()){
      if(ball[i] > b.top()) b.push(ball[i]);
      else c.push(ball[i]);
    }
    else{
      if(ball[i] > c.top()) c.push(ball[i]);
      else b.push(ball[i]);
    }
  }
  return true;
}

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

  int ball[10];
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 10; j++){
      cin >> ball[j];
    }
    if(solve(ball)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int n;

	cin >> n;

	while(n--){
		int input = 0;
		int left = 0, right = 0;
		bool achieve = true;
		REP(i, 10){
			cin >> input;

			if(left >= input && right >= input){
				//両方入らなかったら
				achieve = false;
				break;
			}
			else{
				//どっちかにしか入らない場合
				if(left >= input || right >= input){
					//入る方探して入れる
					if(input > left){
						left = input;
					}
					else if(input > right){
						right = input;
					}
				}
				//どっちにも入る場合
				else{
					//先に入ってる数字が大きい方に入れる
					if(left > right){
						left = input;
					}
					else{
						right = input;
					}
				}
			}
		}
		cout << (achieve ? "YES" : "NO") << endl;
	}
	return 0;
}

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

int main() {
	int a, n, j;
	bool d;
	vector<int> b, c;

	cin >> n;
	for (int i = 0; i < n; i++) {
		for (j = 0; j < 11; j++) {
			if (j == 10) {
				break;
			}
			cin >> a;
			if (j == 0) {
				b.push_back(a);
			}
			else if (a - 1 != b[b.size() - 1] && c.size() == 0) {
				c.push_back(a);
			}
			else if (a - 1 == b[b.size() - 1]) {
				b.push_back(a);
			}
			else if (a - 1 == c[c.size() - 1]) {
				c.push_back(a);
			}
			else {
				break;
			}
		}
		if (j == 10) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}

C++: #include <iostream>

using namespace std;

int N;
int a[10];

bool dfs(int left, int right, int next)
{
	if(next >= 10) return true;
	
	bool ret1 = false, ret2 = false;
	if(left < a[next]) ret1 = dfs(a[next], right, next+1);
	if(right < a[next]) ret2 = dfs(left, a[next], next+1);
	
	return ret1 || ret2;
}

int main(void)
{
	cin >> N;
	for(int i = 0; i < N; i++){
		
		for(int j = 0; j < 10; j++) cin >> a[j];
		bool ans = dfs(0, 0, 0);
		
		if(ans) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	
	return 0;
}