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>
#include <vector>
#include <string>
#include <stack>
#include <cmath>
#include <algorithm>
using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main() {
  int n; cin >> n;
  while(n--) {
    stack<int> sta[2];
    vi a(10); rep(i, 10) cin >> a[i];
    bool b = true;
    rep(i, 10) {
      int x = a[i];
      if(i == 0) sta[0].push(x);
      else if(sta[1].empty()) {
        if(sta[0].top() < x) sta[0].push(x);
        else sta[1].push(x);
      } else {
        if(sta[0].top() > x && sta[1].top() > x) {
         b = false;
         break;
        } else if(sta[0].top() > sta[1].top()) {
          if(sta[0].top() < x) sta[0].push(x);
          else sta[1].push(x);
        } else {
          if(sta[1].top() < x) sta[1].push(x);
          else sta[0].push(x);
        }
      }
    }
    if(b) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

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

using namespace std;

int main(){
  int f;
  int n;
  int in,b,c;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    f=b=c=0;
    for(int j=0;j<10;j++){
      scanf("%d",&in);
      if(in<=min(b,c)){
	f=1;
	break;
      }
      if((b>=c && b<in)||(b<c && c>in))b=in;
      else c=in;
    }
    if(f)printf("NO\n");
    else printf("YES\n");
  }
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
#define Vi vector<int>
#define Vl vector<long long>
#define pb(a) push_back(a)

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct edge{int to,cost;};
struct pos{
	int x,y;
};

int main() {

	int n;
	cin>>n;
	rep(i,n){
		ll a=0,b=0,f=0;
		rep(j,10){
			ll x;
			cin>>x;
			if(f==1)continue;
			if(x<a&&x<b)f=1;
			else if(x>max(a,b)){
				if(a>b)a=x;
				else b=x;
			}else{
				if(a>b)b=x;
				else a=x;
			}
		}
		if(f==0)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>

using namespace std;

int s[10]={0};

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        for(int i=0;i<10;i++)
            scanf("%d",&s[i]);
        int a=0;
        int b=0;
        bool flag=0;
        for(int i=0;i<10;i++)
        {
            if(s[i]<a&&s[i]<b)
            {
                flag=1;
                break;
            }
            else if(s[i]<a&&s[i]>b)b=s[i];
            else if(s[i]>a&&s[i]<b)a=s[i];
            else
            {
                a=a>b?s[i]:a;
                b=a<b?s[i]:b;
                if(a==b)a=s[i];
            }
        }
        if(flag)printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int check(int cc[10])
{
    int temp,z=0,x=0;
    for(int i=0;i<10;i++){
	if(cc[i]<x)return 10;
	else if(cc[i]>z)z=cc[i];
	else if(cc[i]<z&&cc[i]>x)x=cc[i];
    }
    return 1;
}

int main()
{
    int log,N,bb[10];
    cin>>N;    
    for(int i=0;i<N;i++){
    	for(int k=0;k<10;k++)cin>>bb[k];
    	log=check(bb);
	if(log==10)cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
    }
    return 0;
}

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

int a[10];

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

int main() {
	int N;
	scanf("%d", &N);
	for (; N > 0; N--) {
		for (int i = 0; i < 10; i++)
			scanf("%d", &a[i]);
		printf(dfs(0, 0, 0) ? "YES\n" : "NO\n");
	}
}

C++: #include <iostream>

using namespace std;

int main( void )
{
	int n, input[10], stA[11], stB[11];
	cin >> n;
	while(n--) {
		for(int i=0; i < 10; ++i) {
			stA[i] = stB[i] = 0;
			cin >> input[i];
		}
		int idxI, idxA, idxB;
		idxI = 2; idxA = idxB = 0;
		stA[0] = input[0];
		if(stA[0] < input[1]) {
			stA[1] = input[1];
			idxA = 1;
		}
		else {
			stB[0] = input[1];
		}
		bool hit = true;
		while(10 > idxI && hit) {
			int tmp = input[idxI];
			if(stB[idxB] < stA[idxA]) { // A
				if(stA[idxA] < tmp) stA[++idxA] = tmp;
				else if(stB[idxB] < tmp) stB[++idxB] = tmp;
				else hit = false;
			}
			else {	// B
				if(stB[idxB] < tmp) stB[++idxB] = tmp;
				else if(stA[idxA] < tmp) stA[++idxA] = tmp;
				else hit = false;
			}
			++idxI;
		}
		if(idxI == 10 && hit)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

C++: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    input.readLine();
    while (input.ready())
    {
      String[] INPUT_STR = input.readLine().split(" ");

      System.out.println(solver(INPUT_STR));
    }

  }

  private static String solver(String[] array)
  {
    int currentA = 0;
    int currentB = 0;
    int currentC = 0;

    for (int i = 0; i < array.length; i++)
    {
      currentA = Integer.parseInt(array[i]);
      if (i % 2 == 0)
      {
        if (currentB > currentA)
        {
          return "NO";
        }
        currentB = currentA;
      }
      else
      {
        if (currentC > currentA)
        {
          return "NO";
        }
        currentC = currentA;
      }
    }
    return "YES";
  }

}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<map>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

bool memo[11][11];
int data[10];

bool ans(int p, int b, int c){
  if(memo[b][c]) return false;
  if(p == 10) return true;
  int d = data[p];
  if(b < d && ans(p+1, d, c)) return true;
  if(c < d && ans(p+1, b, d)) return true;
  memo[b][c] = true;
  return false;
}

int main(){
  int n;
  scanf("%d",&n);
  while(n --> 0){
    memset(memo,0,sizeof(memo));
    REP(i,10) scanf("%d",&data[i]);
    puts(ans(0,0,0)?"YES":"NO");
  }
  return 0;
}