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 <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
    int N,pre,current,second_pre;
    bool NO_FLG;

    scanf("%d",&N);
    for(int i=0;i<N;i++){
        pre = -1;
        second_pre = -1;
        NO_FLG = false;
        for(int k = 0; k < 10; k++){
            scanf("%d",&current);	//????????????????????????
            if(k == 0){	//??????????????????????????´?????????????????????
                pre = current;
            }else{
                if(pre > current){	//1?????????????????????????????§????????´???,current?????????1????????????????§????
                    if(second_pre == -1){	//?°?????????°????????\?????????????§????
                        second_pre = current;
                        NO_FLG = true;
                    }else{
                        if(second_pre > current){
                            printf("NO\n");
                            NO_FLG = true;
                            break;
                        }else{
                            second_pre = current;
                            NO_FLG = false;
                        }
                    }
                }else{ //pre < current
                	pre = current;
                }
            }
        }
        if(!NO_FLG)printf("YES\n");

    }
    return 0;
}

C++: #include <stack>
#include <cstdio>
using namespace std;
  int main(){
    int k,n,i,j,x[10];
    scanf("%d",&n);
for(k=0;k<n;k++){
    for(i=0;i<10;i++){
       scanf("%d",&x[i]);
}
stack<int> B;
stack<int> C;
B.push(x[0]);
for(i=1;i<=9;i++){
if(x[i-1]>x[i]){
C.push(x[i]);
goto ccc;
}else{
	B.push(x[i]);
	goto bbb;
}
bbb:;
}
ccc:
for(j=i;j<9;j++){
if(B.top()<x[j+1]){
B.push(x[j+1]);
}else if(C.top()<x[j+1]){
	C.push(x[j+1]);
}else{
	printf("NO\n");
	goto aaa;
}
}
printf("YES\n");
aaa:;
}
return 0;
  }

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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  cin >> n;
  while(n--) {
    int a[10];
    REP(i,10) {
      cin >> a[i];
    }
    int i;
    for (i=0; i<(1<<10); i++) {
      int s=0,t=0;
      int j;
      for (j=0; j<10; j++) {
        if (1&(i>>j)) {
          if (a[j]>s)
            s=a[j];
          else
            break;
        } else {
          if (a[j]>t)
            t=a[j];
          else
            break;
        }
      }
      if (j==10) break;
    }
    if (i!=(1<<10))
      cout << "YES" << endl;
    else
      cout <<"NO" <<endl;
  }
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;

int main(){
	int i,j,N,ball;
    cin>>N;
    for(i=0;i<N;i++){
		int ri=0,le=0,flg=0;
		for(j=0;j<10;j++){
			cin>>ball;
			if(ri<ball){
				ri=ball;
			}else if(le<ball){
				le=ball;
			}else{
				flg=1;
			}
		}		
		if(flg==0){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
    }
    return 0;
}

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

using namespace std;

const int BALL_NUM = 10;

static bool
judge_ball(const vector<int> &ball, const int right_head, const int left_head, const int fall_ball) {

	if (10 <= fall_ball) {
		return true;
	}

	if (right_head < ball.at(fall_ball)) {
		if (true == judge_ball(ball, ball.at(fall_ball), left_head, fall_ball + 1)) {
			return true;
		}
	}
	if(left_head < ball.at(fall_ball)) {
		if (true == judge_ball(ball, right_head, ball.at(fall_ball), fall_ball + 1)) {
			return true;
		}
	}

	return false;
}

int main(void) {
	// input
	int data_num;
	cin >> data_num;
	vector<vector<int>> ball_set(data_num, vector<int>(10,0));
	for (int i = 0; i < data_num; i++) {
		for (int j = 0; j < BALL_NUM; j ++) {
			cin >> ball_set.at(i).at(j);
		}
	}

// judge true or false
for (int i = 0; i < data_num; i ++) {
	// int right_head = ball_set.at(i).at(0)
	// int left_head = 0;
	// int fall_ball = 1;

	if (true == judge_ball(ball_set.at(i), ball_set.at(i).at(0), 0, 1)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

return 0;
}

C++: #include <iostream>
// #include <algorithm>

using namespace std;

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

    if(balls[i] > left && dfs(i+1, balls[i], right, balls))
        return true;

    if(balls[i] > right && dfs(i+1, left, balls[i], balls))
        return true;

    return false;
}

int main() {
    int N;
    int balls[10];
    cin >> N;
    while(N-- > 0) {
        for(int i = 0; i < 10; i++)
            cin >> balls[i];

        if(dfs(1, balls[0], 0, balls))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main(){
  stack<int>a;
  stack<int>b;
  int n,m,s;
  cin>>n;
  for(int i=0;i<n;i++){
    s=0;
    a.push(0);
    b.push(0);
    for(int i=0;i<10;i++){
      cin>>m;
      if(m>a.top()){
	a.push(m);
      }
      else if(m>b.top()){
	b.push(m);
      }
      else s=1;
    }
    if(s==0)cout<<"YES"<<endl;
    else    cout<<"NO"<<endl;
  }
  return 0;
}

C++: #include <iostream>

int main(void)
{
	int n;
	std::cin >> n;
	for(int j=0; j<n; j++)
	{
		int top[2]={0,0};
		for(int i=0; ; i++)
		{
			int next;
			std::cin >> next;
			if((top[0] < next)&&(top[1] < next))
			{
				if(top[0] < top[1])
					top[1]=next;
				else
					top[0]=next;
			}
			else if(top[0] < next)
				top[0]=next;
			else if(top[1] < next)
				top[1]=next;
			else
			{
				std::cout << "NO" << std::endl;
				break;
			}

			if(i==9)
			{
				std::cout << "YES" << std::endl;
				break;
			}
		}
	}
	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<unordered_map>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-8
#define REP(i, m) for(long long i=0; i<m; ++i)
#define FOR(i, n, m) for(long long i=n; i<m; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<ll> vl;
typedef vector<vector<ll> > vll;

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	REP(roop,n) {
		vector<int> num(10);
		REP(i,10) cin>>num[i];
		bool d=false;
		REP(bit,(1<<10)) {
			vector<bool> used(10,false);
			ll buf=bit;
			REP(i,10) {
				if(buf%2==1) used[i]=true;
				buf/=2;
			}
			bool e=true;
			int an=0,bn=0;
			REP(i,10) {
				if(used[i]) {
					if(an>num[i]) e=false;
					an=num[i];
				} else {
					if(bn>num[i]) e=false;
					bn=num[i];
				}
			}
			d=d|e;
		}
		if(d) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}