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>
#include<cstdio>
#include<string>
#include<vector>
using namespace std;


int res=0;

int saiki(int ball[],int ttB,int ttC,int res){
	if(res==10)return res;
	if(ball[res]>ttB){
		return saiki(ball,ball[res],ttC,res+1);
	}
	if(ball[res]>ttC){
		return saiki(ball,ttB,ball[res],res+1);
	}
	return res;
}

int main(void){
	int a,b;
	int ball[11];
	int ttB=0,ttC=0;
	int n;
	scanf("%d",&n);
	for(a=0;a<n;a++){
		for(b=0;b<10;b++){
			ball[b]=0;
		}
		ttB=0;
		ttC=0;
		res=0;
		for(b=0;b<10;b++){
			scanf("%d",&ball[b]);
		}
		res=max(res,saiki(ball,ttB,ttC,res));
		if(res==10)printf("Yes\n");else printf("No\n");
	}
	return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int dfs(int b[10],int c[10],int m,int k,int t);//a中，b中，c中游标
int a[10];
int flag;
int main()
{
	int N;
	cin >> N;
	while (N--)
	{
		for (int i = 0; i < 10; i++)
			cin >> a[i];
		int b[10];
		int c[10];
		b[0] = 0;
		c[0] = 0;
		if (dfs(b, c, 0, 0, 0)== 1)
			cout << "YES" << endl;
		if (dfs(b, c, 0, 0, 0) == 0)
			cout << "NO" << endl;
	}
	return 0;
}
int dfs(int b[10], int c[10], int m, int k, int t)
{
	int ma = m;
	int kb = k;
	int tc = t;
	int i;
	int x[10], y[10];             //用x,y去中间值，好进行回溯
	if (ma == 10)
		return 1;
	for (i = 0; i <=kb; i++)
	{
		x[i] = b[i];	
	}
	for (i = 0; i <= tc; i++)
	{
        y[i] = c[i];
	}
	if (x[kb] > a[ma] && y[tc] > a[ma])
		return 0;
	if (x[kb] > a[ma] && y[tc] < a[ma])
	{
		y[tc] = a[ma];
		ma++; tc++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
	}
	if (x[kb] < a[ma] && y[tc] > a[ma])
	{
		x[kb] = a[ma];
		ma++; kb++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
	}
	if (x[kb] < a[ma] && y[tc] < a[ma])
	{
		x[kb] = a[ma];
		ma++; kb++;
		if (ma <=10)
			dfs(b, c, ma, kb, tc);
		 kb--;
		y[tc] = a[ma];
		 tc++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
	}
}

C++: #include <iostream>

using namespace std;

int main(void){
    int a[11],fir,sec=0,i,n;
    cin>>n;
    while (1) {
    
    for (i=0; i<10; i++) {
        cin>>a[i];
    }
    fir=a[0];
    for (i=1; i<10; i++) {
        if(fir<a[i])fir=a[i];
        else if(sec<a[i])sec=a[i];
        else break;
    }
    if(i==10)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
        n--;
        if(n==0)break;
        
    }
    return 0;
}

C++: #include 	   <stdio.h>
#include <vector>  

using namespace std;			

void solve(vector<int> left, vector<int> right, vector<int> all, int n) {
	bool flag = true;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else
							flag = false;
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}	 	
		if (flag)
			printf("YES\n");
		else
			printf("NO\n");
		flag = true;
	}
}

int main() {		
	vector<int> left;
	vector<int> right;
	vector<int> all;


	int n;
	scanf("%d", &n);
	if (n <= 0) return -1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			scanf("%d", &temp);
			all.push_back(temp);
		}
	}	  

	solve(left, right, all, n);

	return 0;
}

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

using namespace std;

int main(){
	stack<int> st1,st2;
	int ball[10];
	int n;
	cin >> n;
	for(int loop=0;loop<n;loop++){
		for(int i=0;i<10;i++){
			cin >> ball[i];
		}
		st1.push(ball[0]);
		for(int i=1;i<10;i++){
			if(st1.top() < ball[i]){
				st1.push(ball[i]);
			}else if(st2.empty()){
				st2.push(ball[i]);
			}else if(st2.top() < ball[i]){
				st2.push(ball[i]);
			}
		}

		if(st1.size()+st2.size() == 10){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
}

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

vector<vector<int> > arr;

void display(int n){
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 10; j++){
      cout << arr[i][j] << " ";
    }
    cout << endl;
  }
  cout << endl;
}

bool dfs(int n, int i, int left, int right){
  if(i == 10) return true;

  bool ans = false;
  if(left < arr[n][i]) ans = dfs(n, i + 1, arr[n][i], right);
  if(right < arr[n][i]) ans = dfs(n, i + 1, left, arr[n][i]);

  return ans;
  
}

int main(){
  int n;
  cin >> n;
  arr.resize(n);
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 10; j++){
      int tmp;
      cin >> tmp;
      arr[i].push_back(tmp);
    }
  }

  //display(n);

  for(int i = 0; i < n; i++){
	bool ans = dfs(i, 0, 0, 0);
	if(ans) cout << "YES" << endl;
	else cout << "NO" << endl;
  }
  
  
  return 0;
}

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


bool vis[15];
int a[15];

bool ok = false;


void dfs(int cnt, int last){
	if(ok){
		return;
	}
	if(cnt == 9){
		vector<int> ver;
		for (int i = 0; i < 10; i++){
			if(!vis[i]){
				ver.push_back(a[i]);
			}
		}
		bool flag = true;
		for (int i = 1; i < ver.size(); i++){
			if(ver[i] < ver[i - 1]){
				flag = false;
			}
		}
		if(flag){
			ok = true;
		}
		return;
	}
	for (int i = cnt; i < 10; i++){
		if(a[i] > last){
			vis[i] = true;
			dfs(i + 1, a[i]);
			vis[i] = false;
		}
	}
	return;
}
 





int main(){
	int n;
	cin >> n;
	while(n--){
		ok = false;
		memset(a, 0, sizeof(a));
		memset(vis, false, sizeof(vis));
		for (int i = 0; i < 10; i++){
			cin >> a[i];
		}
		
		dfs(0, 0);
		if(ok){
			cout << "YES" << endl;
		}else cout << "NO" << endl; 
		
		
		
	}
	return 0;
}

C++: #include<iostream>

int ball[10];
int ls = 0, rs = 0;
bool res = true;

int main(){
	int n;
	std::cin >> n;
	for (int j = 0; j < n; j++){
		ls = 0, rs = 0, res = true;

		for (int i = 0; i < 10; i++)std::cin >> ball[i];

		for (int i = 0; i < 10; i++){
			int d1 = ball[i] - ls, d2 = ball[i] - rs;

			if (d1 > 0 && d2 > 0){
				if (d1 <= d2)ls = ball[i];
				else rs = ball[i];
			}
			else if (d1 > 0 && d2 < 0)ls = ball[i];
			else if (d1 < 0 && d2 > 0)rs = ball[i];
			else res = false;
		}

		std::cout << (res ? "YES" : "NO") << std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
int ball[10];
int left=0,right=0;
bool dfs(int de){//??????????????§???????????????
	if(de==9)return true;
	if(left<ball[de]){
		left=ball[de];
		return dfs(de+1);
	}
	if(right<ball[de]){
		right=ball[de];
		return dfs(de+1);
	}
	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))std::cout << "YES" << std::endl;
		else std::cout << "NO" << std::endl;
	}
}

C++: #include <iostream>

#define MAX 10
using namespace std;

int main(){
  int count;
  int ball1,ball2,ball;
  cin >> count;
  for(int i=0;i<count;i++){
    ball1=0;ball2=0;
    for(int j=0;j<MAX;j++){
      cin >>ball;
      //cout << ball1 << " " << ball2 << endl;
      //      cout << ball << endl;
      //cout << j << endl;
      if(ball1 < ball || ball2 < ball){
	if(ball2<ball){
	  ball2=ball;
	}
	else{
	  ball1 = ball;
	}
	if(j==MAX-1){
	  cout << "YES";
	}
      }
      else{
	cout << "NO";
	for(int k=0;k<MAX-j;k++) cin >>ball;
	break;
      }
    }
    if(i!=count-1){
      cout << endl;
    }
  }
}