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 <bits/stdc++.h>

using namespace std;

int ball[10];
int B[10];
int C[10];
int D[2] = {0,1};
int j,k;
int ans;

void bfs(int n);
int main()
{
  int n;
  
  cin >> n;

  while(n--){
    ans = 0;
    for(int i = 0;i < 10;i++){
      cin >> ball[i];
    }

    bfs(0);

    if(ans == 1)cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

void bfs(int n)
{
  if(n == 10){
    ans = 1;
    return ;
  }
  for(int i = 0;i < 2;i++){
    if(D[i] == 0){
      B[j] = ball[n];
      n++;
      if(j > 0 && B[j] < B[j-1])return ;
      j++;
      bfs(n);
    }
    else{
      C[k] = ball[n];
      n++;
      if(k > 0 && C[k] < C[k-1])return ;
      k++;
      bfs(n);
    }
    return ;
  }
}

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

int main(){
	int k;
	std::cin>>k;
	while(k>0){
		std::vector<int>v(10,0);
		std::stack<int>s;
		std::stack<int>s2;
		int a;
		for(int i=0;i<10;i++){
			std::cin>>v[i];
		}
		s.push(v[0]);
		s2.push(0);
		for(int i=1;i<10;i++){
			int x=s.top(),y=s2.top();
			if(v[i]>x&&v[i]>y){
				if(x>=y)s.push(v[i]);
				else s2.push(v[i]);
			}else if(v[i]>x&&v[i]<=y)s.push(v[i]);
			else if(v[i]<=x&&v[i]>y)s2.push(v[i]);
			else{
				std::cout<<"No"<<std::endl;
				break;
			}if(i==9)std::cout<<"Yes"<<std::endl;
		}
		k--;
	}
	return 0;
}

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

using namespace std;


int n;
int A[10];

bool solve(stack<int> v1, stack<int> v2, int index){
    if (index == 10)
        return true;
    if (v1.empty() || A[index] > v1.top())
        v1.push(A[index]);
    else if(v2.empty() || v2.top() < A[index])
        v2.push(A[index]);
    else
        return false;
    return solve(v1,v2, index + 1);
}

int main(){
    cin>>n;
    stack<int> v1,v2;
    while(n--){
        for (int i = 0; i < 10; ++i) {
            cin>>A[i];
        }
        if (solve(v1,v2,0))
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

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

void get_input(int* arr) {
    for (int i = 0; i < 10; i++) {
        std::cin >> arr[i];
    }
}

char* solve(int* balls) {
    std::stack<int> a, b;
    a.push(0); b.push(0);

    for (int i = 0; i < 10; i++) {
        if (balls[i] > a.top() && balls[i] > b.top()) {
            if (a.top() > b.top()) {
                a.push(balls[i]);
            } else {
                b.push(balls[i]);
            }
        } else if (balls[i] > a.top() && balls[i] < b.top()) {
            a.push(balls[i]);
        } else if (balls[i] < a.top() && balls[i] > b.top()) {
            b.push(balls[i]);
        } else {
            return "NO";
        }
    }
    return "YES";
}

int main(void) {
    int balls[10];
    int n;
    std::cin >> n;

    for (int i = 0; i < n; i++) {
        get_input(balls);
        std::cout << solve(balls) << std::endl;
    }

    return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int ball[10];
int l,r;
bool flag;
void dfs(int num,int l,int r){
	if(num==10) return ;
//	if(flag) return ;
	if(ball[num]>l) dfs(num+1,ball[num],r);
	else if(ball[num]>r) dfs(num+1,l,ball[num]);
	else{
		flag=true;
		return ;
	}
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			cin>>ball[i];
		}
		l=0,r=0;
		flag=false;
	    dfs(i,l,r);
		if(flag){
			cout<<"NO"<<endl;
		}else{
			cout<<"YES"<<endl;
		} 
	}
}

C++: //Aizu 0033
//DinnerHunt
#include <cstdio>
#include <stack>
using namespace std;
int n,k,flag;
int main(){
	scanf("%d",&n);
	while(n--){
		stack<int> stk1,stk2;
		stk1.push(0);
		stk2.push(0);
		flag=1;
		for(int i=0;i<10;i++){			
			scanf("%d",&k);
			int a=k-stk1.top();
			int b=k-stk2.top();
			if (a<0&&b<0) flag=0;
			else if((0<a&&a<b)||(b<0)) stk1.push(k);
			else stk2.push(k);
		}
		if(flag)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++: #include <cstdio>

int B[10];
int C[10];
int ball[10];
int res = 0;

void solve(int i, int bi, int ci) {
  if (i == 10) {
    res = 1;
    return;
  }

  if (bi == 0) {
    B[bi] = ball[i];
    solve(++i, 1, ci);
    i--;
    B[bi] = 0;
  } else {
    if (ball[i] > B[bi-1]) {
      B[bi] = ball[i];
      solve(++i, ++bi, ci);
      B[bi] = 0;
      i--;
      bi--;
    }
  }

  if (ci == 0) {
    C[ci] = ball[i];
    solve(++i, bi, 1);
  } else {
    if (ball[i] > C[ci-1]) {
      C[ci] = ball[i];
      solve(++i, bi, ++ci);
    }
  }

}

int main() {
  int i,j;
  scanf("%d", &i);
  while(i) {
    for (j=0;j<10;j++)
      scanf("%d", &ball[j]);
    solve(0,0,0);
    if (res == 1) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
    i--;
    res = 0;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
  bool f;
  int n, b, c, p;
  cin >> n;
  while (n--) {
    b = c = 0;
    f = true;
    for (int i = 0; i < 10; i++) {
      cin >> p;
      if (p < b && p < c) f = false;
      else if (p > b) b = p;
      else if (p > c) c = p;
      else f = false;
    }
    cout << (f ? "YES" : "NO") << endl;
  }
}

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

string solve(int a, int b, int f) {
	if (f >= 10) return "YES";
	
	int x;
	cin >> x;
	
	if (x > a) return solve(x, b, f + 1);
	if (x > b) return solve(a, x, f + 1);

	return "NO";
}

int main() {
	int n;
	cin >> n;

	for (int i = 0; i++ < n;) {
		cout << solve(0, 0, 0) << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
signed main(void){
	ios::sync_with_stdio(false);
	int T;
	cin>>T;
	for(int t=1;t<=T;t++){
		int a=0,b=0;
		for(int i=1,x;i<=10;i++){
			cin>>x;
			if(x<a&&x<b){
				cout<<"NO"<<endl;
				break;
			}
			else if(x>a&&x>b){
				if(a>b)	a=x;
				else	b=x;
			}
			else if(x<a&&x>b){
				b=x;
			}
			else if(x>a&&x<b){
				a=x;
			}
			if(i==10)
				cout<<"YES"<<endl;
		}
	}
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int ball[10];
int l,r;
bool flag;
void dfs(int num,int l,int r){
	if(num==10) return ;
	if(flag) return ;
	if(ball[num]>l) dfs(num+1,ball[num],r);
	else if(ball[num]>r) dfs(num+1,l,ball[num]);
	else{
		flag=true;
		return ;
	}
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			cin>>ball[j];
		}
		l=0,r=0;
		flag=false;
	    dfs(0,l,r);
		if(flag){
			cout<<"NO"<<endl;
		}else{
			cout<<"YES"<<endl;
		} 
	}
}

C++: #include <iostream>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  cin>>n;
  while(n--){
    int a[10],b[2][11]={0},b1=1,b2=1,k=0;
    r(i,10)cin>>a[i];
    r(i,10){
      if(a[i]>b[1][b1-1])b[1][b1++]=a[i];
      else b[0][b2++]=a[i];
    }
    r(i,b1-1){if(b[1][i]>b[1][i+1])k++;}
    r(i,b2-1){if(b[0][i]>b[0][i+1])k++;}
    if(k)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
  }
}