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 <cstdio>
#include <algorithm>

using namespace std;

const int BALL_NUM = 4;

long n;

bool IsLeft(int num, int left, int right) {
    if (left > num) { return false; }
    if (left > right || right > num) { return true; }
    else { return false; }
}

int main() {
    int b, left = 0, right = 0;
    bool flag = true;
    scanf("%ld", &n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < BALL_NUM; j++) {
            scanf("%d", &b);
            printf("%d %d %d ", b, left, right);
            if (b < min(left, right)) {
                printf("%d\n", 0);
                flag = false;
                break;
            }
            if (IsLeft(b, left, right)) { printf("%d\n", 1); left = b; }
            else { printf("%d\n", 2); right = b; }
        }
        if (flag) { printf("%s\n", "YES"); }
        else { printf("%s\n", "NO"); }
    }

    return 0;
}

C++: #include<iostream>

int ball[10];
int ls = 0, rs = 0;
bool res = true;

int main(){
	int n;
	std::cin >> n;
	for (int j = 0; j < n; j++){
		for (int i = 0; i < 10; i++)std::cin >> ball[i];

		for (int i = 0; i < 10; i++){
			int d1 = ball[i] - ls, d2 = ball[i] - rs;

			if (d1 > 0 && d2 > 0){
				if (d1 < d2)ls = ball[i];
				else rs = ball[i];
			}
			else if (d1 > 0 && d2 < 0)ls = ball[i];
			else if (d1 < 0 && d2 > 0)rs = ball[i];
			else res = false;
		}

		std::cout << (res ? "YES" : "NO") << std::endl;
	}
	return 0;
}

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

int main(){
	int N;
	int A[11];
	int cnt1=0;
	cin>>N;
	while(1){
		
		if(cnt1==N){
			break;
		}
		cnt1++;
		for(int i=1;i<=10;i++){
			cin>>A[i];
		}
		int B=A[1];
		int C=0;
		int cnt2=0;
		int cnt3=2;
		for(int i=2;i<=10;i++){
			if(B+1==A[i]){
				B=A[i];
				cnt2++;
			}
			else if(C<A[i]){
				C=A[i];
				cnt2++;
			}
			
			cnt3++;	
		}
		if(cnt2==9){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}
	return 0;	
}

C++: #include <iostream>

using namespace std;

int ball[10];

bool dfs (int n, int a, int b)
{
    if (n==10) return true; //no ball left
    if (ball[n]>a) return dfs(n+1,ball[n],b); //search further
    if (ball[n]>b) return dfs(n+1,a,ball[n]);
    return false;
}

int main()
{
    //DFS for the first time
    int n;
    cin>>n;
    bool ret[n];
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<10; j++) cin>>ball[j];
        ret[i]=dfs(0,0,0);
    }
    for (int i=0; i<n; i++)
    {
        if (ret[i]) cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

const int n = 10;
int t;
int a, b, c;

int main()
{
  cin >> t;

  while(t--){
    bool ok = true;
    b = c = 0;
    rep(i, n){
      cin >> a;
      if(b > c) swap(b, c);
      if(a > c){ c = a;  continue; }
      if(a > b){ b = a;  continue; }
      ok = false;
      //break;
    }
    puts(ok ? "YES" : "NO");
  }

  return 0;
}

C++: a[10];
int dfs(int l,int r,int i){
  if(i>9)return 1;
  if(a[i]>l&&dfs(a[i],r,i+1))return 1;
  if(a[i]>r&&dfs(l,a[i],i+1))return 1;
  return 0;
}
main(n){
  scanf("%d",&n);
  for(;n;n--)
    scanf("%d%d%d%d%d%d%d%d%d%d",a+0,a+1,a+2,a+3,a+4,a+5,a+6,a+7,a+8,a+9),dfs(0,0,0)?puts("YES"):puts("NO");
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(void)
{
int n;
cin>>n;

for(int i=0;i<n;i++)
{
	int a[10]={0};
	for(int j=0;j<10;j++)
	{
	int x;
	cin>>x;
	a[j]=x;
	}
	int b=0,c=0,k;
		for(k=1;k<10;k++)
		{
			if(b<a[k])b=a[k];
			else if(c<a[k])c=a[k];
			else 
			{
			cout<<"NO"<<endl;
			break;
			}
		}
		if(k==10)cout<<"YES"<<endl;

}
return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
  int n,i,j;
  int a[10];
  int b[10];
  int c[10];
 
  cin >> n;
  int k =0;
  while(k<n){
    for(i=0;i<10;i++){
        cin >> a[i];
    }
    for(j=1;j<10;j++){
        b[0]=a[0];
        c[0]=0;
             
        if(b[j-1] < a[j]){
            b[j]=a[j];
            c[j]=c[j-1];
        }
        else if(c[j-1]<a[j]){
            c[j]=a[j];
            b[j]=b[j-1];
        }
        else{
            cout << "NO" << endl;
            break;
        }
        if(j==9){
            cout << "YES" << endl;
        }
    }
    k++;
 }
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;
int N;
vector<int>a;
int dfs(int n, int b, int c){
  if(n == 10) return 1;
  if(b < a[n] && dfs(n+1, a[n], c)) return 1;
  if(c < a[n] && dfs(n+1, b, a[n])) return 1;
}
int main(){
  scanf("%d", &N);
  rep(i, N){
    a.clear();
    int b;
    rep(i, 10){
      scanf("%d", &b);
      a.PB(b);
    }
    printf("%s\n", dfs(0, 0, 0)?"YES":"NO");
  }
}

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

int main(void)
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		queue <int> a;
		int tmp, b = 0, c = 0;
		for (int i = 0; i < 10; i++){
			scanf("%d", &tmp);
			a.push(tmp);
		}
		
		while (1){
			tmp = a.front();
			if (b < tmp) {
				b = tmp;
				a.pop();
			}
			else if (c < tmp) {
				c = tmp;
				a.pop();
			}
			else break;
		}
		
		if (a.empty()) puts("YES");
		else puts("NO");
	}
	
	return (0);
}

C++: #include <cstdio>
#include <vector>
using namespace std;
int A[10];
vector<int> B, C;
int N;

void solve() {
  B.clear();
  C.clear();
  for (int i = 0; i < 10; i++) {
    int k = A[i];
    if (B.empty()) {
      B.push_back(k);
      continue;
    }
    if (C.empty()) {
      C.push_back(k);
      continue;
    }
    int m = max(k - B.back(), k - C.back());
    if (m <= 0) {
      printf("NO");
      return;
    }
    if (m == k - B.back())
      C.push_back(k);
    else
      B.push_back(k);
  }
  printf("YES");
}

int main() {
  scanf("%d", &N);
  while (N--) {
    for (int i = 0; i < 10; i++) scanf("%d", &A[i]);
    solve();
  }
}

C++: #include<iostream>
main(){int n,i,A,B,C,f;for(std::cin>>n;n-->0;puts(f?"NO":"YES"))for(B=C=f=i=0;std::cin>>A,i++<10;)if(B<A)B=A;else C<A?C=A:f=1;}