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 <algorithm>
using namespace std;

int balls[10];
int b[10];
int c[10];
int b_size;
int c_size;

bool isAscending() {
    for (int i = 0; i < b_size - 1; i++) {
        if (b[i] > b[i + 1]) {
            return false;
        }
    }
    for (int i = 0; i < c_size - 1; i++) {
        if (c[i] > c[i + 1]) {
            return false;
        }
    }
    return true;
}

bool dfs(int k, bool isB) {
    if (isB == true) {
        b[b_size++] = balls[k];
    } else {
        c[c_size++] = balls[k];
    }
    bool res = false;
    if (k == 9) {
        if (isAscending() == true) {
            res = true;
        }
    } else {
        if (dfs(k + 1, true) == true) {
            res = true;
        } else if (dfs(k + 1, false) == true) {
            res = true;
        }
    }
    if (isB == true) {
        b[--b_size] = 0;
    } else {
        c[--c_size] = 0;
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    while (n--) {
        fill_n(balls, 10, 0);
        fill_n(b, 10, 0);
        fill_n(c, 10, 0);
        b_size = c_size = 0;
        for (int i = 0; i < 10; i++) {
            cin >> balls[i];
        }
        bool res = dfs(0, true);
        if (res == true) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

int main(){
    int n;
    cin >> n;
    rep(p, n){
        vector<int> v(10);
        rep(i,10) cin >> v[i];
        int a=0, b=0;
        bool is = true;
        for(int i=0; i < 10; i++){
            if(v[i] < a && v[i] < b){is = false; break;}
            if(a < b) (b<v[i]?b:a) = v[i];
            else (a<v[i]?a:b) = v[i];
        }
        cout << (is?"YES":"NO") << endl;
    }
}

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

int BALLNUM = 10;

	static int data[10];
class balldata
{
private:
	//static std::vector <int> data;
	//int ballnum;
public:
	balldata(int datanum);
	static void enter();
	static void answer();
	static bool check();
	static bool check(int num,int right,int left);
};




int main()
{
	balldata ball(BALLNUM);

int N;
	std::cin >> N;
	for (int i = 0; i < N; i++)
	{
		ball.enter();
		ball.answer();
	}
}


balldata::balldata(int datanum)
{
	//ballnum = datanum;
	//data.resize(datanum);
}



void balldata::enter()
{
	for (int i = 0; i < 10; i++)
	{
		std::cin >> data[i];
	}
	return;
}

bool balldata::check(int num,int right,int left)
{
	//if (num == data.size())return true;
	if (num == 10)return true;
	if (balldata::check(num + 1, right, data[num])&&left<data[num]){ return true; }
	if (balldata::check(num + 1, data[num], left)&&right<data[num]){ return true; }

	return false;
}
bool check()
{
	return balldata::check(0, 0, 0);
}

void balldata::answer()
{ 
	if (balldata::check(0, 0, 0))
	{
		std::cout << "YES" << std::endl;
	}
	else
	{
		std::cout << "NO" << std::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;
		}
			}  	
   }
   int ins;
       for(int i=0;i<n;i++)
  {
  	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");
		else printf("NO");
		if(i!=n-1)printf("\n");
			}  	
   }

C++: #include <iostream>
using namespace std;
int n;
int ball[10];
bool b1;

bool hako(int top1,int top2,int i) {
  if(i<=9) {
    if((ball[i] > top1) && (ball[i] > top2)) {
      return hako(ball[i],top2,i+1) || hako(top1,ball[i],i+1);
    }
    else if(ball[i] > top1) {
      return hako(ball[i],top2,i+1);
    }
    else if(ball[i] > top2) {
      return hako(top1,ball[i],i+1);
    }
    else
      return false;
  }
  return true;
}

int main() {
  cin >> n;
  for(int i=0;i<n;i++) {
    for(int i=0;i<10;i++) {
      cin >> ball[i];
    }
    if(b1 = hako(0,0,0),b1) printf("YES\n");
    else printf("NO\n");
  }
}

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

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

    for(int i = 0; i < N; i++) {
        bool ans = true;
        int B_top = 0, C_top = 0;
        vector<int> ball(10);
        for(int i = 0; i < 10; i++) {
            cin >> ball[i];
        }
        for(int j = 0; j < 10; j++) {
            if(B_top < ball[j]) {
                B_top = ball[j];
            }
            else if(C_top < ball[j]) {
                C_top = ball[j];
            }
            else {
                ans = false;
                break;
            }
        }
        if(ans) {
            cout << "YES" << endl;
        }
        else {
            cout << "NO" << endl; 
        }
    }
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        bool ans(true);
        int in[10],a,b;
        for(int j=0;j<10;j++){
            cin >> in[j];
        }
        a = in[0];   b = 0;
        for(int j=1;j<10;j++){
            if(a<in[j]||b<in[j]){
                if(a<in[j]&&b<in[j]){
                    if(abs(a-in[j])>=abs(b-in[j])){
                        b = in[j];
                    }else{
                        a = in[j];
                    }
                }else if(a<in[j]){
                    a = in[j];
                }else{
                    b = in[j];
                }
            }else{
                ans = false;
            }
        }
        if(ans)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}

C++: #include<cstdio>

int main(){
	int n, b, c, t;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			b = c = 0;
			scanf("%d", &t);
			if(b < t){
				b = t;
			}else{
				if(c < t){
					c = t;
					if(b < c){
						t = b;
						b = c;
						c = t;
					}
				}else{
					t = 0;
					break;
				}
			}
		}

		if(t){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}

C++: #include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



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

	for (int i = 0; i < n; i++)
	{
		int left = 0, right = 0;
		int ball[10];

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

		for (int j = 0; j < 10; j++)
		{
			if (left < ball[j] && right < ball[j])
			{
				if (right < left)
				{
					left = ball[j];
				}
				else
				{
					right = ball[j];
				}
			}
			else if (left < ball[j])
				left = ball[j];
			else if (right < ball[j])
				right = ball[j];
			else
			{
				cout << "NO" << endl;
				break;
			}
		}

		if (right == ball[9] || left == ball[9]) cout << "YES" << endl;
	}

	return 0;
}