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>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
    int N,pre,current,second_pre;
    bool NO_FLG;

    scanf("%d",&N);
    for(int i=0;i<N;i++){
        pre = -1;
        second_pre = -1;
        NO_FLG = false;
        for(int k = 0; k < 10; k++){
            scanf("%d",&current);	//????????????????????????
            if(pre > current){	//1?????????????????????????????§????????´???,current?????????1????????????????§????
				if(second_pre == -1){	//2?????????????????????????????¨?????????????????´???
					second_pre = current;
				}else{	//2???????????????????????¨??????????????´???
					if(second_pre > current){ //2????????????????????°??????current???????????§????????´???
						printf("NO\n");
						NO_FLG = true;
						break;
					}else{	//2????????????????????°??????current??????????°?????????´???
						second_pre = current;
					}
				}
			}else{ //pre < current
				pre = current;
			}
        }
        if(!NO_FLG)printf("YES\n");

    }
    return 0;
}

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

stack<int> B, C;
int A[10];

bool dfs(int index)
{
  bool ret = false;
  char s[11];

  if (index >= 10) {
    return true;
  }

  for (int i = 0; i < 11; i++) {
    if (i < index) s[i] = '>';
    else s[i] = 0;
  }

  if (B.empty() || B.top() < A[index]) {
    B.push(A[index]);
    // printf("%spush %d into B\n", s, A[index]);
    ret = dfs(index + 1);
    // printf("%s%s. pop %d from B\n", s, ret ? "succeeded" : "failed", A[index]);
    B.pop();
  }
  if (!ret && (C.empty() || C.top() < A[index])) {
    C.push(A[index]);
    // printf("%spush %d into C\n", s, A[index]);
    ret = dfs(index + 1);
    // printf("%s%s. pop %d from C\n", s, ret ? "succeeded" : "failed", A[index]);
    C.pop();
  }

  return ret;
}

bool solve()
{
  while (!B.empty()) B.pop();
  while (!C.empty()) C.pop();

  B.push(A[0]);
  bool ret = dfs(1);
  B.pop();

  return ret;
}

int main()
{
  int N;
  scor (int j = 0; j < 10; j++) {
      scanf("%d", A + j);
    }

    if (solve()) {
      printf("Yes\n");
    }
    else {
      printf("No\n");
    }
  }

  return 0;
}

C++: #include<iostream>
using namespace std;
int ball[10];
int flag;  //1??????YES???0??????NO
void dfs(int left,int right,int depth){
  if(depth==10){ //???????????????????????§??\???????????????
    flag=1;
    return;
  }
  if(left<ball[depth])
    dfs(ball[depth],right,depth+1);
  if(right<ball[depth])
    dfs(left,ball[depth],depth+1);
}

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    flag=0;//????????°????????????
    for(int j=0;j<10;j++)
      cin>>ball[j];
    dfs(ball[0],0,1);//????????????????????\??????????????????
                     //3??????????????°?????±???
                     //?????????????????\?????????????????\???????????????????????§
                     //????????\?????????????????????????????????
    if(flag)
      cout<<"YES"<<endl;
    else
      cout<<"NO"<<endl;
  }
  return 0;
}

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

int main() {
  int n; cin >> n;
  while (n--) {
    vector<int> a(10); for (int i = 0; i < 10; ++i) cin >> a[i];
    int sum = 0;
    for (int i = 1; i < 10; ++i) {
      sum += (a[i - 1] > a[i]);
    }
    cout << ( (sum < 3) ? "YES" : "NO" ) << endl;
  }
  return 0;
}

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

int main() {
	int a[10], n, j;
	vector<int> b, c;

	cin >> n;
	for (int i = 0; i < n; i++) {
		for (j = 0; j < 10; j++) {
			cin >> a[j];
		}
		for (j = 0; j < 11; j++) {
			if (j == 10) {
				break;
			}
			if (j == 0) {
				b.push_back(a[j]);
			}
			else if (a[j] - 1 != b[b.size() - 1] && c.size() == 0) {
				c.push_back(a[j]);
			}
			else if (a[j] - 1 == b[b.size() - 1]) {
				b.push_back(a[j]);
			}
			else if (a[j] - 1 == c[c.size() - 1]) {
				c.push_back(a[j]);
			}
			else {
				break;
			}
		}
		if (j == 10) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}

C++: /*
 * AOJ 0033: Ball
 * ?¢????????????????1-10???10???????????????????????????????????\2????????????????????????????????\??????????????????????¢????????????????????????¨???
 * ?±???????DFS
 * ?????????????????????????????\??§???????????¶???????´????????????\??°?????\????????¶??§????????????
 */

#include <cstdio>
#include <iostream>

using namespace std;

int a[10], b[2][10];
int len[2];
bool ans;


void dfs(int step) {
  if (ans) return;
  if (step == 10) {
    ans = true;
    return;
  }
  for (int i = 0; i < 2; ++i) {
    if (len[i] == 0 || a[step] > b[i][len[i] - 1]) {
      b[i][len[i]++] = a[step];
      dfs(step + 1);
      --len[i];
    }
  }
}

void solve() {
  ans = false;
  for (int i = 0; i < 10; ++i) {
    cin >> a[i];
  }
  dfs(0);
}

int main() {
  int T;
  cin >> T;
  while (T--) {
    solve();
    cout << (ans ? "YES" : "NO") << endl;
  }
  return 1;
}

C++: #include<iostream>
#include<cstring>
#include<stack>
using namespace std;
int a[15],t;
int map[2][15];
stack<int>s[2];
void dfs(int g){
	if(g==10){
		t=1;
		return;
	}
	if(t==1)
	return;
	for(int i=0;i<2;i++){
		if(s[i].size()==0||s[i].top()<a[g]){
			s[i].push(a[g]);
			dfs(g+1);
			s[i].pop();
		}
	}
}
int main(){
	int loop;
	cin>>loop;
	while(loop--){
		for(int i=0;i<10;i++)
		cin>>a[i];
		t=0;
		for(int i=0;i<2;i++)
		while(!s[i].empty())
		s[i].pop();
		dfs(0);
		for(int i=0;i<2;i++)
		while(!s[i].empty())
		s[i].pop();
		if(t==1)
		cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

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

using namespace std;

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

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

	if (usea[num] > 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] > 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 >> a[i][j];
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			usea[j] = a[i][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<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
bool sorted(vector<int> a){
	for(int x=0;x<a.size()-1;++x){
		if(a[x]>a[x+1])return false;
	}
	return true;
}
int main(){
	int n;
	cin>>n;
	for(int x=0;x<n;++x){
		vector<int> a,b;
		for(int x=0;x<10;++x){
			int j;cin>>j;
			if(x%2==0){
				a.push_back(j);
			}else{
				b.push_back(j);
			}
		}
		if(sorted(a) && sorted(b)){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}		
	}
	return 0;
}