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<iostream>
using namespace std;
int main(){
  int n;
  int a[10];
  int b[6];
  int c[6];
  int k=0;
  int k2=0;
  int out=0;
  cin>>n;
  b[0]=0;
  c[0]=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>a[j];
      if(b[k]<a[j] ){
	b[k+1]=a[j];
	k++;
      }
      else if(c[k2]<a[j]){
	c[k2+1]=a[j];
	k2++;
      }
      else{
	out=1;
      }
    }
    if(out==0) cout << "YES" << endl;    
    else if(out==1) cout << "NO" <<endl;
  }
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
	int a,b;
	int n;
	int g;
	bool check;

	while(cin >> n){
		vector<int> ball;
		a = b = 0;
		check = true;
		rep(i,10){
			cin >> g;
			ball.insert( ball.begin(), g);
		}
		rep(i,10){
			if(a < ball.back()){
				a = ball.back();
				ball.pop_back();
			}else if(b < ball.back()){
				b = ball.back();
				ball.pop_back();
			}else{
				check = false;
			}
		}
		if(check) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

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<stdio.h>
#include<stack>
using namespace std;
stack<int>ss;
stack<int>ss2;
int main()
{
	int t,n,a;
	scanf("%d",&t);
	while (t--)
	{
		n=10;
		int f=0;
		while(n--)
		{
			scanf("%d",&a);
			if (f==0)
			{
				if (ss.empty())
				{
					ss.push(a);
				}
				else if (ss.top()<a)
				{
					ss.push(a);
				}
				else if (ss2.empty())
				{
					ss2.push(a);
				}
				else if (ss2.top()<a)
				{
					ss2.push(a);
				}
				else
				{
					f=1; 
				}
			}
		}
		if (f==1)
		{
			printf("NO\n");
		}
		else
		{
			printf("YES\n");
		}
	}
	return 0;
}

C++: import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		int n=sc.nextInt();
		sc.nextLine();
		for(int k=0; k<n; k++){
			String[] ss=sc.nextLine().split(" ");
			int[] a=new int[10];
			for(int i=0; i<10; i++)
				a[i]=Integer.parseInt(ss[i]);
			int x=0;
			for(int i=0; i<10; i++){
				if(a[i]>x){
					x=a[i];
					a[i]=-1;
				}
			}
			x=0;
			for(int i=0; i<10; i++){
				if(a[i]>x){
					x=a[i];
					a[i]=-1;
				}
			}
			boolean f=true;
			for(int i=0; i<10; i++)
				if(a[i]!=-1){
					f=false;
					break;
				}
			println(f?"YES":"NO");
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int b = 0, c = 0;
		int flag = 1;
		for (int j = 0; j < 10; j++){
			int k;
			cin >> k;
			if (b < k && c < k) {
				if (b > c) {
					b = k;
				} else {
					c = k;
				}
			} else if (b < k && c >= k) {
				b = k;
			} else if (b >= k && c < k) {
				c = k;
			} else{
				flag = 0;
				break;
			}
		}
		if (flag) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>


int N;
int a[100];
int left[100], right[100], flag;
int main()
{
    scanf("%d", &N);

   while(N--){

        for(int j = 0; j < 10; j++) scanf("%d", &a[j]);

        for(int j = 0; j < 1<<10; j++)
        {
            int l = 0, r = 0;
            flag = 1;
            for(int k = 1, x = 0; k < 1<<10; k<<=1, x++)
            {
                if(j & k)  left[l++] = a[x];
                else   right[r++] = a[x];

                if((l >= 2 && left[l-1] <= left[l-2]) ||(r >= 2 && right[r-1] <= right[r-2]))
                {
                    flag = 0;
                    break;
                }
            }

            if(flag) break;

        }
        if(flag) printf("YES\n");
        else printf("NO\n");
    }

    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

vector<int> a;
stack<int> b, c;

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

	bool res1 = false, res2 = false;

	if (b.empty()) {
		b.push(a[i]);
		res1 = dfs(i + 1);
		b.pop();
    }
    
    if(c.empty()) {
		c.push(a[i]);
		res2 = dfs(i + 1);
		c.pop();
    } 

    if (b.size() && c.size()) {
        if (b.top() < a[i]) {
            b.push(a[i]);
            res1 = dfs(i + 1);
            b.pop();
        }
        if (c.top() < a[i]) {
            c.push(a[i]);
            res2 = dfs(i + 1);
            c.pop();
        }
    }

	return res1 || res2;
}

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

	while (n--) {
		a.clear();
		while (b.size()) b.pop();
		while (c.size()) c.pop();

		for (int i = 0; i < 10; ++i) { int v; cin >> v; a.push_back(v); }

		if (dfs(0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

C++: #include <iostream>

using namespace std;

int caseCnt, numbers[10], curNum;
bool used[10], result;

int main(){
    cin >> caseCnt;

    while(caseCnt--){
        result = true;

        for(int i=0; i<10; ++i){
            cin >> numbers[i];
            used[i] = false;
        }
        curNum = numbers[0];
        used[0] = true;
        for(int i=1; i<10; ++i){
            if(numbers[i] > curNum){
                curNum = numbers[i];
                used[i] = true;
                //cout << "fk\n";
            }
        }

        bool first_not_used = true;
        for(int i=1; i<10; ++i){
            if(used[i] == false){
                if(first_not_used){
                    first_not_used = false;
                    curNum = numbers[i];
                    //cout << "curNum : " << curNum << endl;
                }else{
                    if(numbers[i] > curNum){
                        curNum = numbers[i];
                    }else{
                        result = false;
                        break;
                    }
                }
            }
        }
        if(result) cout << "YES\n";
        else       cout << "NO\n";
    }
    return 0;
}