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 n,A,B,f,ball;
	cin >> n;
	
	for(int i=0;i<n;i++){
		A=0;
		B=0;
		f=0;
		for(int j=0;j<10;j++){
			cin >> ball;
			if(ball<A && ball<B) {f=1;break;} 
			else if(A<ball && ball<B) A=ball;
			else if(ball<A && B<ball) B=ball;
			else if(A<B) B=ball;
			else A=ball;
		}
		
		if(f==0) cout << "YES" << endl;
		else cout << "NO" << endl;
		
	}
}

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

int main() {
	int n, x, z;
	cin >> n;

	for (int i = 0; i < n; i++) {
		vector< vector<int> > v;
		v.assign(3, { 0 });
		z = 1;
		for (int j = 0; j < 10; j++) {
			cin >> x;
			for (int k = 0; k < z; k++) {
				if (v[k].back() < x) {
					v[k].push_back(x);
					break;
				}

				if (k == z - 1) {
					v[z].push_back(x);
					z++;
					break;
				}
			}

			if (z == 3) {
				x = -1;
				break;
			}
		}

		if (x == -1) {
			cout << "NO";
		}
		else {
			cout << "YES";
		}
		cout << endl;
	}
	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=1; 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.pop();
			if (j == (ball-1))
				flag.push(true);
		}
	}

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



	return 0;
}

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


int main(){
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		int ball[10];
		for(int j=0;j<10;j++)scanf("%d",&ball[j]);
		
		stack<int> S,Q;
		int a[2]={0};
		S.push(ball[0]);
		Q.push(a[1]);
		
		int k=1,check[2];
		bool OK = false;
		while(1){
			printf("%d,%d\n",a[0],a[1]);
			a[0] = S.top();
			a[1] = Q.top();
			if(a[0] < ball[k]){
				S.push(ball[k]);
				Q.push(a[1]);
				k++;
				if(k >= 11){
					OK = true;
					break;
				}
			}else if(a[1] < ball[k]){
				Q.push(ball[k]);
				S.push(a[0]);
				k++;
				if(k >= 11){
					OK = true;
					break;
				}
			}else{
				if(check[0] == a[0] && check[1] == a[1])break;
				check[0] = a[0];
				check[1] = a[1];
				S.pop();
				Q.pop();
				
				k--;
			}
			if(S.size() == 0) break;
		}		
		if(OK == true) printf("YES\n");
		else printf("NO\n");
		for(;;){
			if(S.size() == 0)break;
			S.pop();
		}
		for(;;){
			if(Q.size() == 0)break;
			Q.pop();
		}
		
		
	}
	return 0;
}

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

int main(){
	int n;
	bool check;
	stack<int> a;
	stack<int> b;
	int ain,bin;
	cin>>n;
	for(int i=0;i<n;i++){
	check=true;
	cin>>ain>>bin;
	a.push(ain);b.push(bin);
	for(int j=0;j<5;j++){
		cin>>ain>>bin;
		if(!(a.top()<ain||b.top()<bin))check=false;
		a.push(ain);b.push(bin);
	}	
	if(check==false){cout<<"NO"<<endl;}else cout<<"YES"<<endl;
	}
}

C++: #include<stdio.h>

int main()
{
	int n,m[10]={0};
	scanf("%d",&n);

	for(int x=0;x<n;x++)
	{
		scanf("%d %d %d %d %d %d %d %d %d %d",&m[0],&m[1],&m[2],&m[3],&m[4],&m[5],&m[6],&m[7],&m[8],&m[9]);
		int a=0,b=0,t=0;

		for(t;t<=9;t++)
		{
			if(a>=b)
			{
				if(a<m[t])
				{
					a=m[t];
				}
				else
				{
					if(b<m[t])
					{
						b=m[t];
					}
					else
					{
						t=99;
					}
				}
			}
			else if(a<b)
			{
				if(b<m[t])
				{
					b=m[t];
				}
				else
				{
					if(a<m[t])
					{
						a=m[t];
					}
					else
					{
						t=99;
					}
				}
			}
		}

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

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

 
int data[10];

bool dfs(int b, int c, int n) {
	if (n == 10){
		return true;
	}
   	else if (data[n] < b && data[n] < c)
		return false;
 
    	if (data[n] > b){
		return dfs(data[n], c, n+1);
	}
   	else if (data[n] > c){
		return dfs(b, data[n], n+1);
	}
}
 
int main() {
    int N;
    cin >> N;
 
    while(N--){
       for (int i = 0; i < 10; i++) {
            cin >> data[i];
        }
	if (dfs(0, 0, 0)){
		 cout << "YES\n";
	}else{
		 cout << "NO\n";
	}
    }
    return 0;
}

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

using namespace std;

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

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#define INF 1000000000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define all(x) (x).begin(),x.end()
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

int a[11];

int dfs(int left,int right,int cnt){
  //cout<<left<<" "<<right<<" "<<cnt<<endl;
  if(cnt==10)return cnt;
  if(left<a[cnt]&&right<a[cnt]) cnt=max(dfs(a[cnt],right,cnt+1),dfs(left,a[cnt],cnt+1));
  else if(left<a[cnt])cnt=dfs(a[cnt],right,cnt+1);
  else if(right<a[cnt]) cnt=dfs(left,a[cnt],cnt+1);
  
  return cnt;
}

int main(){
  int n;
  cin>>n;
  rep(i,n){
    rep(j,10)cin>>a[j];
    //rep(j,10)cout<<a[i]<<" ";
    //cout<<endl;
    if(dfs(a[0],-INF,1)==10)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[10];
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            cin>>a[j];
        }
        if(a[1]<a[3]&&a[3]<a[5]&&a[5]<a[7]&&a[7]<a[9]&&a[0]<a[2]&&a[2]<a[4]&&a[4]<a[6]&&a[6]<a[8]){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}

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

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

    while (n--) {
        int left = 0, right = 0;
        bool flag = true;
        for (int i = 10; i--;) {
            int x;
            cin >> x;
            if (x > left)
                left = x;
            else if (x > right)
                right = x;
            else {
                flag = false;
                break;
            }
            if (left < right)
                swap(left, right);
        }
        cout << (flag ? "YES" : "NO") << endl;
    }

    return 0;
}