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<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=in;
      else c=in;
    }
    if(f)printf("NO\n");
    else printf("YES\n");
  }
}

C++: #include <iostream>

int nums[10];

bool dfs(int index, int left, int right)
{
  // std::cout << index << std::endl;
  if (index == 10)
  {
    return true;
  }
  // try put at the larger one
  if (left >= right)
  {
    if (left < nums[index])
    {
      return dfs(index + 1, nums[index], right);
    }
    if (right < nums[index])
    {
      return dfs(index + 1, left, nums[index]);
    }
    return false;
  }
  if (right > left)
  {
    if (right < nums[index])
    {
      return dfs(index + 1, left, nums[index]);
    }
    if (left < nums[index])
    {
      return dfs(index + 1, nums[index], right);
    }
    return false;
  }
  return false;
}

int main()
{
  int count = -1;
  std::cin >> count;
  for (int i = 0; i < count; i++)
  {
    for (int j = 0; j < 10; j++)
    {
      std::cin >> nums[j];
    }
    if (dfs(0, -1, -1))
    {
      std::cout << "YES" << std::endl;
    }
    else
    {
      std::cout << "NO" << std::endl;
    }
  }
  return 0;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; -i)
#define INF (1 << 30)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int n;
int ball[11] = {0};

bool solve(int a, int b, int c) {
	if(c == 10) return true;
	if(a < ball[c]) 
		if(solve(ball[c], b, c + 1)) return true;
	if(b < ball[c])	
		if(solve(a, ball[c], c + 1)) return true;
	return false;

}

int main() {
	scanf("%d", &n);
	rep(i, n) {
		rep(j, 10) scanf("%d", &ball[j]);
		printf("%s\n", (solve(0, 0, 0)) ? "YES" : "NO");
	}
	return 0;
}

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

using namespace std;

int n;
int stock[2][11];
int usea[11];

int dfs(int num, int r_num, int l_num) {
	int res = 0;

	if (usea[num+1] > stock[0][r_num]) {
		if (num == 9)
			return 1;
		stock[0][r_num + 1] = num;
		res = dfs(num + 1, r_num + 1, l_num);
		stock[0][r_num + 1] = -1;
		return res;
	}
	else if (usea[num+1] > stock[1][l_num]) {
		if (num == 9)
			return 1;
		stock[1][l_num + 1] = num;
		res = dfs(num + 1, r_num, l_num + 1);
		stock[1][l_num + 1] = -1;
		return res;
	}
	else {
		return 0;
	}
}


int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> usea[j];
		}
		stock[0][0] = -1;
		stock[0][1] = usea[0];
		stock[1][0] = -1;
		if (dfs(0, 1, 0)) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
		stock[0][0] = -1;
		stock[0][1] = -1;
		stock[1][0] = -1;
	}

	return 0;
}

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

using namespace std;
const int maxn = 1024;

int a[12], b[12], c[12];

int main() {
    int T; scanf("%d", &T);
    while(T--) {
        for(int i = 0; i < 10; ++i)
            scanf("%d", &a[i]);
        bool flag = false;
        for(int i = 0; i < maxn; ++i) {
            int pos1 = 0, pos2 = 0;
            for(int j = 0; j < 10; ++j) {
                if(i & (1 << j)) b[pos1++] = a[j];
                else c[pos2++] = a[j];
            }
            flag = false;
            for(int j = 0; j < pos1 - 1; ++j) {
                if(b[j] > b[j+1]) {
                    flag = true; break;
                }
            }
            if(flag) continue;
            for(int j = 0; j < pos2 - 1; ++j) {
                if(c[j] > c[j+1]) {
                    flag = true; break;
                }
            }
            if(flag) continue;
            break;
        }
        puts(flag ? "NO" : "YES");
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int tama[10],n;

bool Haireruka(int i,int left,int right){
	if(i==10)return true;
	if(tama[i]>left){
		if(Haireruka(i+1,tama[i],right))return true;
	}
	if(tama[i]>right){
		if(Haireruka(i+1,left,tama[i]))return true;
	}
	return false;
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		for(int i=0;i<10;i++){
			cin>>tama[i];
		}
		if(Haireruka(0,0,0))cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define INF 114514810
#define FOR(i, r, n) for(int i=(r); i<(n); i++) 
#define REP(i, n) FOR(i, (0), n)

using namespace std;

int n, ct = 1, d[13], flg = 1, t;
vector<int> x, y;

int judge(int ct){
	while (ct < 1023){
		t = ct;
		REP(i, 10){
			if (t & 1) x.push_back(d[i]);
			else y.push_back(d[i]);
			t >>= 1;
		}
		REP(i, x.size() - 1){
			if (x.at(i) > x.at(i + 1)) flg *= 0;
		}
		REP(i, y.size() - 1){
			if (y.at(i) > y.at(i + 1)) flg *= 0;
		}
		if (flg) return 1;
		x.clear(); y.clear(); t = 0; flg = 1; ct++;
	}
	return 0;
}

int main(){
	cin >> n;
	REP(k, n){
		REP(i, 10) cin >> d[i];
		if (judge(1)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

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

#include <string.h>

int a[10];

int memo[10][10+1][10+1];

int search(int i, int j, int k)
{
  if (memo[i][j][k] >= 0)
    return memo[i][j][k];
  
  if (i == 9)
    return memo[i][j][k] = a[i];

  int r = 0;

  if (a[i] > j)
    r = std::max(search(i + 1, a[i], k), r);
		 
  if (a[i] > k)
    r = std::max(search(i + 1, j, a[i]), r);
  
  return r;
}

int main(int argc, char** argv)
{
  int N;

  std::cin >> N;

  while (N --) {
    for (int i = 0; i < 10; i ++)
      std::cin >> a[i];

    memset(memo, -1, sizeof(memo));

    std::cout << (search(0, 0, 0) ? "YES" : "NO") << std::endl;
  }
}

C++: #include <iostream>

using namespace std;

int main(void) {
    int N, a, b, c;
    cin >> N;
    for (; N--; ) {
        b = c = 0;
        bool ok = true;
        for (int i = 0; i < 10; i++) {
            cin >> a;
            if (a < b && a < c) {
                ok = false;
                break;
            } else if (a < b) {
                c = a;
            } else if (a < c) {
                b = a;
            } else if (c > b) {
                c = a;
            } else {
                b = a;
            }
        }
        cout << (ok ? "YES" : "NO") << endl;
    }
    return 0;
}

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

using namespace std;

#define int_ int64_t
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define lb long double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

ll n,a[15];
vector<ll> v1,v2;
bool ans=false;

void dfs(ll idx) {
    if (idx>10) {
        ans=true;
        return;
    }
    if (v1.empty()||a[idx]>v1.back()) {
        v1.pb(a[idx]);
        dfs(idx+1);
        v1.pop_back();
    }
    if (v2.empty()||a[idx]>v2.back()) {
        v2.pb(a[idx]);
        dfs(idx+1);
        v2.pop_back();
    }
}

int main()
{
    scanf("%lld",&n);
    for (ll i=1;i<=n;i++) {
        for (ll j=1;j<=10;j++) scanf("%lld",a+j);
        ans=false;
        dfs(1);
        if (ans) printf("YES\n");
        else printf("NO\n");
    }
}