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 <queue>
#include <stack>
using namespace std;
stack<int> stal, star;
queue<int> que;
bool dfs();

int main() {
    int n;

    while (cin >> n) {
        int num;
        while (n--) {
            while (!que.empty()) que.pop();
            for (int i = 0; i < 10; i++) {
                cin >> num;
                que.push(num);
            }
            while (!stal.empty()) stal.pop();
            while (!star.empty()) star.pop();
            cout << (dfs() ? "YES" : "NO") << endl;
        }
    }

    return 0;
}

bool dfs() {
    bool flag = true, enter = false;
    if (stal.empty() || stal.top() < que.front()) {
        stal.push(que.front());
        que.pop();
        flag = dfs();
        enter = true;
    }
    if (!flag && !enter) { que.push(stal.top()); stal.pop(); }
    if ((star.empty() || star.top() < que.front()) && (!flag || !enter)) {
        star.push(que.front());
        que.pop();
        dfs();
    }
    if (que.empty()) return true;
    else return false;
}

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

int D, A[10];
const int MAX_DATA = 100000;
bool owata[MAX_DATA];

bool dfs(int n,int a,int b)
{
	if(n==10)
	{
		return true;
	}

	if(A[n]>a){
	if(dfs(n+1,A[n],b))
	{
		return true;
	}
	}

	if(A[n]>b){
	if(dfs(n+1,a,A[n]))
	{
		return true;
	}
	}

	return false;

}

int main(){
	cin>>D;
	for(int i=1;i<=D;i++){
		for(int j=0;j<10;j++){
			cin>>A[j];
		}

		owata[i] = dfs(0, 0, 0);
	}
	for(int i=1;i<=D;i++)
	{
		cout << (owata[i] ? "YES":"NO") << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
  int a=0,b=0;
  int c;
  cin>>c;
  for(int i=0;i<c;i++){
    a=0;
    b=0;
    for(int i=0;i<10;i++){
      int t;
      cin>>t;
      if(t<a&&t<b){
	cout<<"NO"<<endl;
	break;
      }
      if(a<t)a=t;
      else b=t;
      if(i==9)cout<<"YES"<<endl;
    }
  }
  return 0;
}

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

int l[11],r[11],n[11];
int N;
int final;

void dfs(int i,int ll,int rr)
{
	if(i==11)
	{
		final=1;
		return;
	}
	if(n[i]>l[ll-1])
	{
		l[ll]=n[i];
		dfs(i+1,ll+1,rr);
	}
	if(n[i]>r[rr-1])
	{
		r[rr]=n[i];
		dfs(i+1,ll,rr+1);
	}
}

int main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		for(int j=1;j<=10;j++)
		{
			cin>>n[j];
		}
		final=0;
		dfs(1,1,1);//从1开始比0更好 
		if(final)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	
	return 0;
}

C++: /*
P135
POJ 2718 Smallest Difference
*/


#include <iostream>
#include <map>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <functional>
#include <string.h>
using namespace std;

int a[10];
bool read()
{
    for(int i=0; i<10; ++i)
        scanf("%d", a+i);
}

void solve()
{
    int x1=0, x2=0;
    bool ans = true;
    for(int i=0; i<10; ++i)
    {
        if(x1 < x2) swap(x1, x2);
        if(x1 < a[i]) x1 = a[i];
        else if(x2 < a[i]) x2 = a[i];
        else {ans = false; break;}
    }
    if(ans) printf("YES\n");
    else printf("NO\n");
}


//
//vector<int> L_bucket;
//vector<int> R_bucket;
//
//bool dfs2(int d){
//    if(d == 10) return true;
//    bool flag = false;
//    if(L_bucket.size() == 0 || L_bucket.back() < a[d]){
//        L_bucket.push_back(a[d]);
//        flag = dfs2(d+1);
//        L_bucket.pop_back();
//    }
//    if(flag) return true;
//    if(R_bucket.size() == 0 || R_bucket.back() < a[d]){
//        R_bucket.push_back((a[d]));
//        flag = dfs2(d+1);
//        R_bucket.pop_back();
//    }
//    if(flag) return true;
//    return false;
//}
//
//void solve2()
//{
//    if(dfs2(0)) printf("YES\n");
//    else printf("NO\n");
//}

int main()
{
    int T;
    scanf("%d", &T);
    while(T--){
        read();
        solve();
    }
}

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

int main() {
	cin.tie(0);
        ios::sync_with_stdio(false);
	
	int n; cin >> n;
	while(n--){
		int balls[10];
		for(int i = 0; i < 10; i++){
			cin >> balls[i];
		}
		
		bool sortable = false;
		for(int i = 0; i < (1 << 10); i++){
			int bit = i;
			bool ok = true;
			
			int top[2] = {0,0}; //top[0]: B, top[1]: C
			for(int j = 0; j < 10; j++){
				if(top[bit & 1] > balls[j]){
					ok = false; break;
				}
				top[bit & 1] = balls[j];
				bit >>= 1;
			}
			
			if(ok) {
				sortable = true; break;
			}
		}
		
		if(sortable) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

C++: #include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
int arr[10];
bool visited[10];

int main() {
    int n;
    scanf("%d", &n);
    for (int t = 0; t < n; t++) {
        for (int i = 0; i < 10; i++) scanf("%d", &arr[i]);
        memset(visited, 0, sizeof(visited));
        stack<int>st;
        st.push(arr[0]); visited[0] = true;
        for (int i = 1; i < 10; i++) {
            if (arr[i] > st.top()) { st.push(arr[i]); visited[i] = true; }
        }
        if (st.size() >= 9) printf("YES\n");
        else {
            int minv, mini;
            for (int i = 0; i < 10; i++) if (!visited[i]) { minv = arr[i], mini = i; break; }
            bool flag = true;
            for (int i = mini+1; i < 10; i++) {
                if (!visited[i] && arr[i] > minv) { minv = arr[i]; }
                else if (!visited[i] && arr[i] < minv) { flag = false; break; }
            }
            (flag) ? printf("YES\n") : printf("NO\n");
        }
    }
    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <stack>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n;
	cin >> n;
	
	rep(i, n)
	{
		queue<int> a;

		rep(i, 10)
		{
			int in;
			cin >> in;
			a.push(in);
		}


		stack<int> b, c;
		b.push(0);
		c.push(0);

		while(!a.empty())
		{
			// ツ湘ュツづ可つつづ個陛サツつェツ妥・ツつォツつ「
			if(b.top() < c.top()) swap(c, b);

			if(b.top() < a.front())
			{
				b.push(a.front());
				a.pop();
			}
			else if(c.top() < a.front())
			{
				c.push(a.front());
				a.pop();
			}
			else break;
		}

		cout << (a.empty() ? "YES" : "NO") << endl;
	}
}