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>
main(){
  int a[10],i,n,c=0,j,b=0,jud=1;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<10;j++){
      scanf("%d",&a[j]);
	}
    for(j=0;j<10;j++){
      if(b>a[j]&&c<a[j]) c=a[j];
      else if(b>a[j]&&c>a[j]){
	jud=0;
	break;
      }
      else if(b<a[j]&&c<a[j]&&b>c) c=a[j];
      else b=a[j];
    }
    if(jud==0) printf("NO\n");
    else printf ("YES\n");
  }
  return 0; 
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int n;
  int i,j;
  int num;

  cin>>n;

  rep(i,n){

    bool yes=true;
    int max1=0,max2=0;

    rep(j,10){

      scanf("%d",&num);

      if(max1>num && max2>num){
	if(yes)	cout<<"NO"<<endl;
	yes=false;
	continue;
      }
      else if(max1>num)
	max2=num;
      else if(max2>num)
	max1=num;
      else
	max1>max2 ? max1=num : max2=num;

    }//repj
    if(yes)
      cout<<"YES"<<endl;
  }//repi
}

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

int main()
{
    int N,ball[10],index=0;
    scanf("%d",&N);
    for(int i=0;i<N;++N) {
        for(int i=0;i<10;++i) {
            scanf("%d",&ball[i]);
        }
        while(index+2 <= 9) {
            if(ball[index] < ball[index+1]) {
                ++index;
                continue;
            } else if (ball[index] < ball[index+2]) {
                ++index;
                continue;
            } else {
                puts("NO");
                return -1;
            }
        }
        puts("YES");
        return 0;
    }
}

C++: #include <iostream>
using namespace std;
int main(){
  int N,t,B,C,i,j;
  cin >> N;
  for(i = 0 ; i < N ; i++){
    for( B = 0, C = 0, j = 0; j < 10; j++){
      cin >> t;
      //どちらにも入らない。
      if(B > t && C > t) break;
      //どっちにも入るなら大きい方に入れる。
      else if(B < t && C < t){
	if(B < C) C = t;
	else B = t;
      }
      //片方にだけ入るなら入れる。
      else if(B < t) B = t;
      else if(C < t) C = t;
    }
    //最後までループしたらYES else NO
    if(j == 10) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

C++: #include<stdio.h>
bool tansaku(int count,int n1,int n2,int ans[],int a[],int b[],bool flg)
{
	if (count == 10)
	{
		return true;
	}
	if (flg == false)
	{
		if (a[n1] < ans[count])
		{
			n1++;					
			a[n1] = ans[count];
			count++;
			bool hozon = tansaku(count,n1,n2,ans,a,b,flg);
			if (hozon == true)
			{
				flg = true;
			}
		}
		if (b[n2] < ans[count])
		{
			n2++;
			b[n2] = ans[count];
			count++;
			bool hozon = tansaku(count,n1,n2,ans,a,b,flg);
			if (hozon == true)
			{
				flg = true;
			}
		}
	}
	return flg;
}
int main(void)
{
	int n = 0;
	int a[10] = {0};
	int damy[20] = {0};
	bool ans_flg[1000] = {false};
	scanf("%d",&n);
	for (int i = 0;i < n;i++)
	{
		scanf("%d %d %d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);
		if (tansaku(0,0,0,a,damy,damy,false) == true)
		{
			ans_flg[i] = true;
		}
	}
	for (int i = 0;i < n;i++)
	{
		if (ans_flg[i] == true)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	return 0;
}

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

bool flag;
int a[10];

void dfs(int idx, int l, int r) {
   if (idx == 10) {
      flag = true;
      return;
   }

   int val = a[idx];
   if (l < val) dfs(idx+1, val, r);
   if (r < val) dfs(idx+1, l, val);
}

int main() {
   int N;
   cin >> N;
   while (N--) {
      for (int i = 0; i < 10; i++) cin >> a[i];
      flag = false;
      dfs(0, -1, -1);
      puts(flag ? "YES" : "NO");
   }
   return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
stack<int> r,l;
int m[10],hantei=0;;

void dfs(int i){
  //cout<< i << endl;///////////
  if(i==10)hantei=1;
  if(m[i]>r.top()){
    r.push(m[i]);
    dfs(i+1);
    r.pop();
  }
  if(m[i]>l.top()){
    l.push(m[i]);
    dfs(i+1);
    l.pop();
  }
}

int main(){
  int b,i;
  cin >> b;
  for(int k=0;k<b;k++){
    for(int j=0;j<10;j++)cin>>m[j];  
    r.push(m[0]);
    l.push(0);
    i=1;
    hantei=0;
    dfs(i);
    if(hantei==1)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
   
  }
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int a[10];
bool dfs(int cur,int l,int r){
	if(cur==10){
		return true;
	}
	return (a[cur]>l && dfs(cur+1,a[cur],r)) || (a[cur]>r && dfs(cur+1,l,a[cur]));
}
int main(){
	ios::sync_with_stdio(false);
	int T;
	cin>>T;
	while(T--){
		for(int i=0;i<10;i++)
			cin>>a[i];
		puts(dfs(0,0,0)?"YES":"NO");
	}
	return 0;
}

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

using namespace std;

int N,balls[1000][10];
string result[1000];

void saiki(int Bnow,int Cnow,int next,int roop)
{
	if(next == 10)
	{
		result[roop] = "YES";
	}
	else
	{
		if(Bnow < balls[roop][next])
		{
			saiki(balls[roop][next],Cnow,next+1,roop);
		}
		if(Cnow < balls[roop][next])
		{
			saiki(Bnow,balls[roop][next],next+1,roop);
		}
	}
}

int main()
{
	for(int a = 0;a<1000;a++)
	{
		result[a] = "NO";
	}

	cin >> N;

	for(int i = 0;i<N;i++)
	{
		for(int a = 0;a<10;a++)
		{
			cin >> balls[i][a];
		}

		saiki(0,0,0,i);

		cout << result[i] << endl;
	}

}

C++: #include <iostream>

using namespace std;

int main(void){

  int a,b,c,out;
  a = b = c = out = 0;

  int n;
  cin >> n;
  while(n--){

    for( int l = 10 ; l > 0 ; l-- ){
      cin >> a;
      if( b < a ){
	b = a;
      }
      else if( c < a ){
	c = a;
      }
      else out = a;
    }
    if( out == 0 )cout << "YES" << endl;
    else cout << "NO" << endl;
  }
 return 0;
}

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

using namespace std;

int main(void){
	int n;

	cin >> n;
	for(int i=0;i<n;i++){
		int ball;
		stack<int> b,c;
		bool put=true;

		for(int j=0;put&&j<10;j++){
			cin >> ball;
			if(b.empty()||b.top()<ball)
				b.push(ball);
			else if(c.empty()||c.top()<ball)
				c.push(ball);
			else
				put=false;
		}
		cout << (put?"YES":"NO") << endl;
	}
}

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

typedef long long ll;
using namespace std;

typedef pair<int,int> P;

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

		stack<int> stk1;
		stack<int> stk2;

		for(int i=0;i<10;i++){
			int tmp;
			cin >> tmp;
			
			if(stk1.empty() || stk1.top() < tmp) stk1.push(tmp);
			else if(stk2.empty() || stk2.top() < tmp) stk2.push(tmp);
			else {
				cout << "NO" << endl;
				goto next;
			}
		}
		cout << "YES" << endl;
next:;
	}
}