Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var num int
	fmt.Scan(&num)

	for i := 0; i < num; i++ {
		sc.Scan()
		line := sc.Text()

		insertCheck(line)
	}
}

func insertCheck(line string) {
	var B, C []int

	for _, v := range strings.Split(line, " ") {
		ball, _ := strconv.Atoi(v)
		switch {
		case len(B) == 0:
			B = append(B, ball)
		case B[len(B)-1] < ball:
			B = append(B, ball)
		case B[len(B)-1] >= ball:
			switch {
			case len(C) == 0:
				C = append(C, ball)
			case C[len(C)-1] < ball:
				C = append(C, ball)
			case C[len(C)-1] >= ball:
				fmt.Println("NO")
				return
			}
		}
	}
	fmt.Println("YES")
}

C++: #include<cstdio>
int n,j,lj,F;
int a[15],f[15];
int main()
{
	scanf("%d",&n);
	while(1)
	{
		j=0;F=0;lj=0;
		for(int i=1;i<=10;i++)
		f[i]=0,a[i]=0; 
		for(int i=1;i<=10;i++)
		scanf("%d",&a[i]);
		lj=1;
		for(int i=1;i<=10;i++)
		if(a[i+1]>a[lj]) f[lj]=1,lj=i+1;
		lj=0;
		for(int i=1;i<=10;i++)
		if(!f[i])
		{
			if(a[i]>a[lj]) lj=i;
			else {printf("NO\n");F=1;break;}
		}
		if(F) continue;
		printf("YES\n");
	}
}
/*
#include <iostream>  
  
using namespace std;  
  
const int N = 10;  
  
int main()  
{  
    int n;  
  
    cin >> n;  
    while(n--) {  
        bool ans = true;  
        int a, b=-1, c=-1;  
        for(int i=1; i<=N; i++) {  
            cin >> a;  
            if(ans) {  
                if(a > b)  
                    b = a;  
                else if(a > c)  
                    c = a;  
                else  
                    ans = false;  
            }  
        }  
  
        cout << (ans ? "YES" : "NO") << endl;  
    }  
  
    return 0;  
}  
*/

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

int main(){
	int n;
	cin>>n;
	
	for(int i=0;i<n;i++){
		int ball[10]={};
		for(int j=0;j<10;j++) cin>>ball[j];
		int a=0,b=0,k;
		for(k=0;k<10;k++){
			if(a<ball[k]) a=ball[k];
			else if(b<ball[k]) b=ball[k];
			else break;
		}
		if(k==10) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
return 0;
}

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

int main(){
	int N;
	cin>>N; 
	while(N-->0){
		int frist=0,last=0,a;
		string s = "YES";
		for(int i=0;i<10;i++){
			cin>>a;
			if(a>last){
				last = a;
			}else if(a>frist){
				frist = a;
			}else {
				frist = -1;
				s = "NO";
			}
		}
		cout<<s<<endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(void){
  int data;
  int data_set;
  int box1,box2;
  int i,j,k,l;
  bool f;

  cin>>data_set;
  for(i=0;i<data_set;i++){
    box1=0;
    box2=0;
    f=false;
    for(j=0;j<10;j++){
      cin>>data;
      if(data>box1&&data>box2){
	if(box1<box2){
	  box2=data;
	}else{
	  box1=data;
	}
      }
      else if(data>box1){
	box1=data;
      }
      else if(data>box2){
	box2=data;
      }
      else{
	f=true;
      }
    }
    if(f){
      cout<<"NO"<<endl;
    }else{
      cout<<"YES"<<endl;
    }
  }
  return(0);
}

C++: #include<iostream>
const int nn = 10;
int a[nn];
using namespace std;
bool dfs()
{
	int left = -1;
	int right = -1;
	
	int T = 0;
	while (T<nn)
	{
		if (right < a[T])
		{
			right = a[T++];
			continue;
		}
		if (left < a[T])
		{
			left = a[T++];
			continue;
		}
		return false;
	}
	return true;
}
int main()
{
	//freopen("in.txt", "r", stdin);
	int N;
	scanf("%d", &N);
	while (N--)
	{
		for (int i = 0; i < nn; i++)
			scanf("%d", &a[i]);
		if (dfs())
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}

C++: #include<iostream>

using namespace std;

char *solve(int d[10])
{
	int l,r;
	l=r=0;
	for(int i=0;i<10;i++)
	{
		if(l>d[i]&&r>d[i])
		{
			return "NO";
		}
		else if(l<d[i]&&r>d[i])
		{
			l=d[i];
		}
		else if(r<d[i]&&l>d[i])
		{
			r=d[i];
		}
		else if(r<l)
		{
			l=d[i];
		}
		else
		{
			r=d[i];
		}
	}
	return "YES";
}

int main(void)
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int d[10];
		for(int j=0;j<10;j++)
		{
			cin>>d[j];
		}
		cout<<solve(d)<<endl;
	}
}

C++: #include<cstdio>
int main()
{
  int n;
  scanf("%d",&n);
  int a[n][10];
  for(int i=0;i<n;i++)
  {
  	for(int j=0;j<10;j++)
	  {
	  	scanf("%d",&a[i][j]);
	  	
			}  	
   }
   
    for(int i=0;i<n;i++)
  {
  	int k=a[i][0];
  	a[i][0]=0;
  	for(int j=0;j<10;j++)
	  {
	    if(a[i][j]>k)
	    {
	    	k=a[i][j];
	    	a[i][j]=0;
		}
			}  	
   }
 
       for(int i=0;i<n;i++)
  {  
    int ins;
  	int count=0;
  	int judge=1;
  	for(int j=0;j<10;j++)
	  {
      if(a[i][j]==0)continue;
      if(count==0)
      {
      	ins=a[i][j];
      	count++;
	  }
      else
      {
      	if(a[i][j]<ins) {
		  judge=0;break;
	}
      	count++;
	  }
		}
		if(judge)printf("YES\n");
		else printf("NO\n");
			}  	
			
			return 0;
   }

C++: #include <cstdio>
int a[10];

bool dfs(int k, int B, int C){
    if(k == 10) return true;
    if(a[k] > B){
        if(dfs(k + 1, a[k], C))
            return true;
    }
    if(a[k] > C){
        if(dfs(k + 1, B, a[k]))
            return true;
    }
    return false;
}

void solve(){
    if(dfs(0, 0, 0))
        printf("YES\n");
    else
        printf("NO\n");
}

int main(int argc, char const *argv[]){

    int t;
    scanf("%d", &t);
    while(t --){
        for(int i = 0; i < 10; i ++)
            scanf("%d", &a[i]);
        solve();
    }

    return 0;
}

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

using namespace std;

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

  int ball_num = 10;
  for(int i=0;i<n;i++){
    vector<int> a;
    bool flag = true;
    for(int j=0;j<ball_num;j++){ 
      int tmp;
      cin >> tmp;
      a.push_back(tmp);
    }

    int b=0;
    int c=0;
    for(int i=0;i<ball_num;i++){
      if(b<=c){
	swap(b, c);
      }
      
      // b > c

      if(b < a[i]){
	b = a[i];
      }else{
	if(c < a[i]){
	  c = a[i];
	}else{
	  flag = false;
	}
      }

      if(flag==false){
	break;
      }
    }

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

  

}

C++: #include<iostream>

using namespace std;

int balls[15];

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

    int last_ball = balls[ball_index];
    if (last_ball > right) return dfs(ball_index+1, last_ball, left);
    if (last_ball > left)  return dfs(ball_index+1, right, last_ball);

    return false;
}

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

    if (dfs(0, 0, 0)) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

int main(int argc, char const* argv[]) {

    int n;
    cin >> n;

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

    return 0;
}

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

using namespace std;

vector<int> nums;
int h, w;

bool dfs(int idx, int x, int y) {
	if (idx == 10) {
		return true;
	}
	bool ok = false;
	int z = nums[idx];
	if (x < z) {
		ok = dfs(idx + 1, z, y);
		if (ok) {
			return true;
		}
	}
	if (y < z) {
		ok = dfs(idx + 1, x, z);
		if (ok) {
			return true;
		}
	}

	return false;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		nums.assign(10, 0);
		for (int j = 0; j < 10; j++) {
			cin >> nums[j];
		}
		bool ok = dfs(0, -1, -1);
		cout << (ok ? "YES" : "NO") << endl;
	}
	return 0;
}

C++: /*
input:
2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
output:
YES
NO
*/

#include <cstdio>

//&#36755;入
int a[10];

//深度&#20248;先放第K个球
bool dfs(int k, int B, int C){
	//若10个球都放完
	if(k == 10) return true;
	if(a[k] > B){
		//能放&#36827;B道
		if(dfs(k + 1, a[k], C))
			return true;
	}
	if(a[k] > C){
		//能放&#36827;C道
		if(dfs(k + 1, B, a[k]))
			return true;
	}
	//都不能放
	return false;
}

void solve(){
	if(dfs(0, 0, 0))
		printf("YES\n");
	else
		printf("NO\n");
}

int main(int argc, char const *argv[]){

	int t;
	scanf("%d", &t);
	while(t --){
		for(int i = 0; i < 10; i ++)
			scanf("%d", &a[i]);
		solve();
	}

	return 0;
}