Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	for i := 0; i < n; i++ {
		a := -1
		b := -1
		ans := true
		// それぞれの筒の一番上にあるたまの数字に着目すればよい
		for j := 0; j < 10; j++ {
			x := nextInt()
			if x > a {
				a = x
			} else if x > b {
				b = x
			} else {
				ans = false
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

C++: #include <stdio.h>

int
main(void)
{
	char line[80];

	int b[10];

	int n;

	if (fgets(line, sizeof line, stdin) == NULL) {
		return 0;
	}
	if (sscanf(line, "%d", &n) != 1) {
		return 0;
	}

	while (n--) {
		fgets(line, sizeof line, stdin);
		sscanf(line, "%d %d %d %d %d %d %d %d %d %d",
			   &(b[0]), &(b[1]), &(b[2]), &(b[3]), &(b[4]), &(b[5]),
			   &(b[6]), &(b[7]), &(b[7]), &(b[9]));

		bool f = true;
		int s0 = 0;
		int s1 = 0;
		for (int t : b) {
			if (t > s0 && t > s1) {
				if (t - s0 <= t - s1) {
					s0 = t;
				} else {
					s1 = t;
				}
			} else 	if (t > s0) {
				s0 = t;
			} else 	if (t > s1) {
				s1 = t;
			} else {
				f = false;
				break;
			}
		}
		printf("%s\n", (f ? "YES" : "NO"));
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
 
int b[10];
  
bool dfs(int i,int j,int k){
  if(k==10)
    return true;
  if(i<b[k]){
    if(dfs(b[k],j,k+1))return true; 
  }
  if(j<b[k]){
    if(dfs(i,b[k],k+1))return true;
  }
  return false;
}
 
int main(){
  int a;
  cin >> a;
  while(a>0){
    for(int i=0;i<10;i++){
      cin >> b[i];
    }
    int p=dfs(0,0,0);
    if(p!=0)
      cout << "YES" << endl;
    else
      cout << "NO" <<endl;
    a--;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#include <map>
#include <sstream>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
using namespace std;

int ball[10];

bool dfs(int b, int c, int k){
	if (k >= 10) return true;
	if (b > ball[k] && c > ball[k]) return false;
	if (b < ball[k] && c > ball[k]) return dfs(ball[k], c, k+1);
	if (b > ball[k] && c < ball[k]) return dfs(b, ball[k], k+1);
	return dfs(ball[k], c, k+1) || dfs(b, ball[k], k+1);
}

int main(){
    int n;
    cin >> n;
    REP(i, n){
    	REP(j, 10){
    		cin >> ball[j];
    	}
    	if (dfs(0, 0, 0)) cout << "YES" << endl;
    	else cout << "NO" << endl;
    }
}

C++: #include <map>
#include <set>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <iostream>
#include <algorithm>
using namespace std;
bool flag;
int ball[15];
bool dfs(int x, int l, int r){
    if(ball[x] > l){
        if(x == 9) return true;
        if(dfs(x+1, ball[x], r)) return true;
    }
    if(ball[x] > r){
        if(x == 9) return true;
        if(dfs(x+1, l, ball[x])) return true;
    }
    return false;
}
int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    while(n--){
        for(int i = 0; i < 10; ++i) cin >> ball[i];
        bool flag = dfs(0, 0, 0);
        cout << (flag ? "YES" : "NO") << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
const int NUM=15;
int num[NUM];
bool vis[NUM];
void dfs(int i);
int main()
{
    int test;
    scanf("%d",&test);
    while(test--)
    {
        int ans=0;
        memset(vis,0,sizeof vis);
        for (int i=0; i<10; i++)
            scanf("%d",&num[i]);
        /*for (int i=0; i<10; i++)
        {
            if (!vis[i])
            {
                vis[i]=1;
                ans++;
                dfs(i);
            }
        }
        if (ans==1||ans==2)
            printf("YES\n");
        else
            printf("NO\n");*/
        int l=0,r=0,flag=1;
        for(int j=0; j<10; j++)
        {
            if(l<num[j])l=num[j];
            else if(r<num[j])r=num[j];
            else flag=0;
            if(flag==0)break;
        }
        if(flag)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}
/*void dfs(int i)
{
    for (int j=i+1; j<10; j++)
    {
        if (!vis[j]&&num[j]>=num[i])
        {
            vis[j]=1;
            dfs(j);
        }
    }
}*/

C++: #include<iostream>

using namespace std;
int balls[11];
bool res;
int n;

bool dfs(int left, int right,int i){
        if(i==9) return balls[left]<balls[i] || balls[right] < balls[i];
        if(balls[i] > balls[left]) return dfs(i, right, i+1);
        else if(balls[i] > balls[right]) return dfs(left, i, i+1);
        else return false;
}

void solve(){
        for (int i = 0; i < 10; ++i) {
                cin >> balls[i];

        }
        balls[10] = -1;
        res = dfs(10,10,1);
        if(res){
                cout << "YES" << endl;
        }else{
                cout << "NO" << endl;
        }
}

int main(){
        ios_base::sync_with_stdio(false);
        cin >> n;
        for (int i = 0; i < n; ++i) {
                solve();
        }
        return 0;
}

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

int main(){
	int num;
	cin>>num;
	int error=0;
	for(int x=0;x<num;x++){
		error=0;
		queue<int> A;
		vector<int> B;
		vector<int> C;
		for(int i=0;i<10;i++){
			int nn;
			cin>>nn;
			A.push(nn);
		}
		C.push_back(0);
		for(int i=0;i<A.size();i++){
			if(i==0){
				B.push_back(A.front());
				A.pop();
				continue;
			}
			if(A.front()>B.back()){
				B.push_back(A.front());
				A.pop();
			}else if(A.front()>C.back()){
				C.push_back(A.front());
				A.pop();
			}else{
				error=1;
				break;
			}
		}
		if(error==0)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

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

bool solver(queue<int> q, int a, int b){
    bool result = false;
    if(q.empty()) {
        return true;
    }
    int tmp = q.front();
    if(tmp > a){
        q.pop();
        result = solver(q, tmp, b);
        q.push(tmp);
    }
    if(result) return true;
    tmp = q.front();
    if(tmp > b){
        q.pop();
        result = solver(q, a, tmp);
        q.push(tmp);
    }
    if(result) return true;
    return false;
}

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

    for(int i=0; i<n; i++){
        queue<int> q;
        for(int j=0; j<10; j++){
            int tmp;
            cin >> tmp;
            q.push(tmp);
        }
        cout << (solver(q,0,0)?"YES":"NO") << endl;
    }
    return 0;
}