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>

int main(void)
{
	int tubeM[10];
	int tube1[10], tube2[10];
	int i, j, k;
	int n;
	int ans;
	
	scanf("%d", &n);
	
	while(n){
		
		for (i = 0; i < 10; i++){
			scanf("%d", &tubeM[i]);
			
			tube2[i] = 0;
		}
		
		tube1[0] = tubeM[0];
		for (i = 1, j = 0, k = 0; i < 10; i++){
			if (tubeM[i] > tube1[j]){
				tube1[j] = tubeM[i];
				j++;
			}
			else {
				tube2[k] = tubeM[i];
				k++;
			}
		}
		
		ans = 0;
		for (i = 1; tube2[i] != 0; i++){
			if (tube2[i - 1] > tube2[i]){
				ans = 1;
				break;
			}
		}
		
		if (ans == 0){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
		
		n--;
	}
	
	return (0);
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[20];
int b[20],c[20];
int n;
bool flag;
void dfs(int i,int j,int k)
{
    if(i == 10)
    {
        flag = true;
        return ;
    }
    if(flag == true)
        return ;
    if(a[i] > c[j - 1]){
       /* printf("游街、?\n");
        printf("a[i] = %d\n",a[i]);
        printf("c[j - 1] = %d\n",c[j - 1]);*/
        c[j] = a[i];
       /* printf("c[j] = %d\n",c[j]);
        printf("j = %d\n",j);
        printf("i = %d\n",i);*/
        dfs(i + 1,j + 1,k);
        memset(c,0,sizeof(c));
    }
    //printf("\n\n\n\n");
    if(a[i] > b[k - 1]){
        //printf("a[i] = %d\n",a[i]);
       // printf("b[k - 1] = %d\n",b[k - 1]);
        b[k] = a[i];
       /* printf("b[k] = %d\n",b[k]);
        printf("k = %d\n",k);
        printf("i = %d\n",i);*/
        dfs(i + 1,j,k + 1);
        
    }
   // printf("OKOKOK\n\n\n\n");
    return ;
}
int main()
{
    scanf("%d",&n);
    while(n --)
    {
        for(int i = 0; i < 10; i++)
            scanf("%d",&a[i]);
        flag = false;
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));

        dfs(0 , 1, 1);
        //printf("b[1] = %d\n",b[1]);

        if(flag == true)
            printf("YES\n");
        else
            printf("NO\n");
       /* for(int i = 0; i <= 10; i++)
            printf("%d ",c[i]);
        printf("\n");
        for(int i = 0; i <= 10; i++)
            printf("%d ",b[i]);
        printf("b[1] = %d\n",b[1]);*/
    }
    return 0;
}
/*
100
1 2 3 4 8 5 6 7 9 10
*/

C++: #include <iostream>

using namespace std;

int main(){
  int n, count;
  int ball_list[10];
  int max_val;
  bool flag;

  cin >> n;

  for(int i = 0; i < n; i++){
    for(int j = 0; j < 10; j++){
      cin >> ball_list[j];
    }

    flag = true;
    for(int j = 0; j < 10; j++){
      count = 0;
      max_val = ball_list[j];
      for(int k = j; k >= 0; k--){
        if(max_val < ball_list[k]){
          max_val = ball_list[k];
          count++;
        }
      }

      if(count >= 2){
        flag = false;
      }
    }
    if(flag){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }

  return 0;
}

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

using namespace std;
typedef long long ll;


int a[10];
int lt, rt;

bool put(int cur,int lt, int rt) {
	if (a[cur] < lt && a[cur] < rt)
		return false;
	bool lres,rres;
	if( cur > lt) {
		lres = put(cur + 1, a[cur], rt);
	}
	if( cur > rt) {
		rres = put(cur + 1, lt, a[cur]);
	}
	if (lres || rres)
		return true;
	else
		return false;
}

int main() {
	int T;
	cin >> T;
	for (int t = 0; t < T; t++) {
		for (int i = 0; i < 10; i++) {
			cin >> a[i];
		}
		lt = rt = 0;
		if (put(0, 0, 0))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

vector<int> ball;
vector<int> A;
vector<int> B;
bool flag;

void solve(int i){
	if(flag == true) return;
	if(i == 10){
		for(int i = 1; i < A.size(); ++i){
			if(A[i - 1] > A[i]){
				return;
			}
		}
		for(int i = 1; i < B.size(); ++i){
			if(B[i - 1] > B[i]){
				return;
			}
		}
		flag = true;
	} else {
		A.push_back(ball[i]);
		solve(i + 1);
		A.pop_back();
		
		B.push_back(ball[i]);
		solve(i + 1);
		B.pop_back();
	}
}

int main(){
	int T; scanf("%d", &T);
	while(T--){
		ball.clear();
		for(int i = 0; i < 10; ++i){
			int digit; scanf("%d", &digit);
			ball.push_back(digit);
		}
	
		flag = false;
		solve(0);
		printf(flag ? "YES\n" : "NO\n");
	}
}

C++: #include <iostream>

using namespace std;

int ball[10];
bool dfs(int n,int l,int r){
	if(n == 10)
		return true;
	if(ball[n]>l&&dfs(n+1,ball[n],r))
		return true;
	if(ball[n]>r&&dfs(n+1,l,ball[n]))
		return true;
	return false;
}


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

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

using namespace std;

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


  for(int q=0; q<n;q++) {
    
    vector <int> ball;
    
    ball.resize(10);
    for(int i=0;i<10;i++) cin >> ball[i];
    reverse(ball.begin(),ball.end());
    
    int a[10] = {0},b[11] = {0};
    a[0] = ball.back();
    ball.pop_back();
   int ac = 1;
   int bc = 1;
   int t,flg = 0;
   
   //    cout << "t:a:b" << endl;
   for(int i=0;i<9;i++) {
     
     t = ball.back();
     ball.pop_back();
     // cout << t <<":"<< a[ac-1]<<":" << b[bc-1]<<endl;
     
     if(t > a[ac-1] && a[ac-1] >= b[bc-1]) {
       a[ac] = t;
       ac++;
     }
     else if(t > b[bc-1]) {
       b[bc] = t;
       bc++;
     } else {
       flg = 1;
	break;
     }
    }
   
   if(flg == 0) cout << "YES" <<  endl;
   else cout << "NO" << endl;
   
   ball.clear();
   
  }

  return 0;

}

C++: #include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;

int main(){
	int b=-1,c=0,m,n,s;
	cin>>m;
	for(int i=0;i<m;i++){
		s=0;
		for(int j=0;j<10;j++){
			cin>>n;
			if(n>b&&n>c){
				if(b>c)b=n;
				else c=n;
			}
			else if(n>b)b=n;
			else if(n>c)c=n;
			else {cout<<"NO"<<endl;s=1;break;}
		}
		if(s==0)cout<<"YES"<<endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  int a[10];
  int b[11];
  int c[11];
  int k=0;
  int k2=0;
  int out=0;
  cin>>n;
  b[0]=0;
  c[0]=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>a[j];
      if(b[k]<a[j]){
	b[k+1]=a[j];
	k++;
      }
      else if(c[k2]<a[j]){
	c[k2+1]=a[j];
	k2++;
      }
      else{
	out=1;
	break;
      }
    }
    if(out==0) cout << "YES" << endl;    
    else if(out==1) cout << "NO" <<endl;
    out=0;
  }
}

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

int main(){
  int n;
  cin >> n;
  while(n--){
    int l=0, r=0, tmp;
    bool flag=true;
    for(int i=0; i<10; i++){
      cin>>tmp;
      if(l>=r && l<tmp){l=tmp; continue;}
      if(l>=r && r<tmp){r=tmp; continue;}
      if(r>l  && r<tmp){r=tmp; continue;}
      if(r>l  && l<tmp){l=tmp; continue;}
      flag=false;
    }
    if(flag) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}

C++: #include<iostream>

int r=0,l=0;

int main(){
	int n;
	std::cin>>n;
	for(int i=0;i<n;++i){
		bool f=true;
		for(int j=0;j<10;++j){
			int a;
			std::cin>>a;
			if(r<a&&l<a){
				if(r<=l)l=a;
				else r=a;
			}else if(r<a)r=a;
			else if(l<a)l=a;
			else f=false;
			//std::cout<<r<<" "<<l<<" "<<f<<std::endl;
		}
		if(f)std::cout<<"YES"<<std::endl;
		else std::cout<<"NO"<<std::endl;
		r=0,l=0;
	}
	return 0;
}