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 <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
using namespace std;
const int maxn = 10001;
int a[maxn];
int vis[maxn];
void dfs(int pre , int cur)
{
    if(cur < 10 && a[pre] < a[cur])
    {
        vis[cur] = 1;
        dfs(cur , cur + 1);
    }
    else if(cur < 10 && a[pre] > a[cur]){
        dfs(pre , cur + 1);
    }
}

int main()
{
    #ifdef DoubleQ
    freopen("in.txt" , "r" , stdin);
    #endif // DoubleQ
    int n;
    cin >> n;
    while(n --){
        for(int i = 0 ; i < 10 ; i ++){
            cin >> a[i];
        }
        bool flag = false;
        for(int i = 0 ; i < 10 ; i ++){
            memset(vis , 0 , sizeof(vis));
            vis[i] = 1;
            dfs(i , i + 1);
            int pre = 0;
            for(int j = 0 ; j < 10 ; j ++){
                if(vis[j] == 0){
                    if(pre > a[j]){
                        flag = true;
                        break;
                    }
                    else pre = a[j];
                }
            }
            if(!flag){
                cout << "YES" << endl;
                break;
            }
        }
        if(flag) cout << "NO" << endl;

    }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int d=0;d<n;d++){
	int a[10]={},b[10]={},c[10]={};
	for(int i=0;i<10;i++){
		cin>>a[i];
	}
	int j=0,k=0;
	for(int i=0;i<10;i++){
		if(b[j]<a[i]){
			b[j+1]=a[i];
			j++;
		}
		else if(c[k]<a[i]){
			c[k+1]=a[i];
			k++;
		}
		else{
			cout<<"NO"<<endl;
			goto age;;
		}
	}
	cout<<"YES"<<endl;
	age:;
}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int d[10];
bool solve(){
  int a=0;
  int b=0;
  for(int i=0;i<10;i++){
    if(a<d[i]){a=d[i];continue;}
    else if(b<d[i]){b=d[i];continue;}
    else return false;
  }
  return true;
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>d[j];
    }
    cout<<(solve()?"YES":"No")<<endl;
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>

typedef long long ll;
using namespace std;

typedef pair<int,int> P;

void seek_lcs(int a,int b,int dp[10+1][10+1],int* num,int* base,vector<int>& idx){
	if(a==0 || b==0){
		return;
	}

	if(num[a] == base[b]){
		seek_lcs(a-1,b-1,dp,num,base,idx);
		idx.push_back(num[a]);
	}
	else{
		if(dp[a-1][b] >= dp[a][b-1]){
			seek_lcs(a-1,b,dp,num,base,idx);
		}
		else{
			seek_lcs(a,b-1,dp,num,base,idx);
		}
	}

}

int main()
{
	int T;
	cin >> T;
	for(int t=0;t<T;t++){

		int num[10+1];
		int base[10+1];
		int dp[10+1][10+1];

		memset(dp,0,sizeof(dp));

		for(int i=1;i<=10;i++){
			scanf("%d",num+i);
			base[i]=i;
		}
		num[0]=0;
		base[0]=0;

		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				if(num[i+1]==base[j+1]){
					dp[i+1][j+1] = max(dp[i+1][j],max(dp[i][j+1],dp[i][j]+1));
				}
				else{
					dp[i+1][j+1] = max(dp[i+1][j],max(dp[i][j+1],dp[i][j]));
				}
			}
		}

		vector<int> idx;
		stack<int> stk;
		seek_lcs(10,10,dp,num,base,idx);

		for(int i=1;i<=10;i++){
			if(find(idx.begin(),idx.end(),num[i]) != idx.end()){
				continue;
			}

			if(stk.empty() || stk.top() < num[i]) stk.push(num[i]);
		}

		printf("%s\n",idx.size() + stk.size() == 10 ? "YES" : "NO");
	}
}

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

  int blank,n,num[10],i;
  vector <int> a,b;

  cin>>n;
  for(int j=0;j<n;j++){
  for(i=0;i<10;i++) cin>>num[i];
  blank=0;
  a.clear();
  b.clear();
  a.push_back(0);
  b.push_back(0);
  for(i=0;i<10;i++){

    if(num[i]>a.back() && num[i]>b.back()){
      if(a.back()<=b.back()){
	b.push_back(num[i]);
	continue;
      }
      else {
	a.push_back(num[i]);
	continue;
      }
    }

    if(num[i]>a.back()){
      	a.push_back(num[i]);
	continue;
    }
      if(num[i]>b.back()){
      	b.push_back(num[i]);
	continue;
    }
      
      blank=1;
      break;

  }

  if(blank==0) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  }
  
  return 0;

}

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

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

int main() {
	int n, x;
	cin >> n;
	for (int lop = 0, a = 0, b = 0; lop < n; lop++) {
		bool f = true;
		for (int i = 0; i < 10; i++) {
			cin >> x;
			if (f) {
				if (a < x && b < x) {
					if (a < b) {
						b = x;
						continue;
					}
					a = x;
					continue;
				}
				if (a < x) {
					a = x;
					continue;
				}
				if (b < x) {
					b = x;
					continue;
				}
				f = false;
			}
		}
		cout << (f ? "YES\n" : "NO\n");
	}
	return 0;
}

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

int main() {

  int n;
  cin >> n;

  int b = 0;
  int c = 0;
  int input;

  for ( int i = 0; i < n; i++ ) {

    bool flag = false;
    for ( int j = 0; j < 10; j++ ) {
      cin >> input;

      if ( input < b && input < c ) flag = true;
      if ( flag ) continue;

      if ( input < b ) {
	c = input;
      }else if ( input < c ) {
	b = input;
      }else {
	if ( b < c ) {
	  c = input;
	}else {
	  b = input;
	}
      }

    }

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

  }

  return 0;

}

C++: #include<iostream>

using namespace std;

int tama[10],n;

bool Haireruka(int i,int left,int right){
	if(i==9)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 <iostream>
#include <algorithm>
using namespace std;

int main(void)
{
	int N;
	cin >> N;

	while(N > 0){
		int data[10];
		int a=0,b=-1;
		for(int i = 0; i < 10; i++){
			cin >> data[i];

		}

		for(int i = 0; i < 10; i++){
			if(a > data[i] && b > data[i]){
				a = -1;
				break;
			}
			if(data[i] > a && a > b)
				a = data[i];
			else if(a > data[i] && data[i] > b)
				b = data[i];


		}

		if(a < 0)
			cout << "NO" << endl;
		else
			cout << "YES" << endl;

		N--;
	}

	return 0;

}