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<string>
using namespace std;
int main(){
	int n,a[10];
	cin>>n;
	for(int i=0;i<n;i++){
		bool t=true;
		for(int j=0;j<10;j++)
			cin>>a[j];
		int b,c;
		if(a[0]>a[1]){
			b=a[0];
			c=a[1];
		}
		else{
			b=a[1];
			c=a[0];
		}
		for(int j=2;j<10;j++){
			if(c>a[j])
				t=false;
			if(c<a[j]&&b>a[j])
				c=a[j];
			if(b<a[j])
				b=a[j];
		}
		if(t==true)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	int n, s, t, c, p, f;
	cin >> n;
	
	while(n--){
		s = f = t = 0;
		for(int i = 0; i < 10; i++){
			cin >> p;
			if(p < s && p < t){
				f = 1;
			} else if(p > s){
				s = p;
			} else if(p > t){
				t = p;
			} else {
				f = 1;
			}
		}
		if(f == 0){
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	
	return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
int main(){
	int N, i;
	int num[11];
	cin >> N;
	while( N-- > 0 ){
		for( i = 0; i < 10; i++ ){
			cin >> num[i];
		}
		stack<int> st1;
		stack<int> st2;
		for( i = 0; i < 10; i++ ){
			if( st1.empty() ){
				st1.push(num[i]);
				continue;
			}else if( st2.empty() ){
				st2.push(num[i]);
				continue;
			}
			if( st1.top() > num[i] ){
				if( st2.top() > num[i] ){
					cout << "NO" << endl;
					break;
				}else{
					st2.push(num[i]);
				}
			}else{
				if( st2.top() < num[i] ){
					if( st1.top() > st2.top() ){
						st1.push(num[i]);
					}else{
						st2.push(num[i]);
					}
				}
			}
		}
		if( i == 10 ) cout << "YES" << endl;
	}
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		int A[10];
		for(int j=0;j<10;j++)scanf("%d",&A[j]);
		int X=A[0],Y=-1;
		bool f=true;
		for(int j=1;j<10;j++){
			if(X>A[j]&&Y>A[j]){
				f=false;
				break;
			}
			if(X>A[j])Y=A[j];
			else if(Y>A[j])X=A[j];
			else if(X>Y)X=A[j];
			else Y=A[j];
		}
		if(f)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int loop,ball,hidari,migi;
int main(){
  cin>>loop;
  for(int i=0;i<loop;i++){
    hidari=migi=0;
    for(int j=0;j<10;j++){
      cin>>ball;
      if(ball<=migi&&ball<=hidari){
	cout<<"NO"<<endl;
	j++;
	for(;j<10;j++){cin>>ball;}
      }
      if(hidari>migi){
	if(ball>hidari)hidari=ball;
	else migi=ball;
      }
      else{
	if(ball>migi)migi=ball;
	else hidari=ball;
	}
      if(j==9){
	cout<<"YES"<<endl;
      }
    }
  }
}

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

for(int i=0;i<n;i++)
{
	int a[10]={0};
	for(int j=0;j<10;j++)
	{
	int x;
	cin>>x;
	a[j]=x;
	}
	int b=0,c=0,k;
		for(k=1;k<10;k++)
		{
			if(b<a[k])b=a[k];
			else if(c<a[k])c=a[k];
			else 
			{
			cout<<"NO"<<endl;
			break;
			}
		}
		if(k==10)cout<<"YES"<<endl;
	/*for(int i=0;i<10;i++)
	{
	cout<<b[i]<<" ";

	}
	cout<<endl;
	for(int i=0;i<10;i++)
	{
	cout<<c[i]<<" ";
	}
	for(int i=0;i<10-1;i++)
	{
		if(b[i]>b[i+1] && b[i+1]!=0 || c[i]>c[i+1] && c[i+1]!=0)
		{
		cout<<"NO"<<endl;
		break;
		}
	else 
		{
		cout<<"YES"<<endl;
		break;
		}
	}*/
}
return 0;
}

C++: int main() {
  int n;
  cin >> n;
  while (n--) {
    int a, b = 0, c = 0;
    bool f = true;
    for (int i = 0; i < 10; ++i) {
      cin >> a;
      if (b < a) b = a;
      else if (c < a) c = a;
      else f = false;
    }
    if (f) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

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

int Data[10];

bool dfs(int a,int left,int right) {
	//cout << a << "/" << left << "/" << right << endl;
	if (a == 10) return true; 
	if (Data[a] > left) {
		//Add a to the left
		if(dfs(a+1,a,right)) return true;
	}
	else if (Data[a] > right) {
		//Add a to the right
		if(dfs(a+1,left,a)) return true;
	}
	return false;
}

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

C++: #include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <vector>



int t;
std::vector<int> balls(10);


int dfs(int d,int a,int b)
{
  if(d==10)
    {
      return 1;
    }

  //

  if(balls[d] > a   )
    {
      if(dfs(d+1,balls[d],b) == 1 )
        return 1;
    }

  if(balls[d] > b)
    {
      if( dfs(d+1,a,balls[d]) == 1)
        return 1;
    }

  return 0;
}

int main(int argc,char* argv[])
{
  //freopen("in.txt","r",stdin);
  std::cin>>t;
  while(t--)
    {
      for(int i = 0 ; i < 10 ; i++)
        std::cin >> balls[i];
      if(dfs(0,0,0) == 1 )
        std::cout<<"YES"<<std::endl;
      else
        std::cout<<"NO"<<std::endl;
    }
  return 0;
}

C++: #include <stdio.h>
int main(void)
{
	int a,b,c[10]={0},d,e,f,g,h,i;
	int e=1;
	scanf("%d",&a);
	for (b=0;b<a;b++)
	{
		e=1;
		for (i=0;i<10;i++)
		{
			scanf("%d",&f);
			c[i]=f;
		}
		if (e==1)
		{
			for (g=1;g<8;g++)
			{
				if (c[g-1]<c[g]||c[g-1]<c[g+1])
				{
					e=0;
				}
				else 
				{
					e=1;
				}
			}
		}
		if (e==0)
		{
			printf("Yes\n");
		}
		if (e==1)
		{
			printf("NO\n");
		}
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  int a[10];
  int b[6];
  int c[6];
  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;
  }
}

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

int main(){
	int b, c, n, a, i, j;
	bool executable;
	cin >> n;
	for(i=0;i<n;i++){
		c=0;
		executable = true;
		cin>>a;
		b=a;
		for(j=1;j<10;j++){
			if(a-b < 0){
				if(a-c < 0){
					executable = false;
					break;
				}else{
					c = a;
				}
			}else{
				if(a-c < 0){
					b = a;
				}else{
					if(a-b < a-c){
						b = a;
					}else{
						c = a;
					}
				}
			}
			cin>>a;
		}
		if(executable){
			cout << "YES\n";
		}else{
			cout << "NO\n";
		}
	}
	return 0;
}

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

using namespace std;
const int maxn = 11;

int num[maxn];

int main()
{
    int ite=0;
    scanf("%d", &ite);
    while(ite--)
    {
        bool flag = true;
        for(int i=0; i<10; ++i)
        {
            scanf("%d", &num[i]);
        }

        stack<int> a, b;

        a.push(num[0]);
        int i = 1;
        while(i<10 && num[i]>a.top()){
            a.push(num[i++]);
        }
        if(i+1<10) b.push(num[i++]);
        for(; i<10; ++i){
            int dif1 = num[i] - a.top(), dif2 = num[i]-b.top();
            if(dif1<0 && dif2<0) {
                flag = false;
                break;
            }
            else if(dif1>0 && dif2>0){
                if(a.top()<b.top()) b.push(num[i]);
                else a.push(num[i]);
            }
            else{
                if(dif1>0) a.push(num[i]);
                else b.push(num[i]);
            }
        }
        if(flag)  printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}