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>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define Sort(x) sort((x).begin(),(x).end())
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

ll gcd(ll a,ll b){
    if(a<b){
        int t=a;a=b;b=t;
    }
    int c=a%b;
    while(c!=0){
        a=b;
        b=c;
        c=a%b;
    }
    return b;
}

ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}

bool isPrime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0)return false;
    }
    return true;
}

int kaizyo(int x){
    if(x==1)return x;
    else return x*kaizyo(x-1);
}

vector<int> v(10);
bool f=true;
bool dfs(int i,int top1,int top2){
    if(i==10)return true;
    
    if(top1>v[i]&&top2>v[i]){
        f=false;
        return false;
    }
    else if(top1<v[i]&&top2>v[i]) dfs(i+1,v[i],top2);
    else if(top1>v[i]&&top2<v[i])dfs(i+1,top1,v[i]);
    else if(top1<v[i]&&top2<v[i]){
        if(top1<top2)dfs(i+1,top1,v[i]);
        else dfs(i+1,v[i],top2);
    }
    if(f)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}
int main() {
    int n;
    cin>>n;
    rep(i,0,n){
        rep(i,0,10){
            cin>>v[i];
        }
        if(dfs(0,0,0))cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
int a[20];
using namespace std;
int main(){
	int m,n,p,q;
	scanf("%d",&n);
	while(n--){
		for(int i=0;i<10;i++){
			scanf("%d",&a[i]);
		}
		p = 0;q = -1;m = 1;
		for(int i=1;i<10;i++){
			if(q<0){
				if(a[i]>a[p]){
					p = i;m++;continue;
				}
				else{
					q = i;m++;continue;
				} 
			}
			else{
				if(a[p]>a[i]&&a[q]>a[i]) break;
				if(a[p]>a[i]&&a[q]<a[i]){
					q = i;m++;continue;
				} 
				if(a[p]<a[i]&&a[q]>a[i]){
					p = i;m++;continue;
				}
				if(a[p]<a[i]&&a[q]<a[i]){
					if(a[i]-a[p]>a[i]-a[q]){
						q = i;m++;continue;
					}
					else{
						p = i;m++;continue;
					}
				}
			}
		}
		if(m!=10) printf("NO\n");
		else printf("YES\n");
	} 
}

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

int inp[10];
int n;

bool dfs(int b, int c, int depth) {
  if (depth >= 10) return true;
  if (inp[depth] < b && inp[depth] < c) return false;
  if (inp[depth] > b) dfs(inp[depth], c, depth+1);
  if (inp[depth] > c) dfs(inp[depth], c, depth+1);
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) cin >> inp[j];
    cout << (dfs(0,0,0) ? "YES": "NO") << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;cin>>n;
  rep(i,n){
    bool out=true;
    vector<int>a(1,0);
    vector<int>b(1,0);
    rep(j,10){
      int in;cin>>in;
      if(a[a.size()-1]<in)a.pb(in);
      else if(b[b.size()-1]<in)b.pb(in);
      else out=false;
    }
    if(out)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }

}

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

int main(){
	int k;
	std::cin>>k;
	while(k>0){
		std::vector<int>v(10,0);
		std::stack<int>s;
		std::stack<int>s2;
		int a;
		for(int i=0;i<10;i++){
			std::cin>>v[i];
		}
		s.push(v[0]);
		s2.push(0);
		for(int i=1;i<10;i++){
			int x=s.top(),y=s2.top();
			if(v[i]>x&&v[i]>y){
				if(x>=y)s.push(v[i]);
				else s2.push(v[i]);
			}else if(v[i]>x&&v[i]<=y)s.push(v[i]);
			else if(v[i]<=x&&v[i]>y)s2.push(v[i]);
			else{
				std::cout<<"NO"<<std::endl;
				break;
			}if(i==9)std::cout<<"YES"<<std::endl;
		}
		k--;
	}
	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,r,n) for(int i=r;i<(int)n;i++)
using namespace std;
int in() {int x; cin >> x; return x;}

int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		bool ans = true;
		int r = -1, l = -2;

		for (int i = 0; i < 10; i++)
		{
			int x;
			cin >> x;

			if (min(r, l) > x)
			{
				ans = false;
				break;
			}
			if(r>l)swap(r,l);

			if(l<x)l=x;
			else r=x;

		}
		if(ans)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;


	}

}

C++: #include <bits/stdc++.h>
using namespace std;
int N;
int ar[10];
bool dfs(int i,int L,int R)
{
    if(i==10)
        return true;
    if(ar[i]<L&&ar[i]<R)
        return false;
    if(ar[i]>L)
    {
        if(dfs(i+1,ar[i],R))
            return true;
    }
    else if(dfs(i+1,L,ar[i]))
        return true;
    return false;
}
int main()
{
    scanf("%d",&N);
    while(N--)
    {
        for(int i=0;i<10;i++)
            scanf("%d",&ar[i]);
        if(dfs(0,0,0))
            printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int main(void){
    int a[11],fir,sec=0,i,n;
    cin>>n;
    while (n--) {
    
    for (i=0; i<10; i++) {
        cin>>a[i];
    }
    fir=a[0];
    for (i=1; i<10; i++) {
        if(fir<a[i])fir=a[i];
        else if(sec<a[i])sec=a[i];
        else break;
    }
    if(i==10)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
        
    }
    return 0;
}

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

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

C++: #include <iostream>
using namespace std;
int main(){
	int n,j,j1,j2,a;
	cin>>n;
	for(int i=0;i<n;i++){
		j1=j2=0;a=1;
		for(int k=0;k<10;k++){
			cin>>j;
			if(j1<j&&j2<j){if(j1<j2)j2=j;else j1=j;
			}else if(j1<j)j1=j;
			else if(j2<j)j2=j;
			else a=0;
		}
		if(a==1)cout<<"YES"<<endl;else cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n,a,b,c;
	bool f;
	cin>>n;
	for(int i=0;i<n;i++){
		f=true;b=0;c=0;
		for(int j=0;j<10;j++){
			cin>>a;
			if(b>a&&c>a){
				f=false;
				break;
			}else if(b<a && c<a){
				if(b>=c)b=a;
				else c=a;
			}else if(b<a){
				b=a;
			}else if(c<a){
				c=a;
			}
		}
		if(f)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}