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++: public class Main {
	void run() {
		scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] boll = new int[10];
		for(int k = 0; k < n; k++) {
			for(int i = 0; i < 10; i++) {
				boll[i] = scan.nextInt();
			}
			int judg = 0;
			for(int i = 0; i < n; i++) {
				int right,left;
				right = boll[0];
				left = 0;
				for(int m = 1; m < 10; m++) {
					if(right > boll[m]) {
						if(left < boll[m]) {
							left = boll[m];
						}
						else {
							judg = 0;
							break;
						}
					}
					else if(right < boll[m]) {
						right = boll[m];
					}
					judg = 1;
				}
				if(judg == 0) {
					System.out.println("NO");
				}
				else {
					System.out.println("YES");
				}
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

C++: #include<iostream>
using namespace std;
int main(void)
{
int n;
cin>>n;
int b[10]={0};
int c[10]={0};
for(int i=0;i<n;i++)
{
	int a[10];
	for(int j=0;j<10;j++)
	{
	int x;
	cin>>x;
	a[j]=x;
	}
	int k=0;
	for(int j=0;j<10-1;j++)
	{
	
	if(a[j]>a[j+1])
		{
		b[k]=a[j];
		k++;
		}
	else c[j]=a[j];
	}
	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++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,s;
  cin >> n;
  for(int i=0;i<n;i++){
    int a=0,b=0,flg=0;
    for(int j=0;j<10;j++){
      cin >> s;
      if(s > a) a=s;
      else if(s > b) b=s;
      else flg=1;
    }
    printf("%s\n",flg==0?"YES":"NO");
  }
}

C++: #include<iostream>
main(){
int n,i,A,B,C,f;
for(std::cin>>n;n-->0;puts(f?"NO":"YES"))
  for(B=C=f=i=0;std::cin>>A,i<10;i++){
  if(B<A)B=A;else C<A?C=A:f=1;
 }
}

C++: #include <stdio.h>

int main(void)
{
	int tubeM[10];
	int tube1[10], tube2[10];
	int i, j, k;
	int n;
	int ans;
	
	for (i = 0; i < 10; i++){
		tube2[i] = 0;
	}
	
	scanf("%d", &n);
	
	while(n){
		for (i = 0; i < 10; i++){
			scanf("%d", &tubeM[i]);
		}
		
		tube1[0] = tubeM[0];
		for (i = 1, j = 0, k = 0; i < 10; i++){
			if (tubeM[i] > tube1[j]){
				tube1[j + 1] = 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 <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");
  }
}