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 arr[10],used[10];
void DFS(int pre,int cur)
{
   if(cur<10&&arr[pre]<arr[cur])
   {
	   used[cur]=1;
	   DFS(cur,cur+1);
   }
   else if(cur<10&&arr[pre]>=arr[cur])
	   DFS(pre,cur+1);
}
int main()
{
   int T,pre;
   bool judge;
   cin>>T;
   while(T--)
   {
     for(int i=0;i<10;i++)
		 cin>>arr[i];
	 for(int i=0;i<10;i++)
	 {
		 memset(used,0,sizeof(used));
		 used[i]=1;
	     DFS(i,i+1);
		 judge=false;
		 pre=0;
	     for(int j=0;j<10;j++)
		    if(used[j]==0)
				if(pre>=arr[j])
			{
				judge=true;
				break;
			}else pre=arr[j];
		 if(!judge)
		 {
			 cout<<"YES"<<endl;
			 break;
		 }
	 }
	 if(judge)cout<<"NO"<<endl;
   }

}

C++: #include <bits/stdc++.h>
using namespace std;

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

int a[10];

bool dfs(int n, int l, int r) {
  if (n >= 10) return true;
  if (l < a[n]) if (dfs(n+1, a[n], r)) return true;
  if (r < a[n]) if (dfs(n+1, l, a[n])) return true;
  return false;
};

int main() {
  int N;
  cin >> N;
  rep(i, 0, N) {
    rep(j, 0, 10) {
      cin >> a[j];
    }
    if (dfs(0, -1, -1)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }

  return 0;
};

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		int a=0, b=0, c[15]={0};
		int flag = 0;
		int tmp = 0;
		for(int k =0;k<10;k++){
			cin >> c[k];
		}
		for(int k =0;k<10;k++){
			if(c[k]>a){
				if(c[k]>b){
					b=c[k];
				}
				else{
					a=c[k];
				}
			}
			else{
				flag = 1;
				break;
			}	
		}
		if(flag)cout << "NO"<<endl;
		else cout << "YES"<<endl;
		
	}
	
}

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

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

C++: #include<iostream>
#include<queue>
using namespace std;
int main(void){
	int num;
	queue<int> qu;
	int a,b;
	int n;

	cin>>n;
	while(n--){
		for(int i=0;i<10;i++){//ツボツーツδ仰づーツ詰ツづ淞づゥ
			cin>>num;
			qu.push(num);
		}
		a=0;
		b=0;
		while(1){
			if(a < qu.front()){
				a=qu.front();
			}else if(b < qu.front()){
				b=qu.front();
			}else{
				cout<<"NO"<<endl;
				break;
			}
			qu.pop();
			if(qu.empty()==true){
				cout<<"YES"<<endl;
				break;
			}
		}
	}
	return 0;
}

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

const int MAX_N = 10;
int a[MAX_N];

bool dfs(int idx, int end1, int end2) {
    if (idx+1 == MAX_N) return true;
    if (a[idx] < end1 && a[idx] < end2) return false;
    if (a[idx] > end1 && a[idx] > end2) return dfs(idx+1, a[idx], end2) || dfs(idx+1, end1, a[idx]);
    if (a[idx] > end1) return dfs(idx+1, a[idx], end2);
    if (a[idx] > end2) return dfs(idx+1, end1, a[idx]);
    return false;
}

int main() {
    int T;
    cin >> T;
    while (T--) {
        for (int i = 0; i < MAX_N; i++)
            cin >> a[i];
        bool flag = dfs(0, 0, 0);
        if (flag) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <vector>
#include <set>
#include <cmath>
#include <map> 
#include <iostream>
#include <cctype>
#include <utility> // 包含pair 
using namespace std;
typedef long long LL;
const int MAXN = 10 + 10;
int a[MAXN];
stack<int> s1, s2; // 建立两个栈，用于模拟小球进栈的过程
// 当前第idx个元素 
bool dfs(int idx) {
	if (idx == 10) {
		return true; // 所有元素都遍历完了(思考这里是true还是false) 应该是true 
	}
	if (s1.empty() || a[idx] > s1.top()) {
		s1.push(a[idx]);
		if (dfs(idx + 1)) {
			s1.pop(); // 回溯
			return true; 
		}
	}
	if (s2.empty() || a[idx] > s2.top()) {
		s2.push(a[idx]);
		if (dfs(idx + 1)) {
			s2.pop();
			return true;
		}
	}
	return false; // 都不满足则返回假 
}

int main() {
	// ios::sync_with_stdio(false);
	int T;
	scanf("%d", &T);
	while (T--) {
		// while (!s1.empty()) s1.pop();
		// while (!s2.empty()) s2.pop(); 如果是回溯法的话，其实不需要这两行 
		for (int i = 0; i < 10; i++) {
			scanf("%d", &a[i]);
		}
		if (dfs(0)) printf("YES\n");
		else printf("NO\n");
	}
	
    return 0;
}

C++: #include <iostream>

using namespace std;
const int kBalln = 10;
int main(){
  int n;
  int ball;
  int b, c;
  bool ans;
  cin >> n;
  for (int j = 0; j < n; ++j)
    {
      b = 0; c = 0;ans = true;
      for (int i = 0; i < kBalln; ++i)
        {
          cin >> ball;
          if (b < ball)
            {
              b = ball;
            }
          else if (c < ball)
            {
              c = ball;
            }
          else
            {
              // cout << "NO" << endl;
              break;
            }
        }
      cout << (ans ? "YES" : "NO") << endl;
    }
  return 0;
}

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

int boal[10];

bool dfs(int b,int c, int time)
{
	if(time >= 10)
		return true;
	
	if(boal[time] > b && dfs(boal[time], c, time + 1))
		return true;
	
	if(boal[time] > c && dfs(b, boal[time], time + 1))
		return true;
	
	return false;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	
	while(n > 0){
		for(int i = 0; i != 10; ++i)
			cin >> boal[i];
		
		if(dfs(0, 0, 0))
			cout << "YES";
		else
			cout << "NO";
		cout << endl;
		
		n--;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
bool DFS(int t_b,int t_c,int th,int* balls){
  if(th==10)return true;
  if(t_b<balls[th]&&t_c<balls[th])
      if(t_b>t_c)return DFS(balls[th],t_c,th+1,balls);
      else return DFS(t_b,balls[th],th+1,balls);
  else if(t_b<balls[th])return DFS(balls[th],t_c,th+1,balls);
  else if(t_c<balls[th])return DFS(t_b,balls[th],th+1,balls);
  else return false;
}
int main(){
  int n;
  cin>>n;
  for(int j=0;j<n;j++){
    int balls[10];
    for(int i=0;i<10;i++)cin>>balls[i];
    int t_b=0,t_c=0;int drop_balls=0;
    if(DFS(0,0,0,balls))cout<<"YES";
    else cout<<"NO";
    cout<<endl;
  }
}