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[11];
  int c[11];
  int k;
  int k2;
  int out=0;
  cin>>n;
  b[0]=0;
  c[0]=0;
  for(int i=0;i<n;i++){
    out=0;
    k=0;
    k2=0;
    b[1]=0;
    c[1]=0;
    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 <vector>
int ball[10];
int left = 0,right = 0;
bool dfs(int de,int left, int right){//??????????????§???????????????
	if(de == 9)return true;
	if(left < ball[de]){
		left = ball[de];
		return dfs(de + 1.left,right);
	}
	if(right < ball[de]){
		right = ball[de];
		return dfs(de + 1,left,right);
	}
	return false;
}

int main(){
	int n;
	std::cin >> n;
	while(n--){
		for(int i = 0; i < 10; ++i){
			std::cin >> ball[i];
		}
		left = 0, right = 0;
		if(dfs(0,0,0))std::cout << "YES" << std::endl;
		else std::cout << "NO" << std::endl;
	}
}

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

int main(){
	stack<int> b,c;
	int n;
	cin>>n;

	for(int i=0;i<n;i++){
		bool flag=true;
		b.push(0);c.push(0);
		for(int j=0;j<10;j++){
			int t;
			cin>>t;
			if(b.top()<t && c.top()<t){
				b.top()>c.top()?b.push(t):c.push(t);
			}
			else if(b.top()<t){
				b.push(t);
			}
			else if(c.top()<t){
				c.push(t);
			}
			else {
				flag=false;
				break;
			}
		}
		cout<<(flag?"YES":"NO")<<endl;

		while(!b.empty()) b.pop();
		while(!c.empty()) c.pop();
	}
	return 0;
}

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

int b = INT_MIN, c = INT_MIN;

bool push(int ball) {
    if(ball > b) b = ball;
    else if (ball > c) c = ball;
    else return(false);
    return(true);
}

int main(void) {
    int num; cin >> num;
    bool ans = true;
    for(int r = 0; r < num; r++) {
        for(int c = 0; c < 10; c++) {
            int input; cin >> input;
            if(!push(input) && ans) ans = false;
        }
        if(ans) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

C++: #include <iostream>

using namespace std;

int ball_list[10];
int right_list[10];
int left_list[10];

bool flag;

void dfs(int right, int left){
  int count = right + left;

  if(count == 10){
    flag = true;
  }else{
    if(right == 0 || right_list[right-1] < ball_list[count]){
      if(right == 0){
        right_list[0] = ball_list[count];
      }else{
        right_list[right-1] = ball_list[count];
      }
      dfs(right+1, left);
    }
    if(left == 0 || left_list[left-1] < left_list[left]){
      if(left == 0){
        left_list[0] = ball_list[count];
      }else{
        left_list[left-1] = ball_list[count];
      }
      dfs(right, left+1);
    }
  }
}

int main(){
  int n;

  cin >> n;

  for(int i = 0; i < n; i++){
    flag = false;
    memset(right_list, 0, sizeof(right_list));
    memset(left_list, 0, sizeof(left_list));

    for(int j = 0; j < 10; j++){
      cin >> ball_list[j];
    }
    
    dfs(0, 0);

    if(flag){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }

  return 0;
}

C++: #include <iostream>

using namespace std;
const int kBalln = 10;
int ball[kBalln];

bool ExistAsceOrder(int i, int a, int b){
  if (i == kBalln)  return true;

  if (a < ball[i]) 
    {
      if(ExistAsceOrder(i+1,ball[i],b)) return true;
    }

  if (b < ball[i])
    {
      if(ExistAsceOrder(i+1,a,ball[i])) return true;
    }

  return false;
}

int main(){
  int n;

  cin >> n;
  for (int j = 0; j < n; ++j)
    {
      for (int i = 0; i < kBalln; ++i)
        {
          cin >> ball[i];
        }
      cout << (ExistAsceOrder(0,0,0)? "YES" : "NO") << endl;
    }
  return 0;
}

C++: #include <stdio.h>
#include <stdbool.h>
int balls[10];
int left[10],right[10],l=0,r=0,det;
void solve();
void dfs(int depth);
bool check();
int main(void){
	int times;
	scanf("%d",&times);
	for(int i=0;i<times;i++){
		for(int j=0;j<10;j++)
			scanf("%d",&balls[j]);
		solve();
	}
	return 0; 
}

void solve(){
	det=0;
	dfs(0);
	if(det)	puts("YES");
	else	puts("NO");
}

void dfs(int depth){
	if(det)	return;
	if(depth==10){
		if(check())	det=1;
		return;
	}
	left[l++]=balls[depth++];
	dfs(depth);
	l--;depth--;
	right[r++]=balls[depth++];
	dfs(depth);
	r--;depth--;
}

bool check(){
	bool m=1,n=1;
	for(int i=0;i<l-1;i++)
		if(left[i]>left[i+1]){
			m=0;
			break;
		}
	for(int i=0;i<r-1;i++)
		if(right[i]>right[i+1]){
			n=0;
			break;
		}
	return m&&n;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n,l[10],a=0,b=0;
  cin>>n;
  while(n){
    cin>>l[0]>>l[1]>>l[2]>>l[3]>>l[4]>>l[5]>>l[6]>>l[7]>>l[8]>>l[9];
    for(int i=0;i<10;i++){
      if(!(i%2)){
	if(l[i]>a)a=l[i];
	else
	  break;
      }
      else{
	if(l[i]>b)b=l[i];
        else
	  break;
      }
    }
    (a==l[8]&&b==l[9])?cout<<"YES":cout<<"NO";
    cout<<endl;
    n--;
  }
  return 0;
}

C++: #include<stdio.h>
main(){
int i,j,n;
scanf("%d",&n);
int a[n][10],b,c;
for(i=0;i<n;i++)
for(j=0;j<10;j++)
scanf("%d",&a[i][j]);
for(i=0;i<n;i++){
b=0;
c=0;
for(j=0;j<10;j++)
if(a[i][j]>b)
b=a[i][j];
else if(a[i][j]>c)
c=a[i][j];
else
break;
if(j==10)
puts("YES");
else
puts("NO");
}
return 0;
}

C++: #include<iostream>
#include<stack>
#include<queue>
using namespace std;
int main(){
  int n,i;
  queue<int> a;
  cin>>i;
  while(i--){
    for(int i=0;i<10;i++){cin >> n; a.push(n);}
    stack<int> b,c;
    b.push(0); c.push(0);
    while(a.size()){
      int n = a.front();
      if(n>b.top()) b.push(n);
      else if(n>c.top()) c.push(n);
      else break;
      a.pop();
    }
    if(a.size()) cout << "NO" << endl;
    else cout << "YES" << endl;
  }
  return 0;
}

C++: //#include <iostream>
#include <bits/stdc++.h>
#define max_n  100
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
int n,a=-1,b=-1,c,t=0;
int main(){
    scanf("%d",&n);
    while(n--){
        a=0,b=0;
        for(int i=0;i<10;i++){
            cin>>c;
            if(c>a){
                a=c;
            }else if(c>b){
                b=c;
            }else{
                t++;
            }
        }
        if(t){
            cout<<"NO"<<endl;
        }else cout<<"YES"<<endl;
    }
    return 0;
}

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

#define bottom(v) v[v.size()-1]

using namespace std;

int main() {
  int n, t;
  vector<int> v1, v2;
  cin>>n;
  
  while(n--) {
    bool isOk = true;
    for(int i = 0; i < 10; i++) {
      cin>>t;
      if(v1.empty()) v1.push_back(t);
      else {
	if(bottom(v1)<t) {
	  v1.push_back(t);
	} else if(v2.empty() || bottom(v2)<t) v2.push_back(t);
	else {
	  isOk = false;
	  break;
	}
      }
    }
    cout << (isOk ? "YES" : "NO") << endl;
    v1.clear(); v2.clear();
  }
  return 0;
}