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<iostream>
using namespace std;
int main(){
  int ball[10],bal[10],n,a,flg;
  cin>>n;
  for(int i=0;i<n;i++){
    flg=0;
    for(int j=0;j<10;j++){
      ball[i]=0;
      bal[i]=0;
    }
    for(int k=0;k<10;k++){
      cin>>a;
      if(ball[i]<a){
	ball[i]=a;
      }else if(bal[i]<a){
	bal[i]=a;
      }else{
	flg=1;
      }
    }
    if(flg==0){
      cout<<"YES"<<endl;
    }if(flg==1){
      cout<<"NO"<<endl;
    }
  }
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int a[20], b[20], c[20];
		for(int j = 0; j < 10; j++){
			cin >> a[j]; 
		}

		int ai = 0, bi = 0, ci = 0;
		b[0] = 0;
		c[0] = 0;
		while(ai < 10){
			if(b[bi] > c[ci]){
				if(a[ai] > b[bi]){
					bi++;
					b[bi] = a[ai];
					ai++;
				}else if(a[ai] > c[ci]){
					ci++;
					c[ci] = a[ai];
					ai++;
				}else{
					break;
				}
			}else{
				if(a[ai] > c[ci]){
					ci++;
					c[ci] = a[ai];
					ai++;
				}else if(a[ai] > b[bi]){
					bi++;
					b[bi] = a[ai];
					ai++;
				}else{
					break;
				}
			}
		}

		if(ai == 10){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
using namespace std;
int a[11];
int a1[11];
int pn=0;
int Flag;
void dfs(int i)
{
    if(Flag==1)
        return;

    if(a[i]>a[a1[pn]])
    {
        a1[++pn]=i;
        for(int m=i+1;m<=10;m++)
        {
            dfs(m);
        }
    }
    else
        return;
    int flag=0;
    for(int m=i+1;m<=10;m++)
    {
        if(a[m]>a[i])
            flag=1;
    }
    int flag2;
    if(flag==0||i==10)
    {
        int a2[11];
        int pm=0;
        for(int n=1;n<=10;n++)
        {
            flag2=0;
            for(int m=1;m<=pn;m++)
            {
                if(n==a1[m])
                   flag2=1;
            }
            if(!flag2)
            {
               a2[++pm]=n;
            }
        }
        int flag3=0;
        for(int m=1;m<pm;m++)
        {
            if(a[a2[m]]>a[a2[m+1]])
                flag3=1;
        }
        if(flag3==0)
        {
            Flag=1;
            return;
        }
        else
        {
            pn--;
            return;
        }
    }

}
int main()
{
    int n;
    
    scanf("%d",&n);
    getchar();
    a[0]=-1;
    a1[0]=0;
    for(int i=1;i<=n;i++)
    {
        Flag=0;
        for(int j=1;j<=10;j++)
        {
            scanf("%d ",&a[j]);
        }
        dfs(1);
        if(Flag==0)
        {
            printf("NO\n");
        }
        else
            printf("YES\n");
    }
    return 0;
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int n;scanf("%d",&n);
  for(int i=0;i<n;i++){
    int a=-1,b=0,j=0;
    for(;j<10;j++){
      int c;scanf("%d",&c);
      if(a<b&&b<c){
	b=c;
      }else if(b<a&&a<c){
	a=c;
      }else if(a<c&&c<b){
	a=c;
      }else if(b<c&&c<a){
	b=c;
      }else{
	break;
      }
    }
    if(j==10) puts("YES");
    else puts("NO");
  }
}

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] && st2.top() > num[i] ){
				cout << "no" << endl;
				break;
			}else if( st1.top() > st2.top() ){
				st1.push(num[i]);
			}else{
				st2.push(num[i]);
			}
		}
		if( i == 10 ) cout << "yes" << endl;
	}
}/*
int div( int top, int  ){

}*/

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n;
    cin >> n;
    rep(i, n)
    {
        stack<int> b, c;
        int a[10];
        bool flag = 0;
        rep(i, 10) cin >> a[i];

        b.push(a[0]);
        c.push(0);
        for (int i = 1; i < 10; i++)
        {
            int dis1 = a[i] - b.top(), dis2 = a[i] - c.top();
            if (dis1 < 0 && dis2 < 0)
            {
                flag = 1;
                break;
            }
            if (dis1 < dis2 && dis1 > 0)
            {
                b.push(a[i]);
            }
            else
            {
                c.push(a[i]);
            }
        }
        if (flag == 0)
        {
            OP("YES")
        }
        else
        {
            OP("NO")
        }
    }

    return 0;
}

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

int N;
int arr[15];
int left_arr[15]={0},right_arr[15]={0};
bool flag;

void dfs(int l,int r){
    if(l>1&&left_arr[l-1]<left_arr[l-2]){
        return;
    }
    else if(r>1&&right_arr[r-1]<right_arr[r-2]){
        return;
    }

    if(l+r==10){
        flag=true;
        return;
    }


    left_arr[l]=arr[l+r];
    dfs(l+1,r);

    right_arr[r]=arr[l+r];
    dfs(l,r+1);


}

int main(){
    cin >> N;
    while(N>0){
        N--;

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

        flag=false;
        dfs(0,0);
        if(flag){
            cout<<"YES\n";
        }else{
            cout<<"NO\n";
        }


    }


    return 0;
}

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

int main()
{
	int ball = 10;
	int n,k;
	cin >> n;
	queue<int> a;
	int b = 0 , c = 0;
	queue<bool> flag;


	for (int i=0; i < n; i++){
		for (int j=0; j < ball; j++){
			cin >> k;
			a.push( k );
		}
		b = a.front();
		a.pop();
		
		for (int j=1; j <= (ball-1); j++){
			if (a.front() > b && a.front() > c){
				if (a.front() - b > a.front() - c)
					c = a.front();

				else
					b = a.front();

			}else if(a.front() > b){
				b = a.front();
			
			}else if(a.front() > c){
				c = a.front();
			
			}else {
				flag.push(false);
				j = ball;
				a.empty();
			}
			a.pop();
			if (j == (ball-1)){
				flag.push(true);
				a.empty();
			}
		}
	}

	for (int i = 0; i < n; i++){
		if (flag.front()){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
		flag.pop();
	}



	return 0;
}