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<string>
using namespace std;
int main(){
	int n,a[10];
	cin>>n;
	for(int i=0;i<n;i++){
		bool t=true;
		for(int j=0;j<10;j++)
			cin>>a[i];
		for(int j=0;j<8;j++){
			if(a[j]>a[j+2]&&a[j+1]>a[j+2])
				t=false;
		}
		if(t==true)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}

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

int ma[11];
int a[11];int b[11];

bool ch;

int dx[]={1,0,0,-1};
int dy[]={0,-1,1,0};

void dfs(int deep,int aa,int bb)
{
    if(ch)return ;
    if(deep==10)
    {
        ch=true;
        return ;
    }


    if(ma[deep]>a[aa-1])
    {
        a[aa]=ma[deep];
        dfs(deep+1,aa+1,bb);
    }

    if(ch==false&&ma[deep]>b[bb-1])
    {
        b[bb]=ma[deep];
        dfs(deep+1,aa,bb+1);
    }

}


int main()
{
    int f;
    scanf("%d",&f);
    while(f--)
    {
        ch=false;
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for(int i=0;i<10;i++)
            scanf("%d",&ma[i]);
        dfs(0,1,1);
        if(ch)
            printf("YES\n");
        else
            printf("NO\n");
    }


}

C++: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i,n)   for (int i = 0; i < (n); ++i)
#define SORT(a)    sort((a).begin(), (a).end());
#define UNIQ(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define FIND(a,x)  find((a).begin(), (a).end(), (x)) != (a).end()
#define REVERSE(a) reverse((a).begin(), (a).end());

using namespace std;
using ll = long long;
using P = pair<int,int>;

const int MOD = 1000000007; // 10^9 + 7

int a[10];

bool dfs(int i, int b, int c) {
  if (i == 10) return true;

  if (a[i] > b && dfs(i + 1, a[i], c)) return true;
  if (a[i] > c && dfs(i + 1, b, a[i])) return true;
  return false;
}

bool solve() {
  return dfs(0, -1, -1);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n; cin >> n;
  REP(i, n) {
    REP(j, 10) cin >> a[j];
    cout << (solve() ? "YES" : "NO") << endl;
  }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl

int main() {
	lint N;
	cin >> N;
	rep(t, N) {
		bool yes = true;
		vector<lint>A(10);
		rep(i, 10) {
			cin >> A[i];
		}
		deque<lint>B;
		deque<lint>C;
		B.push_front(0);
		C.push_front(0);
		rep(i, 10) {
			if (i == 0) {
				B.push_front(A[i]);
			}
			else {
				if (B.front() < A[i] && A[i] < C.front()) {
					B.push_front(A[i]);
				}
				else if (C.front() < A[i] && A[i] < B.front()) {
					C.push_front(A[i]);
				}
				else if (B.front() < A[i] && C.front() < A[i]) {
					if (B.front() > C.front()) {
						B.push_front(A[i]);
					}
					else {
						C.push_front(A[i]);
					}
				}
				else {
					cout << "NO" << endl;
					yes = false;
					break;
				}
			}
		}
		if (yes == true) {
			cout << "YES" << endl;
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to) 
void dfs(stack<int> s, stack<int> r, stack<int> l, bool &f) {
	if(s.empty()) {
		f = 1;
		return;
	}
	int x = s.top();
	if(r.empty() || r.top() < x) {
		s.pop();
		r.push(x);
		dfs(s,r,l,f);
		r.pop();
		s.push(x);
	}
	if(l.empty() || l.top() < x) {
		s.pop();
		l.push(x);
		dfs(s,r,l,f);
		l.pop();
		s.push(x);
	}
}
int main() {
	int n;
	cin >> n;
	while(n--) {
		int a[10];
		stack<int> s;
		rep(i,10) {
			cin >> a[i];
		}
		rep(i,10) {
			s.push(a[10-i-1]);
		}
		stack<int> r;
		stack<int> l;
		bool f = 0;
		dfs(s,r,l,f);
		if(f) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

int main(){
  int n;
  int a[10];
  cin>>n;
  while(n--){
    for(int i=0;i<10;i++) cin>>a[i];
    for(int i=0;i<8;i++){
      if(a[i]>a[i+1]&&a[i]>a[i+2]&&a[i+1]>a[i+2]){
	cout<<"NO"<<endl;
	break;
      }
      if(i==7) cout<<"YES"<<endl;
    }
  }
  return 0;
}

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

int pow(int a,int n){
	if(n <= 0){
		return 1;
	}
	return a * pow(a,n - 1);
}

int main(){
	int n;
	int a[10];
	int ans1 = 0;
	int ans2 = 0;
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			scanf("%d",&a[j]);
		}
		for(int j = 0; j < 10; j++){
			if(ans1 >= ans2 && ans1 < a[j]){
				ans1 = a[j];
			}else if(ans2 > ans1 && ans2 < a[j]){
				ans2 = a[j];
			}else if(ans1 < a[j]){
				ans1 = a[j];
			}else if(ans2 < a[j]){
				ans2 = a[j];
			}else{
				printf("NO\n");
				break;
			}
			if(j == 9){
				printf("YES\n");
			}
		}
	}
	///////////////////////////////////
	//Sleep(200000);///////////////////// 提出するときは必ず外す！
	///////////////////////////////////
	return 0;

}

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

int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    int a, b = 0, c = 0;
    bool f = true;
    for (int i = 0; i < 10; ++i) {
      scanf("%d", &a);
      if (b < a) b = a;
      else if (c < a) c = a;
      else {
        puts("NO");
        f = false;
        break;
      }
    }
    if (f) puts("YES");
  }
}

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

using namespace std;

int main(){

	int n;
	cin>>n;

	int B=0,C=0;
	for(int i = 0; i < n; i++){
		bool f=false;
		for(int j = 0; j < 10; j++){
			int num;
			cin>>num;
			if(num>B&&num>C){
				if(num-B>num-C){
					C=num;
				}
				else
					B=num;
			}
			else if(num>B){
				B=num;
			}
			else if(num>C)
				C=num;
			else if(!f){
				f=true;
				cout<<"NO"<<endl;
//				break;
			}
		}
		if(!f)
			cout<<"YES"<<endl;
	}

	return 0;
}

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

int ball[10];

bool solve(int i, int a, int b){
	if (i == 10) return true;
	bool ans = false;
	if (a < ball[i]) ans = solve(i + i, ball[i], b);
	if (b < ball[i])ans = solve(i + i, a, ball[i]);
	return ans;
}

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

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

	return 0;
}
//beatmaniaIIDX 23th copula