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>  

using namespace std;

int main() {
	vector<int> left;
	vector<int> right;
	vector<int> all;

	bool flag = true;

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else  if (all.size() == (i+1)*(j+1)) {

						}
						else {
							flag = false;
						}			  						
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}

		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
		flag = true;
	}

	return 0;
}

C++: using System;
class _0033
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            string[] data = Console.ReadLine().Split();
            Console.WriteLine(Judge(data) ? "YES" : "NO");
        }
    }
    public static bool Judge(string[] data)
    {
        int right = 0;
        int left = 0;
        for (int i = 0; i < data.Length; i++)
        {
            if (right < int.Parse(data[i])) right = int.Parse(data[i]);
            else if (left < int.Parse(data[i])) left = int.Parse(data[i]);
            else return false;
        }
        return true;
    }
}

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

int a[15];
int t, m, A, B;

bool dfs(int k, int A, int B)
{
    if(k == 10) return true;
    if(a[k] > A) {
        if(dfs(k + 1, a[k], B))
            return true;
    }
    if(a[k] > B) {
        if(dfs(k + 1, A, a[k]))
            return true;
    }
    return false;
}

int main()
{
    cin >> t;
    while(t--) {
        for(int i = 0; i < 10; ++i) {
            cin >> a[i];
        }

        if(dfs(0, 0, 0)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #include<iostream>

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

 	return 0;
}

C++: /*
P135
POJ 2718 Smallest Difference
*/


#include <iostream>
#include <map>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <functional>
#include <string.h>
using namespace std;

int a[10];
void read()
{
    for(int i=0; i<10; ++i)
        scanf("%d", a+i);
}

void solve()
{
    int x1=0, x2=0;
    bool ans = true;
    for(int i=0; i<10; ++i)
    {
        if(x1 < x2) swap(x1, x2);
        if(x1 < a[i]) x1 = a[i];
        else if(x2 < a[i]) x2 = a[i];
        else {ans = false; break;}
    }
    if(ans) printf("YES\n");
    else printf("NO\n");
}



vector<int> L_bucket;
vector<int> R_bucket;

bool dfs2(int d){
    if(d == 10) return true;
    bool flag;
    if(L_bucket.size() == 0 || L_bucket.back() < a[d]){
        L_bucket.push_back(a[d]);
        flag = dfs2(d+1);
        L_bucket.pop_back();
    }
    if(flag) return true;
    if(R_bucket.size() == 0 || R_bucket.back() < a[d]){
        R_bucket.push_back((a[d]));
        flag = dfs2(d+1);
        R_bucket.pop_back();
    }
    if(flag) return true;
    return false;
}

void solve2()
{
    if(dfs2(0)) printf("YES\n");
    else printf("NO\n");
}

int main()
{
    int T;
    scanf("%d", &T);
    while(T--){
        read();
        solve();
    }
}

C++: #include<cmath>
#include<queue>
#include<iostream>
#include<algorithm>
#define debug(ARGS) cout << #ARGS << ": " << ARGS << endl;
#define ll long long
using namespace std;

bool dfs(queue<int> &v, int l, int r){
  if(v.size() == 0) return true;
  
  int ball = v.front(); v.pop();
    
  if(ball > l) return dfs(v, ball, r);
  if(ball > r) return dfs(v, l, ball);
  
  return false;
}

int main(){
  int n; cin >> n;
  int size = 10;

  for(int c = 0; c < n; c++){
    queue<int> v;
    for(int i = 0; i < size; i++){
      int tmp; cin >> tmp;
      v.push(tmp);
    }

    if(dfs(v, 0, 0)) cout << "YES" << endl;
    else cout << "NO" << endl;  
  }

  return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
#define INF 40
using namespace std;

int ball[12];
int flag ;
stack<int> A, B;


void dfs(int s)
{
	if (s >= 10)
	{
		flag = 1;
		return;
	}
	else if (ball[s] < A.top() && ball[s] < B.top())
	{
		return;
	}
	else {
		if (ball[s] > A.top())
		{
			A.pop();
			A.push(ball[s]);
			dfs(ball[s + 1]);
		}
		if (ball[s] > B.top())
		{
			B.pop();
			B.push(ball[s]);
			dfs(ball[s + 1]);
		}
	}
}


int main()
{
	int n;
	while (~scanf("%d",&n))
	{
		while (n--)
		{
			flag = 0;
			A.push(0);
			B.push(0);
			memset(ball, 0, sizeof(ball));
			for (int i = 0;i < 10;i++)
			{
				scanf("%d", &ball[i]);
			}
			dfs(0);
			if (flag) printf("YES\n");
			else printf("NO\n");
		}
	}
	return 0;
}

C++: #include<stdio.h>
int a[10],b=0,c=0;
bool tube[10];
bool dfs(int i){
    if(i==10) return true;
    bool flagb,flagc;
    if(b>=a[i]&&c>=a[i]) return false;
    else if(b<a[i]){
        int oldb=b;
        b=a[i];
        flagb=dfs(i+1);
        b=oldb;
    }else{
        int oldc=c;
        c=a[i];
        flagc=dfs(i+1);
        c=oldc;
    }
    return flagb||flagc;
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            scanf("%d",a+j);
        }
        if(dfs(0)) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

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

using namespace std;

bool solve(int *data)
{
  int i, j, k;
  int stack1[11] = {0};
  int stack2[11] = {0};

  for (i = j = k = 0; i < 10; i++) {
    if (stack1[j] < data[i]) {
      j += 1;
      stack1[j] = data[i];
    }
    else if (stack2[k] < data[i]) {
      k += 1;
      stack2[k] = data[i];
    }
    else {
      return false;
    }
  }
  return true;
}

int main()
{
  int i, j, n;

  cin >> n;

  for (j = 0; j < n; j++) {
    int *data = new int[10];
    for (i = 0; i < 10; i++)
      cin >> data[i];
    if (solve(data))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }

  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(r>l)swap(r,l);

			if (r>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;


	}
	return 0;

}

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